Monthly Archives: May 2011

CoffeeScriptCookbook.com: How YOU can help!

CoffeeScript is awesome. There’s a HUGE problem with The CoffeeScript Cookbook, however: it does not exist.

Want to help me fix that? Please say yes.

I just bought the domain coffeescriptcookbook.com, and I want to give it to YOU. I mean it. I want to open-source the website code and crowd-source the cookbook content. Partly because I know a lot of folks are WAY smarter than me and partly because I just don’t have enough time to make the CoffeeScript Cookbook as awesome as I need it to be.

Ideally I want to build a sort of “vettable wiki” or perhaps a very trusting git-based website, where people can submit code samples quickly and easily (but still have some way to prevent people publishing XSS attacks without any kind of safeguard). Here’s a short list of what I would like. If any of this enthuses you, please send mail to my gmail account, “ratgeyser”. [Edit: added Geoffrey Grosenbach’s excellent tips]

Getting the Cookbook code/site off the ground:

  • Cookbook versioning. As of this writing, CoffeeScript is at 1.0.1. When it updates, I’d like people to be able to see in the cookbook what version introduced or changed a feature, or even to say “I’m using version x.y.z, please only show me valid recipes for that version.”
  • Syntax highlighting. Sort of obvious there, I guess.
  • Examples runnable in-browser, the same way they are on The Main CoffeeScript Website.
  • Automated recipe testing. Essentially, if you submit a recipe that’s supposed to evaluate 3 + 4, you should be able to put something like # => 7 underneath it, and if the code DOESN’T evaluate to 7, the recipe should be flagged as broken.
  • With automated recipe testing in place, we now have the ability to check a recipe against various versions of CoffeeScript. You write a recipe for version 1.1.0, and the site can immediately say “works in 1.1.0 and 1.0.2 and 1.0.1 but not in 1.0.0”. Then it can add those recipes to the cookbooks for those versions. Also, when a new version of CoffeeScript is released, all recipes can be checked against it instantly, and you immediately get a working Cookbook for that version.
  • Website design that doesn’t suck. I’m a programmer, I draw boxes around everything and every website I design looks like ass. And not just regular ass, I mean ass from 1996.

Contributing CoffeeScript Examples

  • Promotes good CoffeeScript style (as opposed to code that compiles but isn’t idiomatic)
  • Helps new programmers learn how to get over common roadblocks
  • Self-checkable examples where possible (see the bit above about automated testing)

Thoughts? Ideas? Offers to help? Let me know!

Tourbus 2 is Out!

I just released Tourbus 2.0! You can get it by cloning the tourbus repo in that link, or by simply installing the gem from rubyforge.

What’s TourBus?

TourBus is a ruby framework for stress-testing a website. You define “Tourist” classes that “tour” their way through your site, and then tell tourbus to send a load of them at your site.

What’s New

Better Syntax, and tested support for most rubies. TourBus 2.0 has been tested and found worky on:

  • JRuby 1.6.0 <– strongly recommended, as it has better threading
  • MRI 1.8.7p334
  • MRI 1.9.2p180
  • REE 1.8.7-2011.03

Upgrading from Tourbus 0.9

  • Your tour classes will change; they are now called tourists and they go on tours, instead of being called tours who run tests (which really never made sense anyway)
  • Open your tour class, and change it to inherit from Tourist instead of Tour.
  • Change before_tests and after_tests to before_tours and after_tours.
  • Rename all your test_ methods to be tour_ methods. E.g. “def test_simple” => “def tour_simple”
  • That’s it! Tourbus should now run normally.

Quick and Easy Setup

gem install tourbus

Okay, let’s say you have a website running at localhost:3000 and you want to test that home.html includes the text “hi there” even when being pounded by hundreds of visitors at once. Let’s install and set up everything all at once! cd into your project folder, and do the following:

mkdir tours
 
echo 'class Simple tours/simple.rb

That’s it, you now have a tourist ready to wander over to your site and request the home page. Let’s run him and see that everything’s okay:

tourbus

You should see a clean run followed by a text report showing what happened. If that worked, let’s make your tourist go through the website 10 times in a row. But let’s ALSO make 100 different tourists to the same 10 laps with him, all at once:

tourbus -n 10 -c 100

Happy server stressing! Check out the README for more info.

Bonus: Isolating Tourbus

Here’s how I like to install tourbus. I cd into my development folder, and then do:
rvm install jruby-1.6.0
rvm use jruby-1.6.0
rvm gemset create tourbus
rvm gemset use tourbus
git clone git://github.com/dbrady/tourbus.git
cd tourbus
gem install bundler
bundle install
gem build tourbus.gemspec
gem install tourbus-2.0.1.gem # (update version if it changes)

Next I cd into my project and do

echo 'rvm use jruby-1.6.0@tourbus' > .rvmrc

This lets me run tourbus under jruby and its own gemset, so even if my website is running rails on MRI, I can still get the lovely JVM native threads when tourbussing my site.