The British Ruby Conference

In this episode, Peter and Jason discuss the British Ruby Conference, Ruby 1.9.3-p327, Capybara 2.0.0, and more.

Also, huge apologies for Jason’s audio quality in this episode. There was a hiss that showed up after recording that couldn’t be fixed. Listen at your own risk!

Async JavaScript and Mac Kung Fu, 2nd Ed. in print and shipping

Async JavaScript and Mac Kung Fu, 2nd Ed. in print and shipping

The Split is Not Enough: Unicode Whitespace Shenigans for Rubyists

That code is legal Ruby! If you ran it, you’d see 8. How? There’s a tale to tell..

The String with the Golden Space

I was on IRC in #nwrug enjoying festive cheer with fellow Northern Rubyists when ysr23 presented a curious problem.

He was using a Twitter library that returned a tweet, "@twellyme film", in a string called reply. The problem was that despite calling reply.split, the string refused to split on whitespace. Yet if he did "@twellyme film".split in IRB, that was fine.

International man of mystery Will Jessop suggested checking $; (it’s a special global variable that defines the default separator for String#split). It was OK.

In an attempt to look smarter than I am, I suggested reply.method(:split).source_location to see if the String class had been monkey-patched by something annoying. Nope. (Though this is a handy trick if you do want to detect if anyone’s tampered with something.)

Someone suggested Mr. Ysr23 show us reply.codepoints.to_a:

# reply.codepoints.to_a
 => [64, 116, 119, 101, 108, 108, 121, 109, 101, 160, 102, 105, 108, 109]

Something leapt out at me. Where was good old 32!? Instead of trusty old ASCII 32 (space) stood 160, a number alien to my ASCII-trained 1980s-model brain.

From Google with Love

To the Google-copter!

Aha! Non-breaking space. That’s why split was being as useful as a chocolate teapot.

After an intense 23 seconds of discussion, we settled on a temporary solution for Mr. Ysr23 who, by this time, was busy cursing Twitter and all who sailed upon her:

reply.gsub(/[[:space:]]/, ' ').split

The solution is simple. Use the the Unicode character class [[:space:]] to match Unicode’s idea of what whitespace is and convert all matches into vanilla ASCII whitespace. reply.split(/[[:space:]]+/) is another more direct option – we just didn’t think of it at the time.

Quantum of Spaces

Solving an interesting but trivial issue wasn’t where I wanted to end my day. I’d re-discovered an insidious piece of Unicode chicanery and was in the mood for shenanigans!

Further Googling taught me you can type non-breaking spaces directly on OS X with Option+Space. (You can do the homework for your own platform.)

I also knew Ruby 1.9 and beyond would let you use Unicode characters as identifiers if you let Ruby know about the source’s encoding with a magic comment, so it was time for shenanigans to begin!

My first experiment was to try and use non-breaking spaces in variable names.

Cool! So what about variable names and method names?

What about without any regular printable characters in the identifiers at all?

And so we’re back to where we started. A hideous outcome from a trivial weekend on IRC. But fun, nonetheless. Stick it in your “wow, nice, but totally useless” brain box.

A Warning

Please don’t use this in production code or the Ruby gods will come and haunt you in your sleep. But.. if you want to throw some non-breaking spaces into your next pair programming session, conference talk, or job interview, just to see if anyone’s paying attention, I’ll be laughing with you. (And if you’re a C# developer too, Andy Pike tells me that C# supports these shenanigans too.)

P.S. My Ruby 2.0 Walkthrough Kickstarter only has about 12 hours to go! Check it out if Ruby 2.0 is on your radar or you want a handy way to get up to speed when it drops in February 2013.

Archiving OnRails.org

Since I started blogging on my corporate blog I neglected this blog. It is a little ironic as I’m doing more Rails work than ever and I have a few blog posts comming up. I contacted Lee Marlow and Solomon White, my long time cohosts of this blog and authors of some of the most famous blog entries of this blog, and we decided to put it in archival mode. We won’t add new entries but thought that as there was some good and now historical material we could just keep around.

Enjoy!

– Daniel.

Archiving OnRails.org

Since I started blogging on my corporate blog I neglected this blog. It is a little ironic as I’m doing more Rails work than ever and I have a few blog posts comming up. I contacted Lee Marlow and Solomon White, my long time cohosts of this blog and authors of some of the most famous blog entries of this blog, and we decided to put it in archival mode. We won’t add new entries but thought that as there was some good and now historical material we could just keep around.

Enjoy!

  • Daniel.

This Week in Ruby: Ruby 2.0 Refinements, Cost of GC::Profiler, and BritRuby Cancelled

Welcome to this week’s roundup of Ruby news, articles, videos, and more, cobbled together from my e-mail newsletter, Ruby Weekly. If you’ve been celebrating Thanksgiving this week, I hope you’re having a good break.

Highlights include: Charles Nutter on Ruby 2.0 refinements, the cancellation of the British Ruby Conference, and DHH’s latest object instantiation (thanks Doug Renn).

Featured

Refining Ruby (or The Best Study of Ruby 2.0 Refinements Yet)
I’ve editorialized the title somewhat but this article by Charles Nutter is a great look into the world of ‘refinements’ in Ruby 2.0, what they’re intended for, and all of the challenges they throw up, both for developers and language implementers.

The British Ruby Conference.. Cancelled
It’s a pretty long story but the British Ruby Conference, which I was getting rather excited about.. is no more. There’s a statement as to why but if you want to join

Continue reading “This Week in Ruby: Ruby 2.0 Refinements, Cost of GC::Profiler, and BritRuby Cancelled”

This Week in Ruby: Ruby 2.0 Refinements, Cost of GC::Profiler, and BritRuby Cancelled

Welcome to this week’s roundup of Ruby news, articles, videos, and more, cobbled together from my e-mail newsletter, Ruby Weekly. If you’ve been celebrating Thanksgiving this week, I hope you’re having a good break.

Highlights include: Charles Nutter on Ruby 2.0 refinements, the cancellation of the British Ruby Conference, and DHH’s latest object instantiation (thanks Doug Renn).

Featured

Refining Ruby (or The Best Study of Ruby 2.0 Refinements Yet)
I’ve editorialized the title somewhat but this article by Charles Nutter is a great look into the world of ‘refinements’ in Ruby 2.0, what they’re intended for, and all of the challenges they throw up, both for developers and language implementers.

The British Ruby Conference.. Cancelled
It’s a pretty long story but the British Ruby Conference, which I was getting rather excited about.. is no more. There’s a statement as to why but if you want to join the melee of conversation, try here or here. Luckily other attempts are now afoot – news coming soon.

DHH’s Latest Project: Colt Heinemeier Hansson
It’s DHH’s latest release 🙂 Congratulations to him and his growing family. And before anyone complains about having a human interest story here, cheer up a bit – it’s Thanksgiving 😉

Edge Rails Now Tested on Ruby 2.0 with Travis CI
Little to read but Ruby 2.0 is now most clearly on the edge Rails developers’ radar.

Reading

Deploying Ruby Applications to AWS Elastic Beanstalk with Git
Just last week, Amazon announced Ruby support for its AWS Elastic Beanstalk semi-automated deployment and scaling system. This tutorial by Loren Segal fills in all the blanks by walking us through using it from start to finish with a Rails app.

Zen and The Art of Speaking at RubyConf 2012 – The dRuby Way
An excellent story and walkthrough about both preparing a talk for RubyConf 2012 and what happened while the speaker was there. More articles like this please.

The Cost of Ruby 1.9.3’s GC::Profiler
James Golick presents an examination of the flaws in Ruby 1.9.3’s included garbage collector instrumentation in his typically punchy style. Luckily he presents a potential solution too: GC::BasicProfiler.

Is Your Application Running with Ruby – Slow?
Two developers moved a large Ruby webapp between two machines and experienced a 50% drop in performance. Why? Clue: It was something to do with RVM.

A 2012 Mac Setup for Ruby development
We see articles like this quite often but there are a lot of handy links here despite not being particularly Ruby focused.

A Lightweight ‘CMS’ Using Ruby and Google Drive
An interesting approach to content management. Let users enter text in a Google Drive spreadsheet, grab it with Ruby, and use the data to create your content or templates locally.

A ‘yield’ Gotcha Every Ruby Developer Should Be Aware of
It’s not a true yield gotcha but is something you might trip over nonetheless regarding earlier than expected returns. Luckily, ‘ensure’ blocks help save the day.

Profiling Ruby (or How I Made Rails Start Up Faster)
Four steps: measure, find the problem, fix, and repeat.

Watching and Listening

Guest User Records – RailsCasts
Ryan Bates is back with another Rails Cast, this time demonstrating how to create a ‘temporary guest record’ in a Rails app so users can try out apps without filling in their information up front.

Matz Speaking at LinkedIn about Ruby
Back in October, Matz spoke at LinkedIn about his background, Ruby’s history, and his current work. I enjoyed this.

Libraries and Code

Convert Syck to Psych YAML Format
Change has been afoot with Ruby’s attitude to YAML parsing for a while now but the shift from Syck to Psych can still cause issues. If you still have legacy Syck-produced YAML files around that are causing problems, this code might help.

Daybreak: A Simple Key/Value Store for Ruby
Very lightweight and very Ruby (in the best possible way).

chruby: Changes The Current Ruby
An ‘ultra-minimal’ (around 80 lines) alternative to RVM and rbenv. chruby allows one to install rubies into /usr/local/$ruby, /opt/$ruby or ~/.rubies/$ruby but install gems into ~/.gem/$ruby/$version. chruby only modifies $PATH, $GEM_HOME and $GEM_PATH, and does not hook cd or rely on shims.

Jobs

Last but not least..

Giles Bowkett: ‘I Wrote An eBook In A Week’
Being silly enough to not send me a copy for review or give me a title, all I can do is say Giles has written an interesting sounding book about how ‘DHH gets OOP wrong’ but why that’s OK. It costs money but hopefully we’ll see some reviews soon. He does have a no-quibble refund policy, however, and his writing is always an eye opener.

#393 Guest User Record

Instead of presenting a sign up form to the user, consider creating a temporary guest record so the user can try out the application without filling in their information up front. They can then become a permanent member afterwards.

Ruby Programming 38th Batch: Registrations now open

Registrations are now open for RubyLearning’s popular Ruby programming course. This is an intensive, online course for beginners that helps you get started with Ruby programming.

Here is what Demetris Demetriou, a participant who just graduated, has to say – “When I joined this course I was sceptical about how useful this course would be for me instead of reading material and watching videos on YouTube and thus saving money. After the course started I realised how valuable this course was. In the past I had read many Ruby books over and over, but never got into really getting practical with it and never had confidence in it. Lots of theory but couldn’t use it. I feel that the exercises in this course and the support, monitoring from our mentor Victor, made the huge difference that all books in the past didn’t. It wasn’t about reading lots of books, but simply few things and get practical and understand them well. I feel I learnt a lot and I’m coming back for more to rubylearning.org Thanks a lot Victor and Satish and all the other Rubyists who gave us today’s Ruby.”

What’s Ruby?

Ruby

According to http://www.ruby-lang.org/en/ – “Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. Ruby’s elegant syntax is natural to read and easy to write.”

Yukihiro Matsumoto, the creator of Ruby, in an interview says –

I believe people want to express themselves when they program. They don’t want to fight with the language. Programming languages must feel natural to programmers. I tried to make people enjoy programming and concentrate on the fun and creative part of programming when they use Ruby.

What Will I Learn?

In the Ruby programming course, you will learn the essential features of Ruby that you will end up using every day. You will also be introduced to Git, GitHub, HTTP concepts, RubyGems, Rack and Heroku.

Depending on participation levels, we throw a Ruby coding challenge in the mix, right for the level we are at. We have been known to give out a prize or two for the ‘best’ solution.

Who’s It For?

A beginner with some knowledge of programming..

You can read what past participants have to say about the course.

Mentors

Satish Talim, Michael Kohl, Satoshi Asakawa, Victor Goff III and others from the RubyLearning team.

Dates

The course starts on Saturday, 8th Dec. 2012 and runs for eight weeks (one week break for Christmas and New Year).

RubyLearning’s IRC Channel

Most of the mentors and students hang out at RubyLearning’s IRC (irc.freenode.net) channel (#rubylearning.org) for both technical and non-technical discussions. Everyone benefits with the active discussions on Ruby with the mentors.

How do I register and pay the course fees?

Please Note: We will not be processing registrations from 25 Nov. until 3 Dec. 2012.

  • The course is based on the The Ultimate Guide to Ruby Programming eBook. This book is normally priced at US$ 19.95 and we are discounting it US$ 10.00 by combining it in the Course+eBook option below.
  • You can pay either by Paypal or send cash via Western Union Money Transfer or by bank transfer (if you are in India). The fees collected helps RubyLearning maintain the site, this Ruby course, the Ruby eBook, and provide quality content to you.
  • Once you pay the fees below, register on the RubyLearning.org site and send us your name and registered email id while creating an account at RubyLearning.org to satish [at] rubylearning [dot] com We will enrol you into the course within 48 hours.
  • If you have purchased the eBook at the time of registration, we will personally email you the eBook within 48 hours.

You can pay the Course Fees by selecting one of the three options from the drop-down menu below. Please select your option and then click on the “Buy Now” button.

Options

At the end of this course you should have all the knowledge to explore the wonderful world of Ruby on your own.

Here are some details on how the course works:

Important:

Once the course starts, you can login and start with the lessons any day and time and post your queries in the forum under the relevant lessons. Someone shall always be there to answer them. Just to set the expectations correctly, there is no real-time ‘webcasting’.

Methodology:

  • The Mentors shall give you URL’s of pages and sometimes some extra notes; you need to read through. Read the pre-class reading material at a convenient time of your choice – the dates mentioned are just for your guideline. While reading, please make a note of all your doubts, queries, questions, clarifications, comments about the lesson and after you have completed all the pages, post these on the forum under the relevant lesson. There could be some questions that relate to something that has not been mentioned or discussed by the mentors thus far; you could post the same too. Please remember that with every post, do mention the operating system of your computer.
  • The mentor shall highlight the important points that you need to remember for that day’s session.
  • There could be exercises every day. Please do them.
  • Participate in the forum for asking and answering questions or starting discussions. Share knowledge, and exchange ideas among yourselves during the course period. Participants are strongly encouraged to post technical questions, interesting articles, tools, sample programs or anything that is relevant to the class / lesson. Please do not post a simple "Thank you" note or "Hello" message to the forum. Please be aware that these messages are considered noises by people subscribed to the forum.

Outline of Work Expectations:

  1. Most of the days, you will have exercises to solve. These are there to help you assimilate whatever you have learned till then.
  2. Some days may have some extra assignments / food for thought articles / programs
  3. Above all, do take part in the relevant forums. Past participants will confirm that they learned the best by active participation.

Some Commonly Asked Questions

  • Qs. Is there any specific time when I need to be online?
    Ans. No. You need not be online at a specific time of the day.
  • Qs. Is it important for me to take part in the course forums?
    Ans. YES. You must Participate in the forum(s) for asking and answering questions or starting discussions. Share knowledge, and exchange ideas among yourselves (participants) during the course period. Participants are strongly encouraged to post technical questions, interesting articles, tools, sample programs or anything that is relevant to the class / lesson. Past participants will confirm that they learned the best by active participation.
  • Qs. How much time do I need to spend online for a course, in a day?
    Ans. This will vary from person to person. All depends upon your comfort level and the amount of time you want to spend on a particular lesson or task.
  • Qs. Is there any specific set time for feedback (e.g., any mentor responds to me within 24 hours?)
    Ans. Normally somebody should answer your query / question within 24 hours.
  • Qs. What happens if nobody answers my questions / queries?
    Ans. Normally, that will not happen. In case you feel that your question / query is not answered, then please post the same in the thread – “Any UnAnswered Questions / Queries”.
  • Qs. What happens to the class (or forums) after a course is over? Can you keep it open for a few more days so that students can complete and discuss too?
    Ans. The course and its forum is open for a month after the last day of the course.

Remember, the idea is to have fun learning Ruby.

Technorati Tags: , , ,


(Powered by LaunchBit)

This Week in Ruby: MRI 1.9.3-p327, Rails 3.2.9, Capybara 2.0, and the Fukuoka Ruby Award

Welcome to this week’s roundup of Ruby news, articles, videos, and more, cobbled together from my e-mail newsletter, Ruby Weekly.

Highlights include: MRI 1.9.3-p327, Rails 3.2.9, Capybara 2.0, and the Fukuoka Ruby Award.

Featured

Ruby 1.9.3-p327 Released: Fixes a Hash-Flooding DoS Vulnerability
Carefully crafted strings can be used in a denial of service attack on apps that parse strings to create Hash objects by using the strings as keys. This new patch level release of 1.9.3 counters the issue.

2013 Fukuoka Ruby Award Competition
Each year Matz and the Government of Fukuoka in Japan run an award for Ruby programs. Submit by November 30th to enter – it doesn’t have to be an all new app either. The grand prize is 1 million yen (about $12,000).

Capybara 2.0.0 Released: The Acceptance Test Framework for Webapps
Not backwards compatible with Capybara 1.x so be careful and read the notes. It also drops support for Ruby 1.8.

Reading

Printing ‘Hello, World’ in Style (Concurrently)
Daniel Szmulewicz looks at what’s involved in using Celluloid and two actors to print out ‘Hello, World’.

Matz Is Not A Threading Guy
Jesse Storimer talks about the status of concurrency in Ruby and Matz’s opinions in a Q+A session at RubyConf. Reinforcing the status quo, Matz said: ‘Using multiple processes is the best way to do concurrency in MRI for the near future.’

rspec-rails and Capybara 2.0: What You Need to Know
Andy Lindeman of the RSpec core team talks about the new Capybara 2.0 release and what you need to be aware of when using it with RSpec and Rails.

Why Ruby Class Methods Resist Refactoring
Bryan Helmkamp demonstrates why he thinks class methods are much trickier to refactor than instance methods.

Reference Graphs as Tools for Refactoring
A quick look at using graphs of references in order to refactor Ruby code.

Watching and Listening

How I Set out to Benchmark an Algorithm and Ended Up Fixing Ruby
Joshua Ballanco wanted to build a delegation library but got lured into the worlds of benchmarks and garbage collectors.

Ten Things You Didn’t Know You Could Do in Ruby
A month ago, we linked to the slidedeck of James Edward Gray II’s Aloha on Rails talk with 101 various Ruby tricks and code snippets. Now the video is available too! Enjoy.

The Ruby Rogues on Documenting Code
The Ruby Rogues tackle a sore subject: documentation.

Libraries and Code

ruby-lint: Static Code Analysis and Linter for Ruby
Currently a prototype and work in progress so your mileage may vary. It makes it possible for developers to detect errors such as undefined or unused variables and the use of non existing methods.

Spinel: A New, ‘Ruby-Infused’ Open Source Game Engine
Spinel is a new open source game engine still under development that uses ‘mruby’ (the embeddable Ruby interpreter Matz is currently working on) as its scripting layer while leaning on speedy C/C++ under the hood.

Version Cake: An Unobtrusive Way to Version APIs in Your Rails App
Easily version views with their API version in the filename (e.g. index.v3.xml.builder). The cool part is if a request comes in for a different version, the closest version will be used.

Jobs

Test Driven JavaScript and Ruby Developer [San Francisco and Santa Monica, CA]
Carbon Five builds web and mobile products for startups, institutional companies and non-profit organizations using a finely tuned agile process with cutting edge tools and technology. Join a team of seasoned pros in a highly-collaborative environment and work on a new project every couple of months.

Last but not least..

Write Faster Rails Tests: Insights via E-mail
Get an infrequent e-mail from Thoughbot’s Ben Orenstein packed with battle tested advice for speeding up your Rails apps’ tests.

What’s Up?

Oh yeah, things happening…

Got A New Job, Got A New Office

First off, I’ve started a new job as a Senior Developer and Agile Coach at Table XI, putting me back in the realm of small, Chicago-based consulting companies. Very exited, Table XI seems like a great place so far. Hoping to do new things, challenge myself, and learn.

Book Update

Most importantly, you can still buy it.

It’s going slowly but steadily, thanks for asking. I’m determined to start releasing weekly even if it means that I cut off the book in mid-sentence. Hoping that will start next Monday. The remaining Backbone chapter is something like 1/3 to 2/5 done.

Next up, Ember. I was already placed on a blog post of Ember.js resources, which is quite flatteringly optimistic given that the Ember stuff doesn’t technically exist yet. A couple of members of the Ember team have reached out and offered some technical assistance, all of which is very nice, and motivating, and terrifying.

Anyway, the Ember stuff is going to be interesting because, first off, Ember is still a rapidly moving target. I had hoped they’d have locked down a 1.0 API by now, but given the comments made on the recent JS Jabber podcast, it looks like we still have some movement coming. Also, it seems as though the nature of Ember implies a more complex example to really show it off. Still hopeful that I’ll be able to start pushing out Ember content in December, though.

Cons

The video from WindyCityRails is now up, as well as the slides from the evolutionary decendent of the talk from RailsConf — the RailsConf video should be up in a couple of days. There’s a blog post in progress exploring the common theme of those talks, as well as a couple of speakers at SCNA who came at similar themes.

Rubinius 2.0.0.rc1

In this episode, Peter and Jason talk about the Ruby 2.0 walkthrough, Rails 4.0, Rubinius 2.0.0.rc1, and much more.

Check out Peter’s Kickstarter for the Ruby 2.0 walkthrough!

iOS 6 SDK Development, now in print and shipping

Hacking Buildpacks

Buildpacks are an extremely powerful tool for specifying the ecosystem of tools and dependencies packaged with your Heroku application and controlling the way the application is built from code to a deployed app.

In the post announcing the release of buildpacks we illustrated this point, explaining how buildpacks provide the mechanism by which Heroku supports a variety of languages and frameworks, not just Ruby and Rails. We also briefly covered some of the end-user customizations that can be achieved with custom buildpacks, such as adding binary support and modifying the build process.

Today we’ll examine the basic structure of buildpacks and study some example customizations to better understand how they can be used to extend the capabilities of the Heroku defaults.

The Anatomy of a Buildpack

At its core, a buildpack is a collection of 3 Bash scripts stored in the bin directory. These scripts are called detect, compile, and release. We’ll take a quick look at how each of these scripts contributes to supporting a specific language or framework.

An excellent skeleton buildpack with all of these minimal components is Ryan Smith’s null-buildpack. If you’re creating a buildpack from scratch, forking null-buildpack is a good place to start.

detect

The bin/detect script is important to Heroku’s default buildpacks. When an app is deployed, the detect script is used to figure out which buildpack is appropriate for the project.

Most buildpacks detect frameworks by searching for certain config files. For example, the Ruby buildpack looks for a Gemfile. The Node.js buildpack looks for packages.json, and the Python buildpack looks for requirements.txt.

If a buildpack matches, it returns an exit code of 0 and prints the language/framework name to STDOUT. The aforementioned null-buildpack shows what an absolutely minimal detect script would look like.

In the case of custom buildpacks you’ll be specifying the buildpack directly, so detection isn’t as important, and a minimal detect script is usually sufficient.

compile

The bin/compile script is where most of the magic happens. This script takes 2 arguments, BUILD_DIR and CACHE_DIR.

BUILD_DIR gives you a handle for the root directory of the app, so you can read and write files into the slug. This is where binaries are installed, Heroku-specific config files are written, dependencies are resolved and installed, and static files are built.

CACHE_DIR gives you a location to persist build artifacts between deployments.

We’ll take a closer look at modifying the slug and caching build artifacts in the examples below.

release

Whereas the bin/compile script modifies the slug, the bin/release script modifies the release. Instead of modifying files, this script returns a YAML-formatted hash to define any default config variables, Add-ons, or default process types needed by the buildpack.

Now that we understand the basic structure of buildpack scripts and their roles, lets take a look at some example hacks.

Example 1: Adding Binaries for Language Support

The ability to install binaries is critical for most language support. Richard Schneeman’s mruby buildpack article over on RubySource provides an excellent example of installing custom binaries to support a new language.

Building the binary files with Vulcan

The first step for getting new binaries onto Heroku is building them in such a way that they can be run on Heroku dynos (64-bit Linux virtual machines). It turns out that building these binaries directly on Heroku is the easiest method, since the operating system of a Heroku dyno contains common Linux development tools.

Heroku user Jonathan Hoyt discovered these tools early on and blogged about the process of building xpdf for Heroku using:

  • heroku run bash to boot a new dyno and get a bash session on it
  • curl to download the source
  • make to build the project
  • scp to copy the build artifacts to a local machine

Although you could certainly copy Jon’s procedure, Heroku now provides a tool called Vulcan to make this process much easier. The vulcan create command deploys a custom app to Heroku under your account. Once the app is created, you use the vulcan build command to upload source, build the project, and download the results all in one step.

For more info on Vulcan, see its README and the Heroku Dev Center article on packaging binaries.

Hosting the built files

Once Vulcan has completed and the build artifacts have been downloaded, you’ll need to host them somewhere on the web so that Heroku’s build servers will be able to download them. Heroku’s default language binaries are stored on AmazonS3, for example. Make sure the location you use is publicly readable.

Modifying the compile script

Next you need to make the buildpack copy the binary files down into your project. This is done in the buildpack’s bin/compile script. We can again refer to the mruby buildpack for a straightforward example of how the files are copied down. The steps used are as follows:

  1. Change directories into the build directory. (This directory will be the root of any apps deployed with this buildpack.)

  2. Fetch the archive of the binary files.

  3. Make a directory under /vendor to store the binaries.

  4. Extract the archive.

Modifying the PATH

Finally, you’ll need to add the location of your binaries to the PATH environment variable so that they can be called from anywhere. As discussed earlier, default environment variables are defined by the YAML string returned by the bin/release script. Here you can see PATH being set for the mruby binaries.

Example 2: Using the Build Cache to Speed Up Deployments

The default Ruby buildpack provides support for the Rails asset pipeline by running rake assets:precompile, building shorthand source like coffeescript and sass files into static, browser-consumable javascript and css files. As long as the correct conditions are met, this task will be run on every deploy. Unfortunately, assets:precompile can be very slow, especially on large projects with lots of assets.

To address this slowness, Nathan Broadbent released the turbo-sprockets-rails3 gem. TurboSprockets only compiles assets whose source files have changed, making the asset compilation step much faster after the initial run. This is a nifty enhancement, but it depends on the ability to cache assets between builds. This is where the CACHE_DIR argument to the compile script comes in handy.

(NOTE: The Ruby buildpack is a bit different in that it’s not totally Bash. The bin/compile script invokes a Ruby script. The Ruby code provides some convenience methods for manipulating files in and out of the build cache.)

Nathan forked and extended the default Ruby buildpack to take advantage of turbo-sprockets-rails3’s abilities. This buildpack modifies the default behavior by loading cached files from CACHE_DIR/public/assets into BUILD_DIR/public/assets. The assets:precompile task then runs as usual, but since turbo-sprockets-rails3 is installed, any unmodified assets won’t be rebuilt. The script then runs a custom asset expiration task, storing assets back to CACHE_DIR/public/assets if it’s successful, and clearing CACHE_DIR/public/assets if it fails.

Example 3: Installing Framework Tools

Many popular languages have several competing frameworks for web apps; Rails and Sinatra for Ruby and Django and Pylons for Python are some well-known examples. Usually, these frameworks are contained within a few libraries, so if you want to support a new framework it makes sense to modify existing language buildpacks instead of starting from scratch. James Ward took this approach when he wanted to support Revel, a web framework for the Go programming language.

First he forked the existing Go buildpack.

Next, he modified the bin/detect script to look for a Revel-specific file and announce that it’s a Revel buildpack.

Then he added some functionality to the end of the bin/compile script to fetch and build Revel.

A new line in the bin/release script defines a default web process in the Procfile for running Revel.

Conclusion

I hope this tour into hacking buildpacks has been informative, and you’ve gained some insight into how buildpacks work and how they can be extended to meet your needs. Whether you want to host apps in a new language, or tweak the tools for an existing one, buildpacks are a step towards always answering "yes" to the question, "Does it run on Heroku?"

For more reference information, please check out the buildpack articles available in our Dev Center.

This Week in Ruby: Rubinius 2.0-rc1, Rake 10, Refactoring video, Passenger 4.0 supports JRuby, and more

Welcome to this week’s roundup of Ruby news, articles, videos, and more, cobbled together from my e-mail newsletter, Ruby Weekly.

Highlights include: Passenger 4.0 gets support for JRuby and Rubinius, Ben Orenstein’s awesome refactoring video, Pat Shaughnessy’s new ‘Ruby Under a Microscope’ book, AWS adds Ruby support to Elastic Beanstalk, and more.

Featured

Rubinius 2.0.0 Release Candidate 1
Sadly the Rubinius blog seems to be on hiatus but plenty of people noticed Rubinius 2.0.0rc1 has been tagged. Rubinius is an alternative Ruby implementation largely written in a subset of Ruby itself and the 2.0 release brings 1.9 syntax to the fore.

Pat Shaughnessy’s ‘Ruby Under a Microscope’ Now Available
It’s a great time for indie books in the Ruby world lately and this is no exception. Pat’s book is a truly deep dive into Ruby’s internals with lots of diagrams and lucid explanations to help you along the way.

Phusion Passenger 4.0 Now Supports JRuby and Rubinius
Phusion’s popular Ruby app deployment module for Nginx and Apache takes another leap forward by extending support from just MRI to JRuby and Rubinius. This could be big.

Refactoring from Good to Great
Thoughtbot’s Ben Orenstein takes a brave approach of ditching slides and going with live coding to boldly refactor where no presenter has refactored before.

Amazon Adds Ruby Support to AWS Elastic Beanstalk
Amazon’s Elastic Beanstalk service provides a way to quickly deploy and manage apps within AWS’s cloud of services (EC2, S3, etc.) It now supports Ruby apps by using Phusion’s Passenger (I hope Amazon are paying Phusion handsomely for this :-))

Reading

Yet Another Ruby Shootout: MRI 1.9.3 vs MRI 2.0 vs Rubinius 2.0
Igor Alexandrov picks up where Antonio Cangiano left off by benchmarking MRI 1.9.3-p286, MRI 2.0.0-preview1 and Rubinius 2.0.0-rc1. As always with benchmarks, don’t read too deeply but it seems Ruby 2.0.0 holds its own so far.

‘require is slow in its bookkeeping; can make Rails startup 2.2x faster’
An issue on the official MRI issue tracker that shares a patch which can improve the performance of ‘require’. Follows on to the work seen optimizing code loading in Ruby 1.9.3 in June 2011.

Ruby 2.0 Preview Available on Heroku
It’s still only a preview so don’t pull out your production apps yet, but Heroku’s polyglot stack supports Ruby 2.0 preview 1 without much work at all.

Reinventing Wheels of Future: Matz’s RubyConf Keynote Slides
No technical content as such but Matz celebrates the reinventing of wheels and confesses his love for PHP. Worth a quick swipe through for the sentiments.

Game Development and Ruby
Another slide-deck from RubyConf, this time sharing some options and opinions on game development in Ruby.

RubyConf Roundup: Day One
If you missed RubyConf, here are some handy notes for the talks that Mike Leone attended.

Dead Simple Login System for Rails Apps with OmniAuth and Facebook
In just six special steps with Gal Steinitz.

Let’s Not: Refactoring RSpec Specs with Plain Ruby Methods
A look at using plain Ruby methods rather than DSL constructs with RSpec.

Thinking in Objects
Josh Susser drops some object orientation principles on us in his RubyConf 2012 slides.

Building a Peer-to-Peer Chat System using Multicasting in Ruby
IP multicasting allows you to send a datagram to multiple recipients on a network. In this post John Pignata looks at multicasting and creates a simple chat system using Ruby’s socket library.

Ruby’s EventMachine Part 3: Thin
Phil Whelan continues his blog series looking at EventMachine, this time with a quick explanation of how the Thin Web server library uses it.

Making Queries More Composable with ActiveRecord and Arel
Mike Swieton says it isn’t always clear how to get ActiveRecord and Arel to tackle certain difficult database queries so he shares some pointers he figured out here.

A High Level Overview of Acceptance Testing
A straightforward slidedeck from Andy Lindeman of the RSpec core team.

Upgrading to Rails 4 – A Parameters Security Tour
A look at what’s going to change for parameters in controllers from Rails 3 to Rails 4.

Profiling JRuby with NetBeans
The NetBeans IDE includes a profiler for Java which you can twist to profiling JRuby apps instead. Patrick Polycrystal shows us how.

Collecting Metrics from Ruby Processes with Zabbix Trappers
‘Zabbix Trappers’ will be my new name if I ever get abducted by aliens and taken to their home planet. (Back in the real world, Zabbix is an ‘enterprise-class open source distributed monitoring solution.’)

Watching and Listening

RailsCasts Digs Into Rails 4.0’s Turbolinks
A 7 minute tour of ‘turbolinks’ (as will feature prominently in Rails 4.0) with Ryan Bates.

Wrangling Large Rails Codebases
Stephan Hagemann looks at ways to wrestle with large Rails apps to get faster test suites, cleaner structures, and generally more flexible apps.

Modular & Reusable Front-End Code With HTML5, Sass and CoffeeScript
Keeping your Rails app’s front-end code clean can be tricky. Find out how to keep things tidy and reusable using the HTML5 document outline and modular Sass and CoffeeScript.

To Mock or Not to Mock
Mock objects for testing purposes have their supporters and detractors. At Rocky Mountain Ruby 2012, Justin Searls gave a ‘broad-stroke survey’ of the different ways developers use mocks/test doubles and guidelines to bring everyone to a happy medium.

Yay! Mocks!
45 minutes with Corey Haines.

Git and GitHub Secrets
Zach Holman, GitHub’s chief of spreading the love, gives us a peek behind the Git and GitHub curtains and shares some tricks and tips applicable to both.

Life Beyond HTTP
There’s a whole world of interesting network protocols beyond HTTP says Anthony Eden. In this 30 minute talk, he provides examples of interacting with them using Ruby.

Let’s Talk Concurrency
José Valim of the Rails core team shares a digest of what he’s recently learned about concurrent programming and techniques.

The Farmhouse Podcast: Rubyist Talk from Los Angeles
Hard to describe but I’ve been enjoying this podcast from The Farmhouse. The latest episode features Shane Becker and Evan Phoenix discussing the Puma Ruby Web server. Steve Klabnik features on two earlier episodes.

Libraries and Code

Rake 10.0 Released: Yes, Version 10
Ruby’s make-like build utility takes a small step for Jim Weirich but a giant leap for version-kind by going from 0.9 to 10.0. Why? Jim explains.

A Rails Membership Subscription or SaaS Site with Stripe
A Rails 3.2 application with recurring billing using Stripe. Open source and ready to roll.

Rails 3.2.9 Release Candidate 1 Released
Don’t get overexcited. Bug fixes and tweaks.

IProcess 3.1.0: Ruby Tools for Subprocesses and IPC
Provides a number of abstractions on top of spawning subprocesses and interprocess communication. It has an easy-to-use API that supports synchronous and asynchronous method calls and custom serialization.

Espresso: A New Scalable Web Framework Aimed at Speed and Simplicity
I don’t think we’ve had a new Ruby framework for a while so.. enter Espresso 🙂 Has a few interesting ideas but without being too alien to existing Rails, Ramaze, or Sinatra fans.

Ruboto 0.9: The JRuby on Android Platform
Now supports Ruby classes directly subclassing Java classes.

A Simplified Version of Ruby’s Object System, Implemented in Ruby
A clever experiment by James Coglan. It’s intended to model inheritance and method lookup in as little code as possible, for ease of understanding by Rubyists.

Jobs

Sr. Rails Engineer at VMware Socialcast (San Francisco)
Socialcast is looking for a passionate, experienced Ruby and Rails Engineer to join our growing Engineering team! Continue your career in a start-up atmosphere focusing on fast experimentation with the latest technologies and frameworks (Rails 3 and Ruby 1.9).

Ruby on Rails Developer at Litmus (Remote, anywhere!)
Litmus, the e-mail testing and analytics company, offering a great salary, full health care benefits and 28 days paid vacation. We’re looking for great developers wherever you live in the world. Come and see what our team have to say about working here.

Rails Software Engineer at Sleepy Giant (Newport Beach, LA, Chicago)
Sleepy Giant is a game company based in Newport Beach. We are looking for Rails developers to join our talented team. You will work on high-profile, high-scale game services and franchise development projects, including green-field systems engineering.

Last but not least..

The British Ruby Conference: Giving 15% of Sales for Movember
The British Ruby Conference is in Manchester, England in March 2013 with lots of lovely speakers (and I’ll be there!) and for this month only will be giving 15% of ticket sales to the Movember cause. Come join in the fun.

Official (Private) RubyMotion Training Available
The folks behind RubyMotion, the Ruby development toolkit for iOS devices, are now offering official RubyMotion training to groups of 15 or more.

Configuring CloudFlare DNS for a Heroku App

CloudFlare is a popular, and accessible, CDN and website optimizer. If you’ve heard of Akamai then you know basically what CloudFlare does – they sit between your site and your users and accelerate your site’s content by edge-caching and other nifty on-the-fly techniques. CloudFlare also offers additional availability and security features to automatically handle DDoS and other real-world problems.

Heroku needs no introduction other than to say it’s the best place to deploy your applications.

So, how do you get the benefits of CloudFlare for your Heroku application? Until CloudFlare provides a Heroku add-on there’s a bit of manual configuration that needs to occur.

For the purpose of this post I’m assuming you already have a CloudFlare account and an existing Heroku app.

Initial setup

Since CloudFlare needs to be able to handle DDoS and other traffic-related events on your behalf, it must serve as your DNS. When you add a new website to CloudFlare it will scan your existing DNS records and duplicate them in the CloudFlare DNS.

Initial DNS configuration

While this is a great way to quickly bootstrap your DNS, it implements the DNS anti-pattern of using A-records to resolve to a dynamically determined IP address.

Under the covers Heroku uses multiple IP addresses. Choosing just one to bind to is a dangerous practice that can adversely affect your app’s availability. In short, you should never use A-records in your DNS on Heroku because those static IP addresses can change at any time and represent a single point of failure.

Avoid the use of A-records and root domains (ryandaigle.com is a root domain whereas www.ryandaigle.com is not) by redirecting all root domain ryandaigle.com requests to www.ryandaigle.com.

Root domain redirect

Setting up a URL redirect (or “forward” in many DNS providers’ parlance) on CloudFlare requires that you go into the “Page rules” for your site.

From your CloudFlare websites list click on the gears icon for your site and select “Page rules”.

Website settings

If you don’t see “Page rules” as an option your site may not be fully configured. Complete the CloudFlare setup first or go to the CloudFlare settings page and under “Cache Purge” you will see a link to “Page rules”.

Enter the root domain for your site and the www (or other) sub-domain to redirect to. Append a * wildcard pattern to the root domain and the $1 regex to the sub-domain so all requests made to the root domain are properly forwarded (e.g. ryandaigle.com/a/mypage will get forward to www.ryandaigle.com/a/mypage). You’ll need to turn “on” the forwarding toggle to see the sub-domain field.

Forwarding rule

Make sure you include the http:// part of the sub-domain URL. Click “Add rule” to save the forward.

Sub-domains

If CloudFlare wasn’t able to retrieve your existing DNS settings, or you have a new Heroku app, you’ll need to make sure you have the proper CNAME DNS entries.

Map the www sub-domain to your Heroku app URL (appname.herokuapp.com) using a CNAME record.

CNAME entry

Confirmation

To confirm your setup, first verify that your root domain redirects to the sub-domain. Use the curl utility to verify the redirect.


$ curl -I ryandaigle.com
HTTP/1.1 301 Moved Permanently
...
Location: http://www.ryandaigle.com/

You should see a 301 Moved Permanently response code and the proper sub-domain URL in the Location header.

As you may already know, troubleshooting DNS is notoriously difficult given the propagation lag. In my testing it took about an hour for new CloudFlare DNS settings to take effect (and this is after CloudFlare’s name servers are active for your site).

After confirming the redirect you should also confirm that a sub-domain request passes through the CloudFlare system. Do this with a curl against the www sub-domain.


$ curl -I www.ryandaigle.com
HTTP/1.1 200 OK
Server: cloudflare-nginx
...
Set-Cookie: __cfduid=askdjfalk8a98a9sd8fa9sda9jkar8; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.ryandaigle.com

You can identify a CloudFlare-handled request by two response headers: the Server being set to cloudflare-nginx and a __cfduid cookie. If you see these two headers in the response then CloudFlare is properly handling your request. For my domain it took several hours to see these headers appear, so sleep on it if you’re not seeing this after configuring the DNS.

Conclusion

Once these DNS changes have propagated you might think it would be safe to remove the A-record. However, in my testing, you still need to keep the A-record listed in your CloudFlare DNS config or your hostname won’t resolve. The forwarding rule still works as desired and bypasses the A-record IP address but there must be an A-record listed.

If you don’t have an A-record already, add one from @ (the root domain notation) to one of the following IPs: 75.101.163.44, 75.101.145.87, 174.129.212.2.

At this point all requests to your root domain will be forwarded to their www equivalent which properly resolves to one of Heroku’s dynamically determined IP addresses. This is the appropriate setup for Heroku, and is the most robust configuration for any cloud-based environment.

Now that your DNS is properly configured I’d suggest browsing the CloudFlare app store and your site’s CloudFlare settings for all the cool toys and switches you now have at your disposal. They also have a good blog post for new users.

Fork Your Application’s Data (Not Just Your Code) with Heroku Postgres

In the same way Git and Github revolutionized software development by letting you Fork your code with a single click, Heroku Postgres is changing the way you work with database by letting you Fork your data.

The ability to Fork your data is generally available as of today. This exciting technology which is simple, safe (placing no load on your primary database), and robust makes available some exciting new use cases:

  • Analytics reporting
  • Worry-free migrations
  • Trivial cloning of data to development/staging

Read more about our Fork announcement or get started using Fork today and then let us know about your exciting uses at dod-feedback@heroku.com

The Cloud and Amazon Web Services screencast, November PragPub Magazine

The Cloud and Amazon Web Services screencast, November PragPub Magazine now available

Ruby 2.0 preview 1

In this episode of The Ruby Show, Jason and Peter talk about Ruby 2.0 preview 1, Ruby Under a Microscope, Rails Best Practices, and more.