Text 15 Sep 22 notes Running your coffeescript apps on Heroku

If your looking to write your node.js apps in coffeescript and run them on heroku you’ve most likely read this http://stackoverflow.com/questions/6356267/can-i-run-coffeescript-in-heroku question.  It left me scratching my head wondering how they’ve made it sound so complicated.  In reality its quite simple and I’ll show you.

We will use this sample CS/express app for testing:

https://gist.github.com/1220700

Heroku’s new cedar runtime stack uses the existence of a package.json to detect your node.js app so we’ll go ahead and oblige it with a simple one like so:

https://gist.github.com/1220708

Remember to add node_modules to your .gitignore file to keep your slug size down.

Now.  Heroku expects a Procfile to instruct their servers how to run your application. Again this is pretty straight forward and absolutely not specific to coffee-script.

https://gist.github.com/1220715

You’ll not that we’re telling heroku to boot a webworker by running a currently non-existant file ‘boot.js’.  This is where the magic happens that turns your app from a node.js app to a node.js app written in coffeescript. 

https://gist.github.com/1220722

We can simply include coffee-script which augments require to allow it to load coffeescript files. Done and done.

Link 13 Sep New Release: require-jade»

New library adding Jade support to requireJS.  Allows you to include your templates and have a compiled function returned with the signature function(locals), which will return your html as string.

Link 11 May Learnboost releases express-mongoose»

Before this great library there were two ways to supply your views with data.  

Callback soup as demonstrated by TJ Holowaychuk:

https://gist.github.com/967196

Or long lonnnnng filter chains as demonstrated from one of my projects here:

https://gist.github.com/967203

My filter chains can be cleaned up to look like this:

https://gist.github.com/967212

Starting to look a lot better and clearer to me! It’s an exciting time to be a nodejs developer!

Link 20 Apr Alfred Theme - Subtle Transparency»

Created a quick Alfred Theme with a 80% transparency and white background.  Thought I’d share it here

Preview:

Screen shot of transparent alfred theme

If your not using Alfred yet I highly recommend it.  The powerpack is worth it for the terminal commands alone!

Link 21 Mar Music to code to: Lex - Ratatat »
Text 24 Jan 1 note Write your vows in CoffeeScript

Vows is a great node.js BDD framework.  It’s very fast, running your tests asynchronously when possible, or sequentially when controlled execution order is required.

Its incredibly readable and easy to write in its own right but why would that stop us from writing our vows in CoffeeScript!

Taking the example from the vows website

https://gist.github.com/791685

We can write the same in CoffeeScript as below

https://gist.github.com/791686

Personally I think the CoffeeScript version is much more readable with less line noise.  I don’t know about you but this how I’ll be writing my tests for node.js going forward!

For more information on vows be sure to check out there site.  They go into how to write much more complicated tests.  Apply what you leaned here to keep your tests caffeinated! 

Text 18 Jan 2 notes Coffeescript - Leave your curly brackets at the door

So lately my attention has switched to Javascript.  One thing that I noticed, especially coming from ruby, is that Javascript wasn’t a pretty language.  Coffeescript looks to solve this by mashing some good bits of python and ruby together.  

Lets look at some comparisons from http://coffeescript.org

A nested object in Javascript:

https://gist.github.com/781119

And now the same thing in Coffeescript:

https://gist.github.com/781123

It doesn’t solve world hunger or create everlasting piece but it does make it more fun to write javascript.  

Now when I’ve been ranting about it to others in the industry they are skeptical that they should be writing in an intermediate language.  All the while they comment about how much they love writing HAML and SASS. Now I know that there is a difference between Coffeescript and say Haml where one is being compiled into code and the other markup but the comparison stands.

One thing the naysayers have commented on is the fact that Coffeescript has a classical inheritance system built in. Real Javascript professionals don’t try to bend the language *mumble* *mumble* *scratch neck beard* 

The great thing about Coffeescript is you don’t need to use those features which you distrust.  And the compiler will only include the support code features that you use.  Don’t want to use classical inheritance, no problem, don’t know what a list comprehension is* don’t worry just write Coffeescript as you would your Javascript albeit in a more comfortable syntax.

* List compregensions in Coffeescript rock!

https://gist.github.com/781136

Gives us an alert box with [2,3,4,5,6]


Design crafted by Prashanth Kamalakanthan. Powered by Tumblr.