How can I effectively edit jupyter notebook's javascript files? - javascript

So notebook's js files are all stored in python_packages_folder/notebook/static/notebook/js however when I edit them, no change happens and checking the loaded js files on the browser I find them look like as if they were not edited. Why does this happen?

I had the same problem when I want to temporarily test some use cases. I hacked it by doing the following:
cd python_packages_folder/notebook/static/notebook/js
mv main.min.js main.min.js.bak
cp main.js min.min.js
Then you restart your jupyter and open one notebook you will see all the original (not-minified) javascript files. They all come with an ?v=timestamp suffix, indicating they will be reloaded when you modify them.

Related

Opening Local HTML Files using HTML and Javascript

I have a project I'm working on and I am trying to do file organisation with it
I want to open a html file in a folder before it.
Here is an example of the folder tree I am creating:
Main Folder
Game_Folder
Rules
Each folder has a HTML, CSS and JS file in it (For organisation reasons). But I want to be able to open
'Game_Folder.html' from the 'Rules.html'. I know how to do it from the other way, I just cannot figure out how to do it backwards.
I cannot use a full directory (c:/) as it will be operated on a few different computers. So the file location must be in local file format (if that makes sense).
Thanks in Advance
-J
Navigating backwards using ..
Background info
I don't know if you are familiar with the command line but typing cd .. moves you backwards from one directory. This can also be used to reference files outside your current directory
Presumed file layout
Presuming that your file layout is like this:
-> /Main_Folder
-> index.html
-> /Game_Folder
-> game_folder.html
-> /Rules_Folder
-> rules.html
Proposed solution
You can use this rule as below to reference your game_folder.html from your rules.html:
Click to open
Other resources
Some other things worth looking at are:
This answer where I based my answer from
This article from W3 schools
Also leave a comment if you have any questions

Grunt Uglify weird characters at last line leading to no changes

I am working since month with Grunt Watch, which is using Uglify to minify Javascript files and also generating a .map file which worked perfectly since yesterday.
When I now do grunt watch and save a Javascript file, Grunt workes like intended and runs the tasks which copy the Javascript file into the public area and generating the filename.js and filename.js.map file into the public area.
Now I am refreshing the page to look my changes, but instead of my changes, the browser seems loading the old Javascript file (Yes, I am using version like filename.js?v=....).
When I look in the source code and open the Javascript file, at the end of the file following weird characters are there:
//# sourceMappingURL=filename.js.map��������������������
I am using Chrome as my browser and PHPStorm as my IDE.
I tried to convert to UTF-8, UTF-8 without BOM, changed line Feeds to LF and CRLF, but nothing seems to be the solution.
I also displayed all invisible characters to look if there is something hidden, but there is nothing.
Inside the generated file there is the console.log('Test'); I written into, but in the same file I opened in the source code, the console.log('Test'); is not there:
Open file in any IDE: [public/js/filename.js]
... function(){l=!0,console.log("Test"),c.setTimeout(fun ...
Open file in any Browser: [/js/filename.js]
... function(){l=!0,c.setTimeout(fun ...
If I delete the 2 files in the public folder, change something in the original file and save, grunt is uglifying and copying everything and it's working! But just this one time.. the next changes leading to the same weird characters and no changes to the file in the browser again.
Like I said: The whole process I am doing worked for months! But since yesterday it's not working anymore.
I didn't installed/patched anything. This behaviour came from one to another second.
Operating System is:
Linux packer-virtualbox-iso-14225xxxxx 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1 x86_
I am searching since yesterday, but can't find any solution or idea what is wrong.
Used to have the same problem. You should turn off your sendfile in nginx.
sendfile off;
see https://github.com/mitchellh/vagrant/issues/351#issuecomment-1339640
I just restartet my computer and it seems working right now.
But if anyone has a suggestion to prevent this or solving this problem in the future, I would be happy to hear from it! If in the next few days no answer comes, I will mark my answer as solution.

Globally configuring Javascript for notebooks on Jupyterhub

I would like to replace each user's custom.js file with a global version. The only way I can figure out how to do this currently is to overwrite ~/.ipython/profile_default/static/custom/custom.js after a user runs their first ipython notebook and their .ipython directory gets instantiated.
There must be a better way, either by providing some global version of custom.js or by replacing the default custom.js file during installation. In theory, one could also create symbolic links to a global custom.js but this didn't work for me for some reason.
I see that there is a file /srv/notebook/notebook/static/custom/custom.js on my system - but modifying it doesn't alter the custom.js that gets installed for each user.
Any suggestions?
I'm running jupyterhub with dockerspawner, and have just found a solution here.
To make the custom.js file adopted by each user, you can derivate the jupyter/base-notebook image by adding it to each user's custom directory:
ADD ./custom.js /home/$NB_USER/.jupyter/custom/custom.js
Note this path is the path defined in the jupyter notebook doc.
Hope this helps anyone having the same problem.

original vimrc file. Where to fnd? how to restore?

I was trying to set up vim to work with JavaScript (any links about that appreciated), though didn't even know what's .vimrc file. So I deleted it. After removing and installing vim for about 10 times... I now don't know what exactly should I do. I believe there was some default settings that I lost. If I google for it I find bunch of different vimrc files, and if I put their content in my vimrc - whenever I start vim I get a lot of errors (assuming because I don't have all the plug ins). also don't think that I should\can create one and fill it little by little.
so.
1. How do I restore my original vim state (if you think this is smtn I should do) - ?
2. How do I set it up to work nicely with JavaScript files?
3. Possibly good vim tutorial?
OS Ubuntu 12.04 32-bit
Thank you guys.
vim beginner.
If you hadn't customised the file at all before you started, then if it existed at all, it must have been the default for new users.
When creating a new user account, the files in /etc/skel are used to populate the new user's home directory; thus the file you deleted can probably be restored to its original state with the following command:
cp /etc/skel/.vimrc ~/.vimrc
That is "copy the .vimrc file from the skeleton directory into my home directory".
If that doesn't help, or if the file you deleted was actually the system-wide defaults (normally /etc/vimrc or /etc/vim/vimrc) then you can probably get hold of the original file from your OS's package archive.
Since you are running Ubuntu 12.04, the relevant file list seems to be this one: http://packages.ubuntu.com/precise/i386/vim-common/filelist It doesn't seem to put anything into /etc/skel, but it does install an /etc/vim/vimrc which includes /usr/share/vim/vimcurrent/debian.vim.
You can download the package manually from here - the .deb file is just a .tar.gz, so tar -xzvf foo.deb will extract it for you to poke around. cd to a new empty directory before doing that, or you'll get very confused by the directories it creates!
Another thing to double check is that Ubuntu actually has multiple different vim packages, e.g. vim-tiny. See this question for how to check you've installed and selected the "full" version.
A .vimrc file is optional, and without it vim will use all of its defaults.
These defaults, however, are a bit conservative. If I recall correctly, vim defaults to being compatible with its predecessor (vi), which means no syntax highlighting, no line numbers, no ruler to tell you which mode you're in, no nothing.
Tim Pope's sensible vimrc is a good point to start off.
.vimrc usually is a config file under your $HOME directory. Itself is a vimscript too. You can put your config/mapping/plugin config/function... there, so that everytime you started your vim, the file would be automatically loaded. then you have a customized comfortable editor opened.
without this .vimrc, vim can start too, with default config though.
you can start vim and type :h vimrc to see the help doc of vimrc. You can take a vimrc from internet, try to understand the settings in the file. finally make your own vimrc. It will take veryveryvery long time to have a satisifed vimrc. I have used vim for about 10 years, last week I was still editing my vimrc file.
When you read others' vimrc settings, use :h foo to find the help information. In this way, you know "why I set this", not "I don't know what's going on, just copied it".
The charm of vim is, it is highly customizable. You can change it into plain notepad or programming IDE or mp3 player...
enjoy editing!

WebBrowserControl + JS minification: Manipulate resources-properties with js code for minification puproses in Visual Studio's pre-build events

Background: Got a C# project which involves a block of javascript that gets programmatically injected in the web pages displayed by a webbrowser control. However, it is desirable to minify this block of javascript and have it embedded/written-into in a property of the resources-file. I know the minification of javascript is possible. I was just wondering if it's also possible to write the resulting string into a specific property of the resources files using pre-build events.
P.S.: Of course the resulting string can be written into a file which is in turn bound to a resource-property. However I would prefer to avoid something as such, fearing the performance penalty it would impose in runtime (the javascript block gets loaded quite often). If I'm mistaken about this feel free to correct me.
For anyone struggling with similar issues out there, this is the step-by-step approach I have opted for (having run out of alternative solutions) in the context of Visual Studio 2010. The method below handles the minification of javascript files in a uniform way while respect the version control system you might use (by avoiding to generate phantom changes in files hosted by it). Here are the steps:
Install Java and Google's Closure (for javascript minification).
Open the Resources of your project, go to file-resources and create a dummy file-property a-la foo.txt. This should create and include in your project the directory named Resources. You may delete the foo.txt file after this.
Right click the Resources directory and create a javascript file ending in Uniminified.js (for example MyInjectableJavascript.Unminified.js). Edit the properties of this file and make sure that the build action is set to "None". By the way, DO NOT reference this file in the resources.
Now go back to the Resource's file-properties and add a new file-property with the same base-name of the file created above only this time ending in min.js (for example MyInjectableJavascript.min.js).
Go to the .min.js file that was created under the resources directory and turn it into an Embedded Resource.
Now go the properties of your project -> build events and insert the following code:
Pre-Build events (in one line):
call "$(ProjectDir)JavascriptMinificationWithGoogleClosure.bat" "$(ProjectDir)Resources\MyInjectableJavascript.Unminified.js" "$(ProjectDir)Resources\MyInjectableJavascript.min.js"
Post-Build events (two lines):
del "$(ProjectDir)Resources\MyInjectableJavascript.min.js"
call echo. 2> "$(ProjectDir)Resources\MyInjectableJavascript.min.js"
What this does is that it minifies the javascript code before your project is built and after it is build it resets the minified file to a single newline.
Note: The reason we don't delete the minified file all together, is that visual studio will generate an error and will behave very weirdly if the minified file that is referenced by the resources is not found (in my case visual studio deleted Resources.Designer.cs completely out of the blue ... 5 times). By truncating the min.js file it to a single newline you can keep it around and even add it to your version control system without bothering with it ever again.
Under the directory of your project place a file named JavascriptMinificationWithGoogleClosure.bat with the following contents:
"%JAVA_HOME%jre6\bin\java" -jar "%CLOSURE_JS_HOME%compiler.jar" --js %1 --js_output_file %2
Finally, create two environment variables (Right click Computer -> Properties -> Enviroment Variables) named JAVA_HOME and CLOSURE_JS_HOME which point respectively to the directories you have installed the executables of Java and Closure. For example:
JAVA_HOME -> C:\Program Files\Java\
CLOSURE_JS_HOME -> C:\Program Files\Closure\
Note: Make sure to include the trailing slash at the end of each of the two paths.
You can now access the minified javascript that will be generated during the build from C# code, using:
Resources.MyInjectableJavascript_min
Hope this helps. Good luck.
Cheers,
Dominick

Categories

Resources