Load remote Rails links and forms in Bootstrap modals

As a heavy user of Bootstrap modals and Rails, I often want to use remote links or forms in a modal and load the result into the same modal. After doing this in several projects I worked on, I now copy and paste the helper directly into any new project I start that will use modals:

$(document).on 'ajax:success', '.modal [data-remote="true"]', (_, data) ->
      scrollTop: 0
      , 300

The trick is to specify only [data-remote="true"], not a[data-remote="true"] or form[data-remote="true"] so it works with remote links and forms. As you see, I also added a animation that scrolls to modal to the top after inserting the new content.

This helper works with Bootstrap 2.x and 3.x.

Read on

Get query parameter from the current URL with Javascript

When working with Javascript, you sometimes want to fetch the value of a query parameter from the current URL. I found multiple jQuery plugins to do this (in the horrible tradition of writing jQuery plugins for the most miniscule and simplest of tasks) but I ended up writing it myself in seven lines of Coffeescript (and I'm sure it could be compressed to one or two).

Update: as pointed out in the comments, my method has the flaw that it doesn't escape the query parameter it looks for, so it certain circumstances it might match the wrong parameter. If that concerns you, I would recommend to use this alternative method.

Check it out:

getQueryParam = (param) ->
  regex = new RegExp("[?&]#{encodeURIComponent(param)}=([^&]*)")
  match = regex.exec(
  if match?
Read on

How to drop your Postgres database with Rails 4

Update September 28 2016: There is now a gem that you can include in your app to use the technique detailed below.

When you use Postgres as your database with Rails and try to drop your database using rake db:drop, you might run into this annoying error:

PG::ObjectInUse: ERROR:  database "myapp_development" is being accessed by other users
DETAIL:  There is 1 other session using the database.
: DROP DATABASE IF EXISTS "myapp_development"
Read on

How to access your Google Drive files with Ruby

I use Google Drive excessively for documents and spreadsheets, and recently I created a IFTT recipe to store all attachments I receive to my Google Mail email address on Google Drive. No more downloading from Gmail, looking for the downloaded file, opening Google Drive, uploading etc., everything is right there in its own folder. (funnily enough, Gmail added the possibility to open documents right in Google Drive shortly thereafter).

Now, a couple of days ago I had to access some files on my Google Drive from a Rails app, and after some trial and error I found a easy way to do so, which I want to detail in this post.

Read on

How to set up automatic retweeting using a Google Apps Script, Yahoo Pipes, and TwitterFeed

Update (June 2015): several people have pointed out in the comments that there seems to be a authorization problem somewhere in the Google Apps script. Unfortunately I don't have time to dig in and look for the issue. If you find the problem, please let me know so I can update this post!

When Twitter released their API v1.1 in September 2012, they removed the possibility to create RSS feeds from timelines, lists or search results, and thus rendered many retweeting services and manually set up workflows disfunctional. One can rant all about Twitter moving away from their roots of providing an open communication ecosystem and how those restrictions clearly serve the main purpose of getting people to to show them ads, but here are the steps you need to take to get your retweeting back on track.

It has become a bit more complicated but no rocket surgery, as you will see.

Read on

The joy of Ruby and small incremental improvements

Yesterday I added a small new feature to the Tries gem I authored a while ago and was once again reminded what a wonderful language Ruby is and how deeply satisfying it is to be able to work on one's own projects, yet opensource as much as possible to see others benefit from it as well.

The feature isn't anything world-changing, but I needed it right then, so I took 2 hours and implemented it. A feature born out of a real need from a real user of the Tries library so to say.

Read on

Making PHP development bearable for Ruby developers using Coffeescript, Sass, and Haml

Preface: I don't want to bash PHP too much here, it is what it is, but I think it is clear that the Ruby community has put much more work into developing great tools to use while programming over the years, so any Ruby developer getting into PHP development should try and take some of those nice tools with her!

This week I had to start doing some PHP development, for the first time in about a year. Being a Ruby developer, I dreaded this moment, mostly because I am not so well-versed in PHP to avoid those little annoyances and inconsistencies that the language has accumulated over the years (or rather decades).

Read on

Bootstrap Navbar Helpers for Rails and Middleman

I'm in love with the Middleman static website generator and, after discovering it and falling in love with it, I immediately set out to rewrite all static websites I have up and running with Middleman. Since I'm also a heavy user of Bootstrap I ended up writing the HTML (or rather HAML) for the Bootstrap navbar many times as well. What's a Ruby developer to do? Gemify it!

Read on

GemConfig - A nifty way to make your gem configurable

This release is another case of "Jeez, this is the third time I'm doing X... let's see if there's a gem for that... nopes? Let's get started!" What follows immediately after that is, of course, putting the idea on my "idea list" (a Trello board) and letting it ripe there for a few months. But eventually I came around to it and present you with: GemConfig - A nifty way to make your gem configurable

Read on

CarFinder - Find your closest carsharing car

I am a big fan of the carsharing concept and I have been using the two largest providers DriveNow and car2go regularly here in Berlin since I discovered them a few months ago.

One thing I don't like about them is their websites. While the iOs and Android apps work quite well for finding a car, the websites were obviously designed not only for already registered users who want to quickly find a car, but also for prospective customers, press, investors etc. They contain a lot of clutter and the DriveNow website does not even make an attempt to determine your current location, so you have to zoom and swipe the map manually every time. Especially irritating since you want to reload the map repeatedly sometimes when on the hunt for the closest car.

After getting annoyed with their websites once too often I decided to do something about it.

Read on