Monday, 27 August 2012

Rails 3.2 Could not find a JavaScript runtime execjs

Running a fresh copy of Linux Mint and Rails lets you generate a new project with no problems, but you might start to hit issues as soon as you start trying to generate some scaffolding. So for example, if you try
rails g scaffold User name:string email:string
You'll get something like this:
/home/x/.rvm/gems/ruby-1.9.3-p194@rails3.2/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51 in 'autodetect': Could not find a JavaScript runtime.
It will also tell you to visit to see a list of available runtimes. Don't be shy now, head over there and take a look. Or, if you just want to hack it, add the following to your Gemfile:
gem 'therubyracer'
Run your bundle update and you should be good to go.

Thursday, 23 August 2012

What playing in bands taught me about Startups

When I was in university, I thought my band was going to be the next big stadium rock band. We took our music seriously. We played. A lot. We gigged. A bit. We sucked. Big time. Even though, as far as we were concerned, we were destined for fame.

I wish I could point to a single event that brought me to my senses, but really it was just a gradual realisation that I wasn't as good as I thought I was and that, in fact, getting to be "Rolling Stones" famous, was partially luck. I remember once reading an interview with Mark Knopfler. Some fan-boy was asking him about a trip to South America or something saying how Mark probably taught the locals a thing or two about guitar playing. Knopfler replied something to the extent of "naa man, those guys down there can play their ernie balls off. They put me to shame. I'm just a schmuck who got lucky". Full kudos to the man. Humble and self-realised all in one.

Anyway, after a while I stopped being so pissed that my raw talent was going unnoticed, checked a little bit of my ego at the door and stopped trying to put a band together. I just started playing for fun. Now I tinker. I like to play music, and I'm reasonably good for an amateur, but I'm just happy that I can sit in my living room and noodle away in the corner without the cat shrieking or my family skulking off into another room because the sound is so horrid. Heck, the last band I was in sort of fizzled out. Our guitar player left because we weren't goth enough, and our drummer left because he wanted to play covers on cruise ships for money. Seriously, you can't make that stuff up.

Startups are the same. Lookit:
We are looking for someone who has a burning passion, someone who wants to create something unique & exciting. Must be committed! No time-wasters
Seriously, adverts for bands and adverts for startups are practically the same, except in one they idolise QOTSA and in the other they idolise QUORA.

Adverts for bands always want "the next Steve Via" or "the next Dave Grohl". You have to "have a rockstar vibe and image, be ungodly tallented on multiple instruments and be available for rehearsal every minute because we have gigs coming up". Bullshit. You're playing a shitty gig in a shitty dive in two month's time and it won't matter if your guitarist can shred on not because by the time your slot comes around, eveyone will have left the bar or be so blind drunk they won't notice. Couple that with the fact that pretty much every song you've written is just a I-IV-V progression and really you just need someone to play a few notes from the minor pentatonic scale over the bridge section as a solo and you might as well just grab he nearest person you know, give them an old epiphone and plug them in through an auto-arpegiator pedal. It will sound fine.

Adverts for startups always want "rockstar ninja coders who can work with ruby, php, python, java, clojure have a deep knowledge of javascript (sans framework) and be able to do big data with neo4j, have mad skills in linux admin and be able to design compelling front ends". Bullshit. If anyone actually has all those skills to a half reasonable level, they aren't going to wasting their time working for "equity", they'll get a real high-paying job at an established company. Or they'll freelance. Be honest, you need an mvp and the only reason you've put in every major buzzworthy language is because you don't, or can't code. You're only going to need 2 lines of jquery on one screen, and your app is pretty much just a mash-up of apis that connect to facebook and twitter in the hopes that it goes viral. Your data entry is simple crud, "rails g scaffold" will do just fine for pretty much every screen and you're just going to bung on Twitter Bootstrap with maybe a different colour navbar. Monkeys from college can code this up for you as long as they can type "gem install".

Don't be fooled by the play to your ego that always comes towards the end of the advert:
This position entails much more than just being a coder/lead guitarst; you will be an integral part of the company/band with input in major decisions/song writing and the direction of the company/band.
In other words, the startup has no idea what they are building or how they will make money. The band has no songs of any substance written. The startup hopes that you have some great ideas and enough social clout to get some buzz going. The band hopes you have a string of original tunes written, recorded and ready to present to your contact in A&R at Sony.

There are some, though, that want honesty, that aren't looking for some pie-in-the-sky bullshit. The last time I was looking for a few people to jam with now and then, I put out an ad that went:
Part-timer with no aspirations of making it big looking for other musicians who just want to jam now and then. We aren't going to be big, but we are going to have a good time.

I got more responses than the new girl on the dating site.

Imagine if startups started advertising like this.
3 guys with macbooks who like to faff about with ruby on rails and nodejs and put up lolcat clones looking for someone to tweak the api calls a bit.
For an excellent, though very long read on startups read Don't waste your time in crappy startup jobs Drop me a line if you want to code, or jam.

Tuesday, 21 August 2012

Triple boot Linux, Windows 7 and Windows 8 RTM

I wanted to have a triple boot computer - why? don't ask me why! Oh, ok, I'll tell you - I needed Windows 7 for some current work and didn't want to mess up the install. I wanted to install Windows 8 so I could play with the metro style app development that I've seen floating around and of course, I like my Linux system for my ruby web development.

So - here's the rough steps without a specific walk through of each one, except for reinstalling grub, which is really the crucial step to getting everything to hum and purr along nicely. The caveat is that this worked for me, on my system, it might not work on yours - so take precautions, backup, verify backup, store a backup off-site - you know the drill, I shouldn't need to tell you.:

1) Install Windows 7 Easy enough, follow the prompts and pop Windows 7 on your machine.

2) Install Linux Choose your flavour - I've got Mint up and running, but go for Ubuntu if you prefer. Actually, go for pretty much whatever you want. Ubuntu and Mint will give you a nice trouble-free install of Grub to dual boot your system. It should work out of the box.

3) Create a VHD in Windows 7 and use that space to install Windows 8. Check out Scott Hanselman's great blog posts on this because it takes you through in detail what you need to do. Pay attention, because it's subtle (How to guide to installing and booting windows 8 consumer preview off a VHD and Guide to booting windows 8 developer preview of a VHD)

4) Boot up into Windows 8. Crap your pants a little as you notice the Windows 8 boot loader has made your Linux install disappear.

5) Boot to Linux with a live CD and re-install Grub manually. This is fairly simple - once booted, bring up a terminal and do the following (obviously, you need to know your partition number that you've got your linux install on - mine's sda6 - I have sda1 and sda2 as system recovery and windows recovery, sda3 as my Windows install, sda4 is a logical partition, sda5 is swap, sda6 is my actual Linux mint):
sudo mount /dev/sda6 /mnt
sudo grub-install -root-directory=/mnt/ /dev/sda
Note that the second line has the number left off the "sda" on purpose. PAY ATTENTION!

6) Re-boot - you should have options for Linux and Windows 7 again. On my system, selecting Windows 7 takes me to the Windows 8 bootloader from whence I can choose either Windows 7 or Windows 8 for boot.

Now this isn't perfect, because I have 2 boot menus, but you know what? It will do for now.

Monday, 13 August 2012

Generate an absolute URL in padrino

Sometimes, you just need that absolute URL. Padrino gives you a great little helper to create your urls in th form of url_for. Unfortunately, Padrino's documentation seems to be written from the point of view of someone who is intimately familiar with Rails, which means the total noob trying to get into Padrino without any Rails experience can be left a little flummoxed. Anyway, it is important to realise that Padrino has Sinatra as its base and you can tap into all that goodness that Sinatra offers. Absolute urls are as simple as:
<%= uri url(:controller, :action, :param=>value) %>

Thursday, 9 August 2012

Ruby LoadError: cannot load such file

So, you've set yourself up a lovely new app using, for example, Sinatra, and you're really chaffing at the bit to write some lovely code. But you keep getting bit by this:
LoadError: cannot load such file -- sweetsweetcode
You double check your but it is pretty standard stuff:
require 'sweetsweetcode'
run Sinatra::Application
What can be wrong? Please tell me oh gods of Ruby. Is it Passenger? Is it Rack? Have I uncovered a great big bug in Ruby itself? Naaaa! Of course not you fool, it's just that you're on the very latest version of Ruby, probably 1.9.3 or something and the load path no longer includes the current path. So to fix it, just do this:
require './sweetsweetcode'
run Sinatra::Application
And you should be singing again.

Wednesday, 8 August 2012

Adding an item to Linux Mint Cinnamon Menu

Last time I took you through installing Sublime Text 2 on Linux Mint. The trouble with doing the install the manual way as I showed and not using sudo apt-get is that you don't get the neat integration into the operating system so you wont find Sublime Text in your Menu and if you search it wont be there yet. Right click on the "Menu" in the bottom left and choose "Edit Menu". You should have something that looks like this:
Excellent. On my install, Programming was not yet ticked, so I clicked the checkbox so that the Programming section would show up in my Applications menu. Then on the left hand side, you need to click Programming, or whichever other category you want to put Sublime Text into and then on the right, click the "New Item" and fill it in as follows:
If you followed along when I installed Sublime Text, you aliased subl to launch Sublime Text. Clicking where the icon is will let you choose the icon location. I used the 48x48 icon in the Sublime Text 2 directory. Finally click the "show" text box against the new entry and you should be good to go. Sublime Text 2 will now show up in your menu under the Programming category and also if you start typing Sublime Text 2 in the search box.

Monday, 6 August 2012

Padrino, Datamapper, Rake, Uninitialized Constant

So, perhaps you've set up a fancy application using padrino, datamapper and sqlite and you are going great guns until
padrino rake dm:migrate
=> Executing Rake dm:migrate ...

rake aborted!
uninitialized constant Text
Or something similar - the datatype is probably not too important. The solution is to edit your migration and put the datatype into this:
column :description, "TEXT"
There seems to be a bug with the use of datamapper and the migration. I'm not sure where the bug is, but this fixes it!

Friday, 3 August 2012

Installing Sublime Text 2 on Linux Mint

So, continuing on from installing RVM on Linux Mint and installing Ruby on Rails on Linux Mint, I want to give a brief rundown on installing Sublime Text 2 on Linux Mint, though in fact, this will work for pretty much any Linux version, so if you're running Ubuntu it will work as well. If you aren't using Sublime Text 2, I suggest you download it and give it a go - it's an awesome editor, especially for Rails and Python development, bringing a Textmate elegance to Linux. It's cross platform too, so if you are jumping between OSX, Linux and Windows, it makes the perfect companion giving you a consistent interface across the various OSs. Don't trust me? Well take a look at what others think about it So, there are two routes here - you can install using the traditional apt-get on Mint. You'll have to add a repository. That's not really my preferred method though. It takes too long to get releases through to the repository so I like to do a manual install. Don't worry, this isn't complex. First you'll need to download Sublime Text 2 - grab it with wget or just go to the website and download it.
tar -jxvf Sublime\ Text\ 2.0.1.tar.bz2
Your filename might be different if you've got the 64bit version, or if the Sublime text version has incremented. Now you've got a Sublime Text 2 directory with everything you need in it. Next, I like to move it into /opt but feel free to put it anywhere that you normally install additional programs; maybe somewhere in your home directory. Anyway I do:
sudo mv Sublime\ Text\ 2 /opt
Last, but not least, I create a symlink
sudo ln -s /opt/Sublime\ Text\ 2/sublime_text /usr/bin/subl
You should already have /usr/bin in your path so now you can just run
from your terminal to get sublime text to startup. Finally, you should look at Michael Hartl's tutorial on setting up the various packages and plugins to ease Rails development with Sublime Text 2

Thursday, 2 August 2012

Installing Rails on Linux Mint 13 with RVM and gemsets

Last time I did a quick RVM install guide for Linux Mint. This time I'm going to finish up by installing rails so we can rock some new development work. Nothing like a clean and humming system I tell you. Let's begin by making sure we have git - we are going to be using it anyway. Fire up your terminal (Ctrl-Alt-T) and type
sudo apt-get install git
Great - version control level unlocked. We should have rubygems installed already (if you followed along with the RVM install then this is all taken care of). Now, to make sure RVM functions well, see this Or, if you prefer, just move the commands from .bash_login to .bash_profile. As I understand it, and I'm no Linux guru, .bash_login doesn't run if .bash_profile is present. I'm going to create a gemset to install rails 3, just for fun...and just in case I want to go back and work on some legacy apps.
rvm gemset create rails3.2
And set it so it is the default gemset with ruby 1.9.3
rvm use 1.9.3@rails3.2 --default
Note, your ruby might be different - run
rvm list
to find which ruby you have installed and which is current and which is default. If you've started fresh with Mint like I did, then you should be good to go with my command above. We need a few dependencies - if you didn't install these when you put RVM together then do them now
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev \
curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 \
libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison  \
Now, install rails with
gem install rails