Saturday, August 28, 2010

Rails: reset_session and Webrat Don't Play Nicely with One Another

All the Rails security guides say that you should call reset_session after the user logs in or logs out. This clears out the session and forces a new session ID to be created. It seems there have been a few Rails bugs related to reset_session over the years.

In my login action, I call reset_session and then put a nice message in flash. When I actually use the website, I can see (via Firefox) that I'm getting a new session ID, and I can see my flash message. However, when I write tests for those two things, the flash message gets lost, and I don't get a new session ID in my cookies. It's almost as if the new session is being ignored, and the old session is being used.

I submitted a bug to Webrat about this, but it turns out it's an issue in Rails. This issue is present in version 2.3.8. If this is affecting you, there's a workaround here. I implemented the workaround, and it worked like a charm :)

Friday, August 27, 2010

Ruby: Blooger


I needed some sample code for an interview, so I built a website called Blooger. It's a site (like Blogger) where people can go create a blog to blog about their booger stories. It even has functioning Atom feeds :)

Here's the source code. I used Cucumber, RSpec, Webrat, and factory_girl to do behavior driven development. I used Authlogic for authentication. I used BlueCloth for Markdown support in order to format the blog posts. The README in the source has more details.

Saturday, August 21, 2010

Books: Programming Scala

I just finished reading Programming Scala. In short, I really liked it.

The first few chapters are breathtakingly fast. Some of the middle chapters are kind of slow, but are still worthwhile. Scala is a fairly large language (unlike, say, Scheme or C), and the book is a fairly dense 400 pages. I found it helpful to read slowly and take notes.

As for Scala itself, I really like it! Scala is a nice mix of Java, C#, Erlang, Haskell, Ruby, and Smalltalk. You can treat it as a "better Java", or you can treat it as a more enterprise-friendly Haskell. Either way, it's exactly what I was looking for: a language with reasonable syntax, an ML type system, and a decent set of real world libraries. I know that the Haskell community is working hard in this direction as well. I think Scala stands a very good chance at being a work-friendly, programmer-friendly language.

I'm a little afraid that its type system may be too large and too complex for a lot of programmers. To be fair, I think that C++ is too large and complex for most programmers too. I'm also afraid of subsetting--i.e. the situation where every team picks a different subset of the language to use. This is very common in multiparadigmatic languages like C++. On the other hand, some multiparadigmatic languages like Python seem to avoid this problem.

There's a lot to learn in Scala--covariance, contravariance, parameterized types, abstract types, self-type declarations, lazy values, by-name parameters, DSL-friendly abbreviations, path dependent types, oh my! And there's more! I ended up with 50 pages worth of notes.

I'm pretty sold on Scala. Now, all I need is a startup to hire me to write it ;)

Saturday, August 14, 2010

Personal: Looking for Work

I'm looking for a new job. As much as I've enjoyed my time at my current company, I'd like to move on to something new.
  • I'd like to give Scala a shot, if possible. For the last year, I've been doing Ruby on Rails, and before that I was doing Python. I've been learning Scala in preparation of making the transition.
  • I'm only looking at companies in San Francisco or the East Bay.
  • I prefer behavior driven development and really clean code. I'm really bad at working on sloppy code bases with no tests and no documentation.
  • I prefer Linux.
  • I have a predilection toward startups.
Here's my resume. Thanks!