Monthly Archives: December 2012

In memory session store for Rails 3

For the past two days I’ve been playing with the idea of having an in memory session store in a Rails application. Cookies 4KB limit soon became an issue, and I didn’t wan’t to use Redis, Memcached or even database for this. In production, those services have their place for sure, but for development it seems to me that it is silly to ask every developer on the team to have them installed and running to be able to run the application. Development environment is by its nature far from production, even when intentionally similar (e.g same OS), so it makes sense to use as little dependencies as possible.

So, I’ve been searching for in memory session store. At first, there were some references to memory_store, but unfortunately those were all Rails 2 related. There were even some attempts on re-implementing  it in Rails 3, but that of course failed.

Finally, this idea of implementing it for Rails 3 led me to reading Session related code in Rails. And bingo, there it was! Session store in Rails 3 has a couple of implementations, one of them being the CacheStore. And, since there is the in memory cache store in Rails, solution was pretty much straight forward. You can read up on cache store options in Rails here.

In the project, the following changes were needed:

# /config/initializers/session_store.rb
CrazyApp::Application.config.session_store :cache_store

# /config/environments/development.rb
config.cache_store = :memory_store

This will in effect put all your session data in rails process memory. After you kill rails, it all goes away. Ideal for development 🙂

In case you might need the data to persist, you can use file store which will, by default, save the session data in /tmp so you can inspect it. The file store is actually the default cache method.

There is one issue with this setup. You can’t have separate store for session and cache data. In that case, a new session store implementation would be needed, but let’s cross that bridge when the time comes.

Tagged , , ,

Full-fed or a Developer?

A week ago I had the pleasure of speaking to/with Computer Science students at University of Pula. The working title was “Full-fed or a Developer?” and the idea was to present a real life view on what it is to be a developer. Although this was formally a lecture, me and my colleagues (5 of us) imagined this to be more of an “involved theatrical show”, but it seems the students were too much into their “sit and listen” mode to be able to break the habits. Or we were boring. Take your pick 🙂

From gaining weight, through loosing eye sight and suffering socially, all the way to the preferred language and the rest of the developers tool-belt, I believe they got at least a glimpse of the “glorious” life to be 🙂 Well, it was is not all that black, and in the end the conclusion was that we do it because we like it, so all the difficulties actually don’t weight in too much.

From all this, what actually stick with me was a few questions from a student.

First question was: How to practice our skills?

Among a number of answers, a few were common:

  • get on Github and read code
  • listen to the community / podcasts of the platform / language of their choice
  • get out and write something, post it to Github, let people comment
  • Stackoverflow
  • write a blog about their experiences
  • join some open source project and offer help (documenting if nothing else)

You might notice that we didn’t offer one very important thing, and that was actually the second question: How to decide which direction to take in practice? How do I choose a thing to do? And of course, she was right on the spot.

So, the best we could offer was to listen to FLOSS Weekly. It offers the chance for beginner to listen to people that are actually behind so many great projects, and then decide which appeals to them the most. Whether they choose by the author of the project or e.g. by technology used or whichever thing points them in that direction, I feel it is a great way of choosing. Somehow it seems to me that it is a matter of heart, and that can never fail.

Very good questions, that didn’t spring to mind until she asked them. We talked about importance of practice, of reading other peoples code, of communication in teams, tolerance and what not but skipped that very important part, how to learn all of that. Actually, I found these questions to be very important for life (and craft), and the attitude correct and fair. Hope it will bring good things to her, and maybe she’ll be both full fed and a happy developer 🙂

Tagged ,

Http clone with LDAP authentication in Gitlab

I’m beginning to change the title of the blog to Gitlab something 🙂 But, it is the current focus at my day job, so it can’t be helped. Anyway, LDAP Gitlab web UI is pretty easy to setup and use. And it works beautifully. Devise and omniauth are driving it and that is pretty much it. However, if you like to have HTTP access repositories, and use LDAP to authenticate users, it wouldn’t work. The reason is that UI access goes through Devise, but repo access actually doesn’t. The grack_auth.rb is the key to the repo access process.

The main idea is to use plain ruby Net LDAP gem to authenticate the user directly against LDAP, while using Gitlab provided LDAP settings. I couldn’t find a way to hook this into Devise flow, hence this approach. If anybody knows how to manually authenticate using Devise, please let me know?! I suppose in some future versions Gitlab will solve this but for versions <= 3.1.0, this is usable and actually works in production environment at my day job.

There are actually two versions of the fix. Latest version, that applies to latest master, assumes username for the User is filled in when user is added after first time login (or updated later). Stable (3.1.0 or less) fix works a bit differently, it first tries to authenticate user with LDAP and uses the provided user email to continue. More details can be found in the provided gists:

* latest / master version:
* stable (<=3.1.0) version:

Feel free to apply at your environment and let me know if it works.

Update: found another approach @ It is not a pull request but maybe you’ll like this approach better.

Tagged ,