andhapp Random ramblings

Rails3

Rails3 pre has been out for a while and a beta version is due soon. A lot has changed in Rails3. The structure, the way the plugins(yes activerecord is sort of a plugin now) work. To cut to the chase, Rails3 is modularised and exposes much more of the framework to the developers. The first thing I have jumped into is the Rails Generators. A majority of the gems and plugins rely on the generators and this section has been totally revamped in Rails3. It basically extends Thor now, written by Yehuda Katz so you see the connection. It is quite extensive to start with but with time it gets easier. I have written generators for Haml Controller, and Clearance…so if you fancy you can have a look and see how it has been done. I was going to do an extensive post on the Rails3 generators but I guess there are lof of them out there already and are much better than what I can ever write.

Gemcutter

Well, if you work with ruby and rails and you do not know what Gemcutter is then its time for you to come out of the rock you have been living under. It is the awesome gem hosting service that has in time replaced rubyforge for good.

And, now I am an official contributor to such a incredible application. Yes, I added a feature in and it has been merged into the main production branch due for release very soon. And, I am now sitting along the likes of Jim Weirich in the contributors list. Awesome.

Virtues of a programmer

  • Laziness - The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful, and document what you wrote so you don’t have to answer so many questions about it. Hence, the first great virtue of a programmer. Also hence, this book. See also impatience and hubris.
  • Impatience - The anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to. Hence, the second great virtue of a programmer. See also laziness and hubris.
  • Hubris - Excessive pride, the sort of thing Zeus zaps you for. Also the quality that makes you write (and maintain) programs that other people won’t want to say bad things about. Hence, the third great virtue of a programmer. See also laziness and impatience.

* Taken from the book Programming Perl

Facebook, Facebooker gem and ssh-tunnel

Well, it was long hours of endless frustration and little fun, I tell you. That is how I spent most of my saturday trying to follow the instructions to create a ssh-tunnel so that I could test facebook application as I developed it. Putting an application up on facebook is a walk in the park. You create a new application, give it a callback url, where it can find what to display in your application and you are done. As far as your callback url is legitimate your application will work like a charm. If you are interested, please go ahead and check the request-response artchitecture.

I am using the facebooker gem which gives a you a lot of functionality out of the box and one thing it does is gives you rake tasks to start a ssh-tunnel. The purpose of ssh-tunnel is simple port-forwarding. So, any requests to a publicaly available domain at a certain port should be forwarded to the local server where I am doing facebook application development. The latest version of the gem sits on github and you can install it as a plugin, just do:

script/plugin install git://github.com/mmangino/facebooker.git

There are several tutorials that describe how you can set it up, just google it.

And I will go straight into the ssh-tunnel part of the problem so I assume that you have facebooker gem installed and you have made necessary changes to the facebooker.yml file by adding your public host name and ports where you want to achieve port forwarding. For example: any publicly available domain that you have ssh access to can be used as a port-forwarder. For the sake of this post let us say:

public_host :andhapp.com
remote_port: 4007
username :andhapp
localhost :localhost
local_port :3000

As per the above details, when I run the facebooker rake task to start the tunnel I will basically be doing this: Any requests to andhapp.com on port 4007 should be forwarded to my localhost on port 3000 (which is where your dev facebook app is running).

Once it is all set-up you can use facebooker’s nifty rake command to start the tunnel, like this:

rake facebooker:tunnel:start

This would prompt you for your password for sshing to your public host. To check the ssh-tunnel status, just do:

rake facebooker:tunnel:status

If this command comes back with “Seems, ok” you know the ssh-tunnel is up and fine. But when you access http://andhapp.com:4007 (or whatever domain you have used) it just gives you a browser error - “the connection could not be made”. It took me a long time to figure out what exactly the problem is. The ssh-tunnel is fine its the way ssh is configured. To fix the issue, just uncomment the line:

GatewayPorts no

in your ssh config file on your server, most probably found in: /etc/ssh/sshd_config and change it to:

GatewayPorts yes

Restart ssh, and restart the tunnel and it will start working. What the hell? Why do we need to do that for? Here’s an explanation.

BitBucket

I recently read this article comparing BitBucket and GitHub and did mention in in a previous post on Git. Apart from well defined differences like BitBucket is a social repository for Mercurial writting in Python whereas GitHub is obviously for Git written in Ruby with bits written in Erlang.

So, I decided to try BitBucket out and I must say although the UI is quite similar to GitHub but it is still not as intuitive and can be improved massively in terms of overall navigation and organisation. But, hold your thoughts, if you are going to write Mercurial off on the basis of BitBucket then atleast check this article out by Geoffrey Grosenbach before you do so.