View CoffeeScript as Compiled JavaScript - javascript

I am trying to learn coffeescript. I installed the Sublime package 'BetterCoffeeScript', and I am seeing the syntax highlighting, but I can't figure out how to view my coffeescript as compiled javascript. When I go to the command pallet and click Coffee: Display JS, it just generates a new blank file. How do I get this to show the compiled JS? Also, what is the first key that is shown for the keyboard shortcut? I attached a screenshot.

Answer taken from https://github.com/aponxi/sublime-better-coffeescript/issues/142
In terminal, run which coffee to see where coffee is installed.
If it's /usr/bin/coffee, you should be fine.
If it's /usr/local/bin/coffee (or anything else), go to Sublime, Preferences > Package Settings > Better CoffeeScript > Settings - User
Add "binDir": "/usr/local/bin" (or whatever which said it was) there.

Related

How to disable Tern synchronization in Eclipse Luna?

I use Eclipse Luna SP2 for Java EE for some JavaScript development.
Every now and then (mostly on .js file open but also on some timer) I get the following popup error
An internal error occurred during: "Synchronizing script resources with Tern server...".
loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader)
previously initiated loading for a different type with name "org/apache/http/HttpEntity"
I don't need Tern functionality and I would like to disable it or at least get rid of the popup error
I googled about but could not find any relevant information.
For the moment I tried to disable all validators and to change the .js editor but no luck by now.
Any idea?
I think it's the same problem than issue 273 The 0.8.0 didn't set the version of packages of org.apache.http in the MANIFEST.MF.
Please install 0.10.0 version.
Go to Properties of the project > JavaScript > Include Path > Source and remove the whole project. Click on "Add Folder" and give the required path for your JS. Like projectname/src/pages.Ionic 2

Dart Editor: Pub build produces dysfunctional files

I'm working on a dart thing. Everything works flawlessly when I test it in Dartium. But when I Pub Build the project and run the .html file in the build/web folder, everything that's dart gets completely ignored.
I thought the problem might be in my code, but this does not seem to be the case since I don't even need to write any. It's enough if I just create a new project from the 'Web application' template and keep the template code in there (you know, the one with a "Click me!" text that reverses if you click it).
I get no errors while building the project. I build the project by right-clicking on pubspec.yaml and choosing the 'Pub Build (generates JS)' - Is this the right way of doing it, or am I doing something wrong?
Indeed, it was caused by the missing dart.js in the "packages/browser"
Running the 'pub cache repair' command was sufficient in bringing the missing file back and now everything works.

How to preview page when doing javascript developement with Vim

I'm learning to do javascript development with Vim
I would like to know how other people do to preview the result of your javascript code
I can of course manually launch and refresh a browser
but there must be an automatic way
I use xdotool[1] to automate the "switch focus to browser, hit f5" part. All this is in a shell script, say reload.sh, and I call it from vim by mapping like this:
:nmap <C-L> :!reload.sh<CR>
reload.sh (untested, you may need to massage it a bit):
#!/bin/sh
WID=`xdotool search "Mozilla Firefox" | head -1`
xdotool windowactivate --sync $WID
xdotool type f5
[1] http://www.semicomplete.com/projects/xdotool/

How can you set up Eclipse to remove trailing whitespace when saving a JavaScript file?

I am running Eclipse 3.6 (Helios 20110218-0911) on Ubuntu 11.04. Under Preferences, I have gone to the following panel:
JavaScript -> Editor -> Save Actions.
The "Additional actions" checkbox is checked and "Remove trailing whitespaces on all lines" is selected.
Nevertheless, when I save my JavaScript file in Eclipse, there is still trailing whitespace at the end of my lines.
What am I missing?
'Save Actions' for JavaScript is available in the JavaScript project(the project with JavaScript nature) only.
(If you can see 'Convert to JavaScript Project' in 'Configure' menu when right-click the project, try it)
I recently faced the same problem. The only way I found is to convert your project to Javascript project. Right click your project folder in the Explorer, choose [Configure] -> [Convert to Javascript project] and the Javascript Save Action will start to work.
Unfortunately, I don't know how to convert it back.
Since it's not a big problem for me, the way Converting it to javascript project indeed helps me a lot.
For the latest Eclipse -
Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200
The default key-binding shift+ctrl+backspace, which binds to the function "Removes the trailing whitespace of each line" will remove trailing space chars for the entire file.
(The key-binding shift+ctrl+backspace is probably already there in many earlier releases as well.)

Reference javax.script.ScriptEngine in android or evaluate a javascript expression

Is it possible to reference the javax.script.ScriptEngine library when developing an android application?
If not is there anyway possible to evaluate a javascript expression in android?
For the classes javax.script.ScriptEngine, javax.script.ScriptEngineFactory and so on, you can add the jsr223.jar to your Android project: just copy the .jar file to your libs directory, and add it from Properties->Java Build Path.
These class will allow your JSR 223-compliant engines to compile. You can then do new SomeScriptEngienFactory().getScriptEngine() to get an engine. I've managed to do this with JNLua 1.0.4 and Rhino 1.7R2.
The file jsr223.jar can be downloaded from http://www.java2s.com/Code/Jar/j/Downloadjsr223jar.htm, a direct link is http://www.java2s.com/Code/JarDownload/jsr223/jsr223.jar.zip.
javax.script.ScriptEngine is not a default part of android, but you could easily jar up any libraries you need(assuming the size is reasonable, I'm not sure) and include them in your project.
According to this post, javax.script.ScriptEngine is not available in Android SDK. You can try the steps below to include the library, but the code may not run, even though it will compile.
Using Android Development Toolkit in Windows, I performed the following steps to get javax.script library.
Right-clicked on the project, went to Properties (Project).
Under the Java Build Path, I chose Libraries tab.
Select Add Library located on the middle right of the Tab
Select JRE System Library under Add Library and click Next...
Select Workspace Default JRE (jre 7)
Click Finish.
Click Ok on the Java Build Path to exist project properties.
Javax.script was then loaded.
If you want to evaluate some code in JS in android
1) to your gradle dependencies add (rhino):
compile 'org.mozilla:rhino:1.7R4'
2) write some code like this to get the result of JS evaluation
Context rhino = Context.enter()
// turn off optimization to work with android
rhino.optimizationLevel = -1
String evaluation = "2+2"
try {
ScriptableProject scope = rhino.initStandardObjects()
String result = rhino.evaluateString(scope, evaluation, "JavaScript", 1, null).toString()
} finally {
Context.exit()
}
3) You can write more complex scripts in JS to run in the android app also (functions etc.)

Categories