IBAN Validation and Ruby 1.9

In one of our projects 9flats.com we’re using a short IBAN and SWIFT Validation rule to be sure the user entered valid bank account information.
To know how to validate an IBAN account number, just have a look at this article on wikipedia. Therefore you have to do a few steps to be sure get the right format of an IBAN number:

Validating the IBAN
The basis of the IBAN validation is to convert the IBAN into a number and to perform a basic Mod-97 calculation (as described in ISO 7064) on it. If the IBAN is valid, then the remainder equals 1. Rule process of IBAN validation is:

  • Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid.
  • Move the four initial characters to the end of the string.
  • Replace each letter in the string with two digits, thereby expanding the string, where A=10, B=11, …, Z=35.
  • Interpret the string as a decimal integer and compute the remainder of that number on division by 97.

If the remainder is 1, the checks digits test is passed and the IBAN may be valid.

I found a short (and also funny) blogpost about a validation script in ruby. Unfortunely the expression

iban = value.gsub(/[A-Z]/) { | p | p[0]-55 }

does’n work anymore, because Ruby 1.9 doesn’t return the integer ordinal of a one-character string using p[0]. Instead of that just use the .ord method on a string. So our Ruby 1.9 compatible code will looks like this:

iban = value.gsub(/[A-Z]/) { | p | p.ord-55 }

If you’re using two or more environments (e.g.: Ruby 1.8 and Ruby 1.9) on your production or development machine (I know thats not the way to go, but it could happen for a little time) just ask if Ruby respond to the .ord method.

iban = value.gsub(/[A-Z]/) { |p| (p.respond_to?(:ord) ? p.ord : p[0]) - 55 }

The final code from the blogpost mentioned before will be looks like this:

Small things can be very helpful!

DevHouse Friday – 25.03.2011 hosted by adcloud

Es ist wieder einmal Zeit für ein lockeres Come-Together von Web-Entwicklern und Tekki’s (endlich normale Leute). Mit einem Drink und zwei-drei kurzen Talks leuten wir das Wochenende ein und vergessen den Coding-Stress.

Vielen Dank an adcloud, welche den Event in Ihrer neuen Location im hippen Ehrenfeld ausrichten.

WANN: 25.03.2011 ab: 19:00 Uhr

WO: adcloud GmbH, Venloerstr. 25-27, 50672 Köln

WAS: Bring your brain and a beer

MORE: http://devhousefriday.org/ AND @devhousefriday

Das adcloud-Team ist übrigens noch auf der Suche nach Talenten (übrigens wir auch), was ich jedem empfehlen kann der am Puls der Zeit arbeiten möchte.

Entwickler aller Sprachen vereinigt euch!

Railscamp Poland – What is it about?

2008 the 2008th Railslove Crew Bumi, Tim and me visited their first Railscamp in Downe, Kent, UK. Because it was so awesome, here a short retrospective movie:

RailsCamp DOWNE, KENT, UK, AUG 2008 from Michael Bumann on Vimeo.

What is the Railscamp about? As you can see on railscamps.org its just about “[...] a posse of like-minded ruby hackers on a country retreat with zero internet for a weekend of fun. You’ll laugh, hack, learn, cry (well, you probably won’t cry… but you know… it felt poetic) and most likely play a crap-load of Guitar Hero.”

After a few more railscamps in UK and Germany the time for the first Railscamp in Poland is coming!

As (one of a) polish railslover, living in germany for years now, it was a dream to put on a railscamp in Poland. I mentioned this idea a few years ago on my tumbler blog. The idea behind that was and is exactly the same as 2008 in Kent: no internet, just hacking, having fun… After 2 years this dream is happening now. Together with applicake (Krakow), Jarorcon (Wroclaw), SalesKing (Cologne) and Railslove (Cologne) of course we’re put on the first Railscamp in Poland. Hard facts:

When: April 8th – 11th, 2011
Where: Wisła, Poland
Register/Friends/More Info: http://railscamp.pl/

The only thing what you need for an Railscamp is a lot of awesomeness, love and a lots of desire to hack on everything with everybody. Just bring your Laptop, Battery, a few socks and underpants and be sure you have Urban Terror installed on your machine. To not forget something important use dontforgetthewurst.com (AKA shatner.it).

Fill out the application until Thursday and it will be AWESOME to see you in Wisła!

Again: many thanks to: Ela, Bartek, Michal, Thomas, Oliver (Mixxt), Pat, Georg for helping to get this thing up and running! I owe you one guys!

Oh… yeah… Shatner is back! Btw.: Who’s bringing some Shatner-Music? ;-)

Cheers,
Janek ;-)

P.S.: And again: many thanks to:

ApplicakeJarorconRailsloveSalesKing

Dä Kölsch Zähler launched!

Ladies and Gentleman – Railslove and Payango proudly introduce you to “Dä Kölsch Zähler”. What is it about? In the next few days, Cologne (Germany) is going to get crazy. Carnival is coming and on Thursday almost every citizen in the city will be celebrating the “fifth season” here. Almost everything is closed: shops, offices, etc. And instead people will be drinking “Kölsch”. How much Kölsch will be drunk? Nobody knows. So, we decided to count it, and so the idea of “Dä Kölsch Zähler” was born. Tech-Specs: Kölsch Zähler is based on JQueryMobile, Ruby on Rails and Pusherapp. The amount of beer per Table is directly pushed to the other Mobilephones connected.

To be honest: we really have better and more important stuff to do! But this is a kind of “app in a day” project where hacking brings people together. We love building web applications!

Follow @koelschzaehler on twitter, become a fan on Facebook and visit “Dä Kölsch Zähler” while drinking Kölsch on Carnival in Cologne!

Prost!

Dä Kölsch Zähler

Dä Kölsch Zähler

Introducing simple Facebook Share gem

I really love how JavaScript can help you integrate social media into your application. But using the same code over, and over again is just annoying. Therefore, when I was working on inserting a Facebook share button here and there into our app, I thought, why do I have to repeat everything over and over? So, after a day of hacking, I came up with a simple gem facebook_share. This gem will insert any JavaScript needed for Facebook share buttons to work.

Facebook Share demo

How does it work?

Well, that’s rather simple. After the gem is installed (gem install facebook_share), add this snippet to your ApplicationHelper, and you’re almost ready to go.

Then create file config/initializers/facebook_share.rb with the content below (later versions will automate this process, too). Remember that every parameter here is optional, also that you can include more parameters.

After you type your Facebook application ID, you’re ready to go!

Is it that easy?

Yes, it’s that easy. If you want to share current page, all you have to do is:

But how do I customize it?

What if you have more items I want to share? Or the default selector doesn’t work for your application. Maybe you want to use Dojo? Everything is customizable. For example, you can customize your default settings with facebook_share.rb initializer, and then override these settings while calling helper methods. I will show you couple of examples and showcase most of public methods in the gem.

If you edited your config initializer, at most of the times you won’t need to pass any parameters to the helper functions, but for the sake of the examples, let’s say you’re running both Dojo and jQuery in your project, you have several Facebook applications you want to use, etc.

Example 1: Different selector


will produce:

Example 2: But I already have my JS part!

Probably you already have your Facebook app initialized in your layout and put the #fb-root div tag in there.


will produce:

You can easily switch which JavaScript snippets you want to use.

Example 3: Can I initialize any Facebook application?

Yes, you can. Albeit this gem being mostly for sharing links on Facebook, it can also be used to ease initialization of a Facebook app. For example, it you feed your facebook_share initializer like so:

You can simply do:

in your application layout to get:

Notice how locale‘s value of pl was transformed into pl_PL to meet Facebook expectations, and how only relevant values are included in the Facebook initialization script. Watch out for wrong locales, though, and do not use :locale => "en", as it will produce en_EN, and Facebook will not recognize this code as a proper language.

Example 4: I want my share link to show a different title!

Sometimes you might want to put a more relevant title about what you want people to share on Facebook. Not a problem, every method accepts the same set of parameters (which, by default are configured in facebook_share.rb initializer), and within these parameters you can define any FB.ui parameters, and they will be passed on to that function.

Example 5: But I don’t use jQuery/Dojo!

Again, not a problem, if you have configured your facebook_share initializer, that’s how you can do it:

That’s all, folks

I wrote this gem to help us all with the tedious task of copy/pasting the same Facebook JS code over and over again. I hope some people will find it useful.

In the meantime, install it, play with it, grab source code on github, fork it and code it up!

← Previous PageNext Page →