Saturday, July 14, 2012

Finished Rails Tutorial, but I'm still hungry!

Power House below the San Francisco Cable Car Museum - courtesy Christian Mehlführer
After 3 months of part-time slogging I've made it to the end of Michael Hartl's excellent (and free!) Ruby on Rails Tutorial. I really appreciated Hartl's inclusion of the whole Rails workflow, from installation and config, through TDD (test-driven design) and BDD (behaviour-driven design) with RSpec, Capybara and Cucumber, source control with git on Github, and a taste of CSS and Ajax, to actual deployment on Heroku. In fact, you can see the results of all this work at https://furious-cloud-4562.herokuapp.com/.

Along the way I learned a lot, with some side trips into setting up a development environment and finally coming to grips with Vim. It was a bit like I imagine driving a San Francisco cable car - I got where I was going, over lots of hills and curves, in relative ease and comfort, by pulling a few levers (typing in code) at the right time and watching the results roll by. 

But I could tell there was something "under the street" pulling me along, like the power house under the San Francisco Cable Car Museum - lots of big machinery, moving fast, with cables and gears disappearing into dark, unexplained tunnels. I think the next step, now that I've had a ride around on the Rails car, is to step down into the motor room, with conductor David A. Black's book in hand, to get a better understanding of the Ruby engine that drives everything. 

I found the end-of-chapter exercises a bit daunting, especially without an answer key to check against once I'd make my best attempt at it. I found some answers, often for older versions of the tutorial, on StackOverflow and the now-unsupported Get Satisfaction support site for the Rails tutorial.

I really like the BDD testing approach, and I'd like to delve into that next, but I haven't found much online beyond the RSpec documentation (which appears to be generated by rspec tests), a new "gamified" RSpec tutorial at Code School that I haven't tried yet (opinions, anyone?), and a now outdated book from the usually excellent Pragmatic Programmers. Again, I am loathe to spend time and money on a book that was published more than 2 years ago, given the rapid velocity of code changes to the Rails ecosystem. 

Tuesday, June 26, 2012

Online Coding and CS courses

In a comparison of seven (eight, actually) of the current crop of online dev schools, Chris McConnell at DailyTeckk notes the topics available for study (Web dev, programming), languages used (mostly Python and JavaScript) and costs (free to monthly subscription):
Two more notable sites I've found:
Edit: Steampunk Nancy Wu notes a couple of other sites in her survey of the online learning landscape:
If you've come across any other high-quality online learning sites, that you've personally tried and want to recommend, leave a comment here!

Wednesday, May 30, 2012

Friday, May 25, 2012

Ruby one-liner: rename files

I wanted to strip a 20-character prefix, starting with the characters "IP_", from from a dozen XML files in a directory. Each file has a value of a different length following the prefix, e.g. "IP_stuff_foo.xml", "IP_stuff_bargain.xml", etc. I could probably do this by hand, or with a Windows batch file, but seeing as I'm learning Ruby (again), I thought I'd try to get it down as a Ruby one-liner, and here it is:

ruby -e 'Dir.glob("IP*.xml").each { |f| File.rename(f,f[24..-1]) }'
  • ruby -e calls Ruby to -"e"xecute the code in single quotes
  • Dir.glob("IP*").each finds all files in the current working directory that start with the string "IP". The glob() method returns an Array object, e.g. ["IP_foo.xml", "IP_bargain.xml", etc.], so the Array each() method returns "each" element in turn.
  • Each file name is passed in turn into the variable f in the block { ... }, where the File.rename() method does its magic.
  • File.rename takes two parameters, the name of the file to be renamed, and the new name for the file.
  • The new file name is a substring of the characters following the 20 character prefix. The substring is created by returning the remainder of the string after counting backwards, "-1", for "20" characters, f[20..-1].
  • Once File.rename() gets the substringed value, it renames the file.



Monday, May 21, 2012

tmux for Ruby on Rails

A couple of weeks ago I stumbled on tmux as a way to manage the proliferation of terminal windows when doing Ruby on Rails development.

My Rails 3.2 development environment is a Ubuntu guest OS running on a VirtualBox VM hosted on my Windows 7 desktop. Since I wanted to stay on my Windows desktop most of the time, rather than interact with Ubuntu through the somewhat laggy Virtualbox display, I would ssh into the Ubuntu guest using a Cygwin terminal (mintty). And being a good ol' Rails fanboy, I started using Vim and all its plugins as a really nice Rails/Ruby editor.

However: once I got a couple of Vim editors, a rails server, a rails console, a log file tail, and a Guard or RSpec session all running at once, plus the Ruby on Rails tutorial and Rails app open in browser windows, my Windows desktop started to look like Mah Jongg game in full swing. I was spending more time tabbing around looking for the right window than actually learning anything!

Tmux brings some order to that chaos. According to the tmux man page, "tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen." After some tweaking and fiddling, this is the layout I've settled on:


I've split a single "window" named "rails" into to three "panes": top-left I have Guard running Rspec tests, bottom-left I have the Rails server, and at right my main Vim editing session. On a second window named "logs" I have a tail on the Rails server log file.

The cool thing about this is that it all starts up automatically when I run a shell script that instructs tmux to set up the windows and start all of the processes I need for my Rails development session. Tmux will even maintain the session in case my terminal connection dies.

I relied on these excellent introductions to TMUX to get started:
Here's the shell script I cobbled together to create that session:



And my .tmux.conf file:



Thursday, May 17, 2012

Wikipedia on my iPad Sucks!


I love Wikipedia.

What's not to love about the universal reference, all 3,952,630 pages kept up-to-date by an 85,000-strong army of contributors, who do it all for love, that's available online, from anywhere, including my iPad, even offline, thanks to the All of Wiki app that lets me carry the whole 4.73 Gbytes of it around with me whereever I go, so that if I, as an ignoramus Canuck, riding to work on the bus without a handy WiFi connection, get the hankering to know just who played Zaphod Beeblebrox in the original BBC radio broadcast of the Hitchhiker's Guide to the Galaxy, well, heck, I can just pop open All of Wiki and discover it was the aptly-named Mark Wing-Davey, who also played Zaphod in the TV series... in fact, with the addition of perhaps a towel, I would be perfectly equipped to face the Vogons with my Wikipedia-enabled iPad.

Besides, I don't think Vogon ships are equipped with 802.11n WiFi, so that's perfect.

The iPad is pretty much how I envisioned the Hitchhiker's Guide when I first read Douglas Adam's opus many years ago. So if I love Wikipedia so much, why do I say it sucks? Here's what the desktop version looks like on my iPad:

I don't know about you, but i find it hard to read 6-point type on an iPad. Granted it's a now-ancient iPad Mark I, but i don't think the whiz-bang Retina display would make much difference, it's still tiny type.

Let's try the two finger splits and zoom in:


Terrific, the type's bigger now, but it didn't reflow to fit the screen. Okay, you say, switch to the mobile version:

Big improvement, now I see tiny type one block at a time, and it still doesn't reflow when I zoom in.

C'mon, Wiki guys 'n gals, this is the Age of Mobile, I know you've heard about responsive web design (it's right here). Let a thousand screens bloom! You've recorded all that's vital to human knowledge, surely you can make it comfortable to read on my iPad, and Nokia N8, as well as my desktop?

Keep up the great work, though, we do love ya.

Wednesday, May 16, 2012

Lather. Rant. Repent. Love it!

Eric Lloyd (where are you?) summed up the link between code cruft and developer turnover in his comment on the thread Is 4-5 years the “Midlife Crisis” for a programming career? - Programmers

"Lather. Rant. Repent."

How many organizations get this? How many can see past the sunk cost of ancient code and infrastructure to realize when it's time to update?

'via Blog this'