My pet project: Todobadour

Todobadour

Todobadour has been my pet project for quite
some time now. I keep using it to try stuff, or whenever I need a rails app to
experiment with, like checking out rails4 or play with websockets and so on.
I actually started it quite a while back, but yesterday I decided maybe it is
actually useful to somebody else so I decided to push it up to heroku, clean it
up and make it ready to be used. So here it is! It a basic todolist, which can
be shared and is synced real-time, which is actually quite useful I guess, and in the end its all about learning something isn’t it?

Enjoy, drop a comment if you like.

JSHint and Vim

Using JSHint from Vim

Even though I am not a huge fan of JSHint it is
a useful tool here and there, especially to enforce some guidelines in your
code to keep a consistent style. Personally I think style matters, even though I
might not care about certain ones, at least I should be consistent all the way
across. So this is where JSHint comes in and lets you define a certain set of
rules to stay true to, and also eliminate some potential bugs and smells.

Running it is simple, just install via npm globally

$ npm install jshint -g

And run passing the config and the file to hint

$ jshint --config jshint.json myfile.js

Since I personally prefer to run as much as possible from Vim directly I created
a short function to do it for me.

https://gist.github.com/4326296.js

Enjoy.

Foreman and SOA services

For the longest time I was fighting the problem of having the problem that ease
of development setup and composing my apps of different services seemed to fight
each other, but recently I discovered not only one but actually 2 solutions,
Foreman with
Subcontractor as well as
Vagrant.

First a little background: Imagine a very basic app, which relies on another
service to provide some functionality, my always happy to jump in example would
be a rails app which relies on websockets via faye. Of course to develop
locally, which I always prefer, I need to run both on my machine or else the app
will not be fully functional. So far I’ve been always starting the faye server
and the rails app separately, and of course forgetting to start the push server
from time to time and wonder about failing integration tests. So much for the
setting now the solution(s).

First vagrant: It provides a virtualized environment to run the apps, and relies
on Virtualbox to do so. It’s pretty simple to setup a machine which has both
services running at boot which solves the problem. The issue I have with that
is that I am not sure if I am ready to take the performance hit to run
everything virtualized. Also developing in either the VM, and migrating my
vimrc between every project is not really feasible, and mounting is slow.

Foreman to the rescue, foreman allows you to package the whole setup of what
needs to be running to make your app work in one nice file, the Procfile. The
problem has been for me that running a second rack app inside foreman is not
really possible, but this is what subcontractor is for, it lets you
specify which separate ruby apps need to be running with which environment

Procfile.development

push: subcontract --chdir $PUSH_PATH --signal INT 
      -- env BUNDLE_GEMFILE=$PUSH_PATH/Gemfile bundle exec 
      rackup config.ru -s thin -E $PUSH_RACK_ENV -p $PUSH_PORT

This means that all you need to do is specifying all service dependencies in a
Procfile and that run

foreman start -f Procfile.development

This allows even complex service setups to be run as needed.

Enjoy!

ActiveRecordTranslatable, rails plugin to manage translations for ActiveRecord Models

Let’s face it translations are always a pain, be it managing po files for PHP
projects, or YAML files in Rails… Especially if the models in your
database contain some attributes being translated in different languages it
becomes hard to keep track of the translations, as well as managing the database
holding them.

Luckily Rails helps with that by providing I18n translations
across the board, and even supporting flexible backends for the translation
engine. Still if there are multiple attributes on models which
have to be provided in multiple languages, being different by model, I18n in its
basic form fails in my opinion. But the basics are already in place:

There also is the globalize gem, but
it didn’t quite fit what I needed, mainly since it stores the translations per
model, which makes it hard to provide a single interface to manage them. So I decided to roll my own and here it is,
ActiveRecordTranslatable.
The main goal was to integrate in the I18n backend itself so all available
translations can easily be found and contrasted to create an interface a group
managing translations can work in. For a basic usage just checkout the
Readme, or install
via rubygems

$ gem install activerecord_translatable

As always any remarks are highly welcome.

Enjoy

Using Rails ActiveResource via OAuth2

Exposing Resources via a REST interface can be a nice way to split-off certain
parts of a larger Rails application. To consume those,
ActiveResource has been a nice way to go
for quite some time now, and still is in my opinion even thought with Rails 4 it
will move to its own gem and be no longer tied to Rails Core (good or bad?).

One hurdle left is that in some cases resources are, or
should be protected. In this case working with OAuth2 for example is quite easy
the only thing needed is setting a header.

https://gist.github.com/3820532.js

The token obtained for example via Omniauth and then set in the Controller. So
thats it now using the Resource works just as using an ActiveRecord Model.

Scrum Master roles: Some scrum coaches rank among the nicest and most thoughtful people that I ever met. However, the general concept is very suspicious. A scrum master is not supposed to lead the team, code, or take responsibility for deliverables. What do they do? Massage? Get a real job. We use tech leads, who can understand the code that flies around a distributed team, and take responsibility for deliverables. I shed more light on this back in Novemeber with a popular post – Tech Leads will Rule the World.

Seven Things I Hate About Agile

Fixing the restart for faye upstart foreman and thin

In a little test project of min I manage rails deployment by using a combination
of capistrano, upstart and foreman. This
means as soon as I run


$ cap deploy

foreman is exporting the current Procfile to upstart scripts and copies those
to the correct locations for deployment on my ubuntu server, to restart the app
after the deployment capistrano now runs


$ service APPNAME restart

This works perfectly fine as long as all services restart nicely, but I ran into
a problem while setting up faye to allow push in the
app. Now since there is a connection between thin (my appserver) and faye, thin
will not shutdown gracefully as soon as upstart tells it to, which in turn means
faye will not shut down as well… ok so my app server will take a lot of time
to restart which is not that nice. To get rid of this problem I created a small
rake task to shut down the thin servers before the restart phase, this fixes the
“deadlock” (not really a deadlock I know but oh well). So here it is

https://gist.github.com/3434628.js

Basecamp Next Shortcut Chrome Web App

Basecamp Next Shortcut Chrome Web App

Since I couldn’t find the correct shortcut app on the chrome web app store I decided it would be the perfect time to write one myself. All it does is that it offers you to set the ID for your basecamp account and from then on will redirect you on click to it.

Your ID is found when you login to your Basecamp Account

Basecamp Account ID

Maybe anybody else needs that, so check out the Git or install via the Chrome Web Store

By the way the web app store is quite a nice experience after you get through the hurdles of getting to know the system.

Enjoy