Like Ruby 'exec' but for Node.js? - ruby

I'm looking for a command like Ruby's kernel 'exec' but for Node.js. Any thoughts?

I took the advice of #phs and built a native Node.js module. A bit of details can be found here. Github source here.
You can use it like so:
npm install kexec
var kexec = require('kexec');
kexec("your_process with args here");

If you only care about posix platforms you could craft a small module in C and drop down to exec.
For some pointers on how you might do that, first realize that node is a framework that runs on top of v8, and then take a look at this or perhaps this.

Related

The best practice of CLI solution in go

I want to implement a program that provides interactive-shell like experience with CLI.
I have been trying https://github.com/bobappleyard/readline but it needs users to install GNU readline and it causes some bugs in OSX.
Is there any other solution implemented in go without cgo so users do not need to install GNU readline additionally?
I've used the liner library from github.com/peterh/liner with some success for this.
It is a pure Go package with no dependencies on readline and works on windows/linux/os x.
See the docs for more info.
There is also github.com/chzyer/readline which looks very competent too - but I haven't tried that one. Docs are here.

PhantomJS + CasperJS from Ruby - Reuse Code?

I am calling CasperJS from the backend of my Ruby on Rails application using Open3.popen3 to make a command line call. The filename (in my case CoffeeScript) is the first argument followed by options.
Many of my coffee files do similar tasks. I see examples of of how to reuse code with modules, but I think that's a NodeJS only thing.
Any suggestions how I might reuse common code in my situation? I'm really getting horribly un-DRY.
UPDATE:
hexid's answer is correct. What I was missing when I tried it before is that you need the rooted file path, not relative the current file path:
my_module = require('/rooted/path/to/the/file.coffee')
PhantomJS has support for CommonJS' require.
You won't, however, be able to require NodeJS modules because PhantomJS doesn't run on NodeJS, but instead on a version of Webkit that is included in QT.

What's the best way to list a non-ruby dependency of a gem?

I am writing a ruby gem that I would like to use an open source program distributed as python. I don't have the time to port the python program to ruby, and I want to manage the external dependency as automatically as possible.
I'm thinking of using the Gem.pre_install hook to automatically easy_install the python package I'm interested in.
http://rubygems.rubyforge.org/rubygems-update/Gem.html#method-c-pre_install
I'd appreciate suggestions of better ways, or support of pre_install, if it's the accepted practice.
Quite an old question, but worth a reply. Sorry, I haven't been checking stackoverflow for babushka-related questions :)
If the python package is available as a pip, then you could do something like this:
dep 'blah.gem' do
requires 'something.pip'
end
dep 'something.pip'
Then, babushka blah.gem would handle the install, including installing rubygems and pip as required.
Ben
You may want to look at Babushka for describing non-ruby dependencies.
I don't know whether installing the python package in the pre_install hook would be polite behaviour.

CoffeeScript on Windows?

How can I try CoffeeScript on Windows?
The installation instructions are only for *nix: http://jashkenas.github.com/coffee-script/#installation
EDIT:
Since I asked this a while ago, many new answers have appeared. The number ( and quality ) of options for Windows users has been increased a lot. I "accepted" an answer a long time ago, then changed to other ( better ) answers as they came up, but I have now decided to not accept any answer, and let the community ( votes ) show which answers are best. Thanks to everyone for the input.
UPDATE: See my other answer to this question, How can I compile CoffeeScript from .NET? for a far more accurate and up-to-date list of the current options.
CoffeeScript-Compiler-for-Windows works well.
Maybe it was more complicated when this question was posted. But as of 2012, CoffeeScript is as easy to use on any platform. The instructions are the same for Windows, Mac, or Linux
Install Nodejs from http://nodejs.org/
Install CoffeeScript globally with the node package manager npm install -g coffeescript or locally npm install --save-dev coffeescript
Write a script in your favourite text editor. Save it, say as hello.coffee
Run your script coffee hello.coffee or compile it coffee -c hello.coffee (to hello.js)
Node.js runs on Cygwin these days, so that's probably your best bet with getting CoffeeScript running on Windows. I'd try that first.
If you have a different preferred JavaScript runtime, you can probably use the prebuilt-compiler (extras/coffee-script.js). For example, if you include that script on a webpage, you can call
CoffeeScript.compile(code);
... to get back the compiled JavaScript string.
UPDATE 2012-04-12: Cygwin is no longer needed to run Node on Windows. Microsoft
worked with Joyent through 2H 2011 to improve node's support for
Windows IOCP async IO. Node 0.6 was the first release of node to
natively support Windows.
You can run the CoffeeScript compiler under good old Window Script Host (cscript.exe), a standard component on Windows since Windows 98. Admittedly I tried this a while back and it didn't work, but I tried again recently and now all the standard CoffeeScript tests compile just fine.
A bit of plumbing code using a *.wsf file and coffee-script.js is all you need. My code is on GitHub: https://github.com/duncansmart/coffeescript-windows
I blogged about it here: http://blog.dotsmart.net/2011/06/20/the-simplest-way-to-compile-coffeescript-on-windows/
You can use jcoffeescript as a command-line solution.
It uses a Java-based javascript engine (Rhino) and wraps up the task of compiling coffee-script.js from the CoffeeScript project. This allows it to run the CoffeeScript compiler as a Java program.
The command to use (on Windows/Linux) looks like this:
java -jar jcoffeescript-1.0.jar < foo.coffee > foo.js
You will need to download & build the Java source code (use IntelliJ Community Edition to avoid downloading Ant) or a pre-built download for CoffeeScript v1.0.
I now use jcoffeescript in place of the Ruby solution (another answer here), because this allows me to keep up with the latest CoffeeScript version.
You can use a command-line version of CoffeeScript by installing Ruby on Windows and then installing the CoffeeScript Gem.
After that, the command-line is available, for example, 'coffee bla.coffee' - to compile your CoffeeScript code down to JavaScript code.
The only disadvantage doing it this way (not using Node.js) is that the Ruby version of CoffeeScript is restricted to version 0.3.2 - the last version written in Ruby before it was moved over to Node.js.
*However, I still use the Ruby version of CoffeeScript in my current employment and my personal web page and I don't see much of a problem as this version of CoffeeScript is quite mature and most of the features listed on the CoffeeScript website can be used.
*striked out this last statement which was correct at the time but is becoming more incorrect every few days; CoffeeScript has now advanced a long way since 0.3.2 and is past 1.1
There're already bunch of answers here, but let me add mine. I wrote a .NET library for compiling CoffeeScript on Windows.
As jashkenas suggested, I've used the pre-compiled extras/coffee-script.js file.
Together with the Jurassic JavaScript compiler I've wrapped it all up in a single library: CoffeeSharp
The library also ships with a commandline tool and a HttpHandler for ASP.NET web development.
I've used this one: https://bitbucket.org/maly/coffeescript-win/zealots
looks working well, althouth you need to manually need to update coffee.script from 0.95 to 1.0.1.
Since node.js is now ported to Windows, this is actually pretty easy:
http://www.colourcoding.net/blog/archive/2011/09/20/using-coffeescript-on-windows.aspx
If you want to use CoffeeScript in an ASP.NET application then you can use this HTTP handler to serve compiled CoffeeScript code.
I haven't tried this myself yet, but it seems to be an answer. (I've downloaded and installed but not used it yet.)
There's an add-in for Visual Studio 2010 that adds CoffeeScript editing to VS (among other things).
It's called Web Workbench and is downloaded as a vsix. (i.e. can be downloaded from within the VS UI.)
I'm only putting this in only as an answer to the more general implied question for "How can I try" tools that don't normally run on Windows or have yet to be ported. Use a virtual machine running a UNIX-like OS such as Linux or BSD.
Provided you have enough RAM and are willing to learn enough to get around, it will make trying open source software a lot easier. In the CoffeeScript case you can still do things like --watch on a shared folder and remain in Windows land most of the time. You also won't pollute your system with tools and services you try and don't buy into, which is handy if you do that a lot.
Consider using Chocolatey to install http://chocolatey.org/packages/CoffeeScript on Windows.
(Installing Chocolatey : https://github.com/chocolatey/chocolatey/wiki/Installation)

Can Ruby + Crate + Windows work?

I've got a project for work I'd like to do in Ruby that will have to run on Windows, but perturbing the filesystem for a Ruby install or RubyScript2Exe unpack isn't an option (this is supposed to be the harness for a testing system). Has anyone successfully used Crate to package up something on Windows? If so, what was your build environment like and can you pass on any other hints?
I've tried and worked in getting Crate work under Windows, but is a more complicated system than I would expect.
If extraction of code for your system is your problem. I recommend take a look to Exerb, and specially: exerb-mingw hosted on GitHub exerb-mingw
It will generate a single executable like Ocra or RubyScript2Exe, but with the difference that the source code will not be extracted and extensions will be dynamically loaded.
This works perfectly with RubyInstaller packages, and is being used with Pik (Ruby version manager for Windows).
Hope this helps.
You can embed a Ruby interpreter and script into a C program, which may be easier than trying to run Crate. Here are some helpful links that describe how to do this, and may provide enough sample code to use as a skeleton for what you are trying to build.

Resources