minifying javascript messes up characters - javascript

I am trying to minify a .js file that includes code like this:
DIACRITICS = {"\u24B6":"A","\uFF21":"A","\u00C0":"A","\u00C1":"A","\u00C2":"A","\u1EA6":"A","\u1EA4":"A","\u1EAA":"A","\u1EA8":"A","\u00C3":"A","\u0100":"A","\u0102":"A","\u1EB0":"A","\u1EAE":"A","\u1EB4":"A","\u1EB2":"A","\u0226":"A","\u01E0":"A","\u00C4":"A","\u01DE":"A","\u1EA2":"A","\u00C5":"A","\u01FA":"A","\u01CD":"A","\u0200":"A","\u0202":"A","\u1EA0":"A","\u1EAC":"A","\u1EB6":"A","\u1E00":"A","\u0104":"A","\u023A":"A","\u2C6F":"A","\uA732":"AA","\u00C6":"AE", ....
The problem is, when I use a tool like http://javascript-minifier.com/ or http://refresh-sf.com/ to minify it, the above code gets changed to this:
,j={"Ⓐ":"A","A":"A","À":"A","Á":"A","Â":"A","Ầ":"A","Ấ":"A","Ẫ":"A","Ẩ":"A","Ã":"A","Ā":"A","Ă":"A","Ằ":"A","Ắ":"A","Ẵ":"A","Ẳ":"A","Ȧ":"A","Ǡ":"A","Ä":"A","Ǟ":"A","Ả":"A","Å":"A","Ǻ":"A","Ǎ":"A","Ȁ":"A","Ȃ":"A","Ạ":"A","Ậ":"A","Ặ":"A","Ḁ":"A","Ą"
I assume that will cause problems when it executes? Is there any way around this?

Try using Microsoft's AjaxMinifier: http://ajaxmin.codeplex.com/
This is to do with encoding, so use the program with the "-enc:out ascii" command.
Once you download the program, open it. It will appear like a command prompt window. CD to the directory of your JS file, then run:
ajaxminifier file.js -o file.min.js -enc:out ascii

Related

Convert the ssd_mobilenet_v1_coco model with tensorflow_js

I want to build an app with javascript which integrates object-detection. For this, I wanna use the ssd_mobilenet_v1_coco model and use it in tensorflow.
However this line of code:
C:\Users\Jonas\AppData\Roaming\Python\Python36\Scripts\tensorflowjs_converter --input_format=tf_saved_model --output_node_names='image_tensor, detection_boxes, detection_scores, detection_classes, num_detections' \saved_model\saved_model \saved_model\web_model
does not work. It gives me file not found error, but the file is actually there unless I'm very dump and turned back into computer beginner.
OSError: SavedModel file does not exist at: \saved_model\saved_model
Also, I'm not quite sure about the output node names but this is secondary.
Thanks for support, hopefully I'm not totally dump :)
This might be because you are using an absolute path instead of a relative path.
On mac or linux, if you are in the directory that contains the downloaded unzipped model, you would run a command of that type :
tensorflowjs_converter --input_format=tf_saved_model --output_node_names='detection_boxes,detection_classes,detection_scores,num_detections' --saved_model_tags=serve ./ssd_mobilenet_v1_coco/saved_model ./ssd_mobilenet_v1_coco/web_model
From what i can see you are on Windows.
If you are running your command from the directory that contains the saved_model folder, you should run the following command :
C:\Users\Jonas\AppData\Roaming\Python\Python36\Scripts\tensorflowjs_converter --input_format=tf_saved_model --output_node_names='image_tensor, detection_boxes, detection_scores, detection_classes, num_detections' .\saved_model\saved_model .\saved_model\web_model

How to call js completion in html file instead of js file?

I had installed tern_for_vim and YouCompleteMe for js completion this way.
1 install node
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
source ~/.nvm/nvm.sh
nvm install node
2 install tern_for_vim
$ cd ~/.vim/bundle
git clone https://github.com/marijnh/tern_for_vim
3 install YouCompleteMe
cd ~/.vim/bundle/YouCompleteMe
$ ./install.sh --clang-completer --tern-completer
4 edit .tern-project
vim .tern-project
{
"libs": [
"browser",
"underscore",
"jquery"
],
"plugins": {
"node": {}
}
}
Now to vim test.js.
The js completion pop up after inputing document. in test.js file.
Then to vim test.html
No js completion pop up after inputing document. in test.html file.
How to fix it?
Unfortunately this is not officially supported by tern. You can see the response in a closed issue
https://github.com/ternjs/tern_for_vim/issues/170
Because the parsing logic for separating HTML and scripts hasn't been implemented. This could be done as a plugin, if you want to take a shot at it, but it's out of scope for this repository.
But then there is another thread on SO which may help you
Using tern_for_vim plugin in HTML files
So best is to include your code in the html through a JS file and then edit the JS file. Else look at some other plugin/IDE environment. I would explore the below option as well
https://github.com/Shougo/deoplete.nvim#install
I'm unfamiliar with tern_for_vim and YouCompleteMe for js completion, however you could always use vim's built in omni-func completion.
If you add:
filetype on
filetype plugin on
set omnifunc=syntaxcomplete#Complete
to your vimrc file, you can then manually set the filetype of your html file to javascript with :set filetype=javascript whilst in vim.
Following that, when in insert mode, you can then use <C-x> followed by <C-o> to access javascript language specific omni completion.
The resulting completion menu is then navigable by the standard <C-p> for up and <C-n> for down hotkeys.
This, along with other bits of built in completion functionality are discussed in a nice thoughtbot talk.

Writing a git post-commit file in node.js

I'm trying to write a git post-commit file in node.js and I'm having trouble.
The file seems to have to be named post-commit in the .git/hooks directory. Since that file can't have an extension, my vim editor won't persistently give it javascript syntax highlighting, and thus none of my snippets work, and a variety of other challenges present themselves.
What can I do? Tell git to run post-commit.js or tell vim to consider this file javascript, but that doesn't persist.
Thoughts?
You can have the post-commit file run a separate JavaScript file.
post-commit:
#!/bin/bash/
node yourJavascriptFile.js
Use :set filetype=javascript command in vim to set file type.
You may also want to enable modeline in vim and include the aforementioned command in a comment at the top of your file like this:
/* vim: set filetype=javascript : */
your_Javascript_code_goes_here()
To enable modeline in vim, add this to your ~/.vimrc file:
set modelines=2
set modeline
That will enable searching for vim modelines in the first two lines of the file.

doctorjs(aka jsctags) not work with vim+tagbar

I am using windows 7 64bit...
I've installed nodejs 0.6.11 by MSI installer, the installation path is "C:\Program Files (x86)\nodejs", it was automatically added to my %PATH% by the installer, I installed doctorjs by steps below:
I copied doctorjs files under "C:\Program Files (x86)\nodejs\doctorjs"
I created jsctags.cmd filled with content copied from https://gist.github.com/1438882
I added following lines in my _vimrc:
let g:tagbar_type_javascript = {
\ 'ctagsbin' : 'C:\Program Files (x86)\nodejs\jsctags.cmd'
\ }
The problem is, when I run jsctags.cmd "{My js folder}", it generates tags file with only content below:
!_TAG_FILE_FORMAT 2 /extended format/
!_TAG_FILE_SORTED 0 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Patrick Walton /pwalton#mozilla.com/
!_TAG_PROGRAM_NAME jsctags //
!_TAG_PROGRAM_URL http://github.com/pcwalton/jsctags /GitHub repository/
!_TAG_PROGRAM_VERSION 0.1 //
And when I run :tagbaropen in vim, it shows nothing for current js file..
Please kindly guide me where I did wrong, thank you!
Since you're getting some output, it looks like you have the gist implemented correctly. But maybe your expectation of how to use it at a command line is different than the way it really works?
FYI: jsctags.cmd "{my js folder}" returns an empty tags file on my machine too. I don't think the command interface is very mature yet... so it looks like creating a tagfile of a whole folder is not possible - yet...
Try jsctags.cmd "{file}". This should create a populated tag file.
Also note that tagbar calls jsctags like this: jsctags -f - {file}. This streams the output to stdout. So if you're debugging, try this form of the command.
As another debugging tip, modify your batchfile to output debugging info. ie:
Add lines like this:
echo "%~dp0"\"node.exe" "D:\opt\node\doctorjs\bin\jsctags.js" %* > d:\debug.txt
Looking in d:\debug.txt will let you see what the command looks like as it is called from tagbar.
BTW: The gist you're using was mine... I am wondering if I didn't test this batch file well enough with folders that have spaces in them. Do some tests in both folders with and without spaces to see if there is a difference. If you get more insight into where it works/doesn't, let me know and I can investigate further.
Your issue might be related to the commit of narcissus you've cloned for doctorjs. Go into the narcissus folder in the doctorjs folder and run
git checkout 4ae5aff8b3
This should switch the head to the proper version of the file.

Where to place JS files for NodeJS to see them

I've just installed NodeJS on my Mac, and i got it working in the terminal, using inline scripting like "console.log('Hello world'); works fine.
But where do i place JS files for NodeJS to find them? Can i specify the root folder NodeJS to look for file in?
I followed this guide: http://nodeguide.com/beginner.html#learning-javascript
but i cannot get any of the samlpe to work where i reference a script file.
You put them in whatever folder you want. It is common practice to put each application in a different folder.
Then you run node.js like this:
node /path/to/file.js
Or like this:
cd /path/to/
node file.js
Where file.js might look something like this:
console.log('hello world');
You'll have to navigate to the correct folder "manually", in the Node Command Line Interface (CLI).
If you need to change drives, type the drive letter and a colon to switch to that drive, like so;
C:> (<- this is the line prompt, yeah? Just add this after it -> D:
That changes the drive. Now write cd (CD = "Change Directory") and the name of the direcotry you want to go to the directory your stuff is in:
D:> (<- the new prompt. Write something like this after it: ->) cd myprosject\subfoldername
D:\myproject\subfoldername> (<- your new line prompt - if "myproject\subfoldername" exists)
now ask node to execute your script (that is stored in myproject\subfoldername, like so;
D:\myproject\subfoldername> node helloworld.js
Remember to write "node" first - otherwise the command won't go to node, but to the OS, which will probably just open up the js file in a text editior instead of running the goodies inside.
It is very easy.. Go to your command line. navigate to the file location..
then simply run the node helloworld.
I'm not sure I understand. it doesnt 'look' anywhere for your .js files you point at them when you run node. Like so, on the command line:
node mynodeapp.js
If you're meaning where does it look for your .js files as modules, when requirign them, like so:
var mymodule = require("mymodule");
Then it will look inside a folder names node_modules. But I'm sure you're looking for my first example above.

Categories

Resources