Coffeescript compilation: not as file2file, but as text2text

We can compile coffescript file to js-file with command:

coffee --join path/to/result.js --compile path/to/coffeescript_dir/

But what if I want to compile a piece of coffeescript code (as text) and get piece of js code (as a text too), and they are not files. For example:

  • cs text: "func = () -> 55"

  • js text result: "var func; func = function(){return 55;}"

It must be done from console, or even better from python interactive console :)

Answers


You can use --eval to take a string parameter as coffee input, --bare to avoid the JS output being wrapped in a closure, and --print to print the output on stdout instead of a file:

$ coffee --print --bare -eval 'func = -> 55' 
var func;

func = function() {
  return 55;
};

To call it from Python, you can use the subprocess module:

from subprocess import Popen, PIPE
def compile_cs(cs_code):
    args = ['coffee', '--print', '--bare', '--eval', cs_code]
    return Popen(args, stdout=PIPE).communicate()[0]

Need Your Help

Another knack on the “Dialogs must be user-initiated” Security Exception in Silverlight printing

visual-studio silverlight internet-explorer printing debugging

I get the infamous "Dialogs must be user-initiated" Security Exception when I try to print some stuff in Silverlight. As you can see, the dialog is as user-initiated as can be:

C: printf a float value

c floating-point

I want to print a float value which has 2 integer digits and 6 decimal digits after the comma. If I just use printf("%f", myFloat) I'm getting a truncated value.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.