I’ve been playing around with various integrations and decided to knock up a simple Twitter bunkup where you can login to a very simple Sinatra app using Twitter and send a tweet to say so. It’s very very simple as I wanted to concentrate on the Twitter integration rather than the app functionality. So how do you do it? First thing you need is a Sinatra app. I use rvm to manage dependencies so I like to create a .rvmrc file that loads the appropriate gemset whenever I cd into the directory:
The above will create a twitterauth directory, create a twitterauth gemset, install the required gems (note the high security on the twitter gem as it can do all sorts of things with your twitter account if you let it) and create an rvm .rvmrc file in the directory that will do the equivalent of rvm use 1.9.3@twitterauth every time you cd into it. The first time you cd in you’ll see gubbins about running the script for the first time and you have to choose to do so. After that it’s seamless and the gemset is loaded without any interaction.
In this tutorial I’ll show you how to start with a completely blank SD card, a card reader and an internet connection and end up sending email from your Raspberry Pi (RPi) using Ruby and GMail. The instructions for burning the RPi image to disk are for OS X but there are a ton of tutorials for doing it on Windows. See the References section at the end of the tutorial for instructions on how to burn on Windows.
rake was working so where did that file come from? There are two possibilities, either RubyMine did something bad to my system as it doesn’t work, or I haven’t run rake since installing spork as it doesn’t work either apparently. Who knows? It’s ruby, get used to the mess.
In my last place, we employed a graduate software engineer and one day I was asked to review his code. So we sat down and had a look at an app he was working on. Can’t remember what it was now but I seem to remember it was written in Visual Basic, though ‘m not sure about that either now. Anyway, having a glance over the code, large chunks of it were commented out with a warning along the lines of “this code is dangerous, do not use!”. OK, fair enough, graduate and all that and we worked together to sort out problems. That’s a fairly common thing when you’re starting out in coding. You do things like that.
Then, years later, I came across Ruby and its “!” mechanism. Put simply, if you put ! after a method name, you’re saying “this method is dangerous, do not use”. It’s a coding convention which most people follow and what’s worse is, you’re not meant to write a “dangerous” method unless you’ve already written a “safe” version of the method.
Why on earth would you want to write “dangerous” code? Dangerous usually means the method changes a param, rather than returning a value computed from the param, so I presume dangerous equates to more “efficient”. Who’s kidding who here? Efficient for the compiler maybe but what about the maintenance programmer? Wondering where all those bugs come from and why every method ends in a !
What state has software engineering reached when languages positively encourage you to write “dangerous” code?
So I’ve recently upgraded to Snow Leopard, which blew away my Mysql installation as it destroys anything in /usr/local, which is where the installer puts it. I normally compile most apps and bung them in ~/apps, which means they are left alone by OS X upgraders but for simplicity’s sake I let the Mysql installer put it in /usr/local/mysql. So I upgraded to x86_64 Mysql which broke the installed gem. So I recompiled it and it complained ruby was the wrong architecture. So I recompiled ruby, rubygems and reinstalled some other gems and finally got mysql working again by uninstalling a bum mysql gem after I’d installed from source. At last I could run Gitorious on my local machine but alas no! Mongrel doesn’t work with ruby 1.9.1 it seems. Sigh.
I’m wondering just what Ruby can do for me. OK, I won a prize using it, not having used it much before, so that was a good sign but ever since, the more complex the application, the more I spend configuring, googling and compiling and the less I spend coding. For every line of Ruby code I write, there seem to be 10 lines of shell commands to enter, 10 web sites to google and 10 hours of working round ruby version incompatibilities. I had a stable Ruby setup until I went to Snow Leopard. Now I’m back to square one of seething mess.
Standing back from all this, one thing springs to mind. DLL Hell. I left those days behind years ago. Seems like they’re back.