So I just recently made a switch from an isolated Conda-based Jupyter Notebook to a JupyterLab notebook, but I noticed that there was no longer a straightforward way of adding syntax highlighting to the %%sql cell magic, since the code structure is completely different. Previously, the following code would be added to a custom.js file in ~/.jupyter/custom/:
require(['notebook/js/codecell'], function (codecell) {
codecell.CodeCell.options_default.highlight_modes['magic_text/x-mssql'] = { 'reg': [/%?%sql/] };
Jupyter.notebook.events.one('kernel_ready.Kernel', function () {
Jupyter.notebook.get_cells().map(function (cell) {
if (cell.cell_type == 'code') { cell.auto_highlight(); }
});
});
});
Now that JupyterLab extensions rely on Python, I'm not sure how I could go about implementing a similar front-end extension for the cell magic.
Related
I´m trying to create a "one line" message component based on Lexical, but i´m unable to prevent the enter key to create a new paragraph.
Any ideas how to accomplish this?
I´ve added styling with
white-space: nowrap!important;
resize: none;
and i´ve tried to MaxLengthPlugin ( which works but if enter in there it creates two lines)
also tried to add
<EditorWrapper ref={onRef} data-testid="editor"
onKeyDown={event => {
if (event.key === 'Enter') {
event.preventDefault();
}
}}>
I was expecting this to prevent the new paragraph with enter, but still adds a new paragraph in the editor.
I was able to create a single line editor by using registerNodeTransform to remove the LineBreakNode as soon as it's created. It doesn't feel like the best solution, but it works.
editor.registerNodeTransform(LineBreakNode, (node) => {
node.remove();
});
I also explored listening to the KEY_ENTER_COMMAND command, but that didn't prevent newlines from being pasted into the editor.
You can register the command INSERT_PARAGRAPH_COMMAND and then return true. By returning true you tell lexical that you have handled the paragraph insert and the default lexical code will not execute.
Example:
useEffect(() => {
return editor.registerCommand(
INSERT_PARAGRAPH_COMMAND,
() => {
return true;
},
COMMAND_PRIORITY_EDITOR
);}, [editor]);
I have mainly worked with cypress previously for e2e automated testing, I have now started working on webdriverIO. So for a cypress command such as
cy.get("[data-testid='nav-bar']").contains("Search Box").click();
What would be the equivalent for this in webdriverIO? I have tried the following approach in a PageObject Model.
class HomePage extends Page {
get navBar() {
return browser.$("[data-testid='nav-bar']");
}
openSearchBox() {
this.navBar().click('//*[text="Search Box"]');
}
}
However, this approach does not seem to work, any help on this would be appreciated.
Leaving Page Objects asside for now, you'd type this in WebdriverIO:
const bar = $('[data-testid='nav-bar']');
expect(bar.getText()).toInclude('Search Box');
bar.click();
You can use chai for the assertion instead of Jest Matchers:
const expectChai = require('chai').expect;
// ...
expectChai(bar.getText()).to.have.string('Search Box');
// ...
The exact analog to
cy.get("[data-testid='nav-bar']").contains("Search Box").click();
can be achieved with xpath selector
$("[data-testid='nav-bar']").$("./*[descendant-or-self::*[contains(text(), 'Search Box')]]").click();
It looks a bit ugly though, consider adding a custom command that would mimic Cypress's contains:
// put this to `before` hook in your wdio.conf.js
browser.addCommand('cyContains', function(text) {
this.waitForExist()
return this.$(`./*[descendant-or-self::*[contains(text(), '${text}')]]`)
}, true)
$("[data-testid='nav-bar']").cyContains("Search Box").click();
P.S.
Check out the selector in the browser console right on this page, paste in the browser console
$x("//span[descendant-or-self::*[contains(text(), 'Search Box')]]")
In my project one of the templates has in it's onRendered method more than 250 lines. Code is becoming more and more unreadable and unmaintainable (because of its monolithic) and i want to split all the code to functions to achieve something like this:
Template.Products.onRendered(function () {
initCarousels();
const allProducts = Meteor.call('server/collections/products::getAll', product._id, (err, content) => {
...
});
const sortedProducts = sortProducts(allProducts);
updateCarousels(sortedProducts);
...
this.autorun( () => {
this.subscribe('products');
...
if (this.subscriptionsReady()) {
...
}
});
}
Of course, i can define functions in onRendered method, but declaring them in onRendered and using in the same place seems not perfect way do do this - i'm searching something like moving functions from templates or even moving them to another file. Can you advise me a way to achieve this?
Yes! you can move code to lib/ directory and use which will be sibling of Client and server folders.
Template.registerHelpers(function_name, function());
When the server starts it will first load lib/*.js files alphabetically, so you can use the files from client.
I have recent build of Jupyter than has a menu action allowing you to Restart & Run All:
I would like to add a keyboard shortcut that binds to this action. I have seen the documentation for keyboard customization, but I'm still unsure how to add a keyboard shortcut.
I've built Juypter from source, so based on the help, it would appear that I need to add some code to notebook/static/custom/custom.js.
I've tried adding the following:
IPython.keyboard_manager.command_shortcuts.add_shortcut('meta-r', function (event) {
IPython.notebook.restart_kernel();
IPython.notebook.execute_run_all();
return false;
});
However, when I press [Meta-r], the kernel seems to restart but execute_run_all() does not get executed.
As of Jupyter Notebook 5.0, you can now create and edit keyboard shortcuts directly in menu options. As of now, it's Help -> Edit Keyboard Shortcuts. There's a guide at the bottom of that dialogue box.
The docs on it are here:
http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Custom%20Keyboard%20Shortcuts.html
Here's what I have in my custom.js. For it to work, the shortcut addition has to happen after the app is initialized:
$([Jupyter.events]).on("app_initialized.NotebookApp", function () {
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('0,1', {
help: 'restart and run all',
help_index: '0,1',
handler: function (event) {
Jupyter.notebook.kernel.restart();
restartTime = 2000 // decrease this if you have a fast computer
setTimeout(function(){ Jupyter.notebook.execute_all_cells(); }, restartTime);
return false;
}}
);
});
Just in case someone stumbles upon this post looking for the same answer: you need to wait for the kernel to restart with a timeout before executing.
See this discussion on GitHub.
In your case, it would give:
IPython.keyboard_manager.command_shortcuts.add_shortcut('meta-r',
function (event) {
IPython.notebook.kernel.restart();
setTimeout(function(){ IPython.notebook.execute_all_cells(); }, 1000);
return false;
});
Ok I'm trying to make a package from a Phaser game, been researching this for a couple of days, but it doesn't seem to work.
I think I identified the problem though, hopefully somebody can help me with this!
I set everything up to make use of a local package, which all works.
Untill I'm preloading an asset.
This is my Menu class
Menu = function() {
console.log(this);
}
Menu.prototype = {
preload: function(){
this.load.image('background', 'assets/background.png');
console.log("ok in preload");
},
create: function(){
this.background = this.game.add.sprite(0, 0, 'background');
console.log("ok in create");
var text = "We're getting there";
var style = { font: "23px Arial", fill: "#ff0044", align: "center" };
var t = game.add.text(game.world.centerX, 0, text, style);
},
};
and I call this by doing
game = new Phaser.Game(400, 300, Phaser.AUTO, "gameWindow");
game.state.add('menu', Menu);
game.state.start('menu');
which all seems to work by looking at the console logs, as long as I don't try to load the image in the preload function, if I do it just keeps stuck in the preload function.
The background.png is located at my root folder going 'public/assets/background.png'.
So I'm thinking when I try to access this from a local package, it is having trouble getting there...
my package.js is this btw:
Package.describe({
summary: "game one"
});
Package.on_use(function (api, where) {
api.use(['phaserio'], 'client');
api.add_files(['states/menu.js'],
['client']);
api.export('Menu', ['client']);
});
Anybody out there, that sees what I'm doing wrong?
Thanks in advance!
you should be able to load public images from the app, but it depends when that preload sequence is running. Packages get parsed first. So is your new game created within a Meteor.startUp ->? by which time the app itself is initialized?
Also you can put assets in the package itself.
are you using 0.9? there are some issues with paths for static assets inside packages
see this thread:
https://github.com/meteor/meteor/issues/2602
for 0.9 packages you'll have to add a bit more info
Package.describe({
summary: "phaser for meteor",
version: '0.0.1',
git: 'https://github.com/dcsan/package-dev',
name: "YOURNAME:phaser"
});
currently if you use something like replacing colon with an underscore:
/packages/YOURNAME_phaser/added/path/to/asset.png
if you get phaser wrapped i would also be interested, so please publish it to atmosphere!