Alessio Caiazza

Articles tagged 'ruby'

Book review:"Sinatra: Up and Running"

Italian version below.

The first time I leafed through this book I wondered if 20 bucks was too much for a book of just over 100 pages.

When I started reading it was clear that this book was worth every single cent.

Clear concepts and well written, too bad for some mistakes in the code examples. Not even a word is wasted explaining how to develop in ruby; surely it is a book for experienced developers.

If you are looking for a step by step guide about web development with sinatra then this is not the book you are looking for. There are no advices on how to organize a project nor any best practice.

Who is this book for?

It’s a book for experienced developers who want to sharpen their knowledge about how sinatra works and not settle for high-level API. You’ll learn how to develop and use modular applications, building the theoretical bases for applications reuse; you’ll learn how RACK works and how to integrate several web applications developed with different frameworks (Rails, Sinatra and also simple RACK based applications).

Not even a sentence is redundant in this excellent manual, surely it is a reference book to keep on hand.

O'Reilly Shop

Italian version

La prima volta che ho sfogliato questo libro mi sono chiesto se 20$ non fossero troppi per un libretto di poco più di 100 pagine.

Dopo aver iniziato a leggerlo è stato subito chiaro che il libro valeva ogni singolo centesimo.

Concetti chiari e ben scritti, peccato solo per qualche errore negli esempi di codice. Non si spreca neanche una parola per i concetti di ruby; è decisamente un libro per programmatori esperti.

Se state cercando una guida passo passo per lo sviluppo di applicazioni web con sinatra, lasciate perdere, questo non è il libro che fa per voi. Non ci sono consigli su come organizzare un progetto, né alcuna best practice.

Allora per chi è questo libro?

Per sviluppatori esperti che vogliono approfondire il funzionamento di sinatra e che non si accontentano delle API di alto livello. Vengono trattate le applicazioni modulari, gettando le basi teoriche per il riuso delle applicazioni; viene spiegato molto bene come funziona RACK e come integrare web-app differenti (Rails, Sinatra ma anche semplici applicazioni fatte secondo le API di RACK).

Neanche una frase è superflua in questo ottimo manuale, sicuramente si tratta di un testo di riferimento da tenere a portata di mano.

O'Reilly Shop

(l0g.in 4KFN00)

OSX Lion, ruby and mysql2 - [FATAL] failed to allocate memory

I’ve spent a day figuring out how to solve the “[FATAL] failed to allocate memory” with mysql2 gems on Lion.

This solution should work if you installed mysql with Homebrew.

First of all, remove mysql-connector-c and mysql2 gem

$ brew uninstall mysql-connector-c
$ gem uninstall mysql2

Find the mysql version

$ ls /usr/local/Cellar/mysql                
5.5.19

Now recompile mysql2 against brewed mysql server (replace 5.5.19 with your version (twice))

$ gem install mysql2 -- \
  --with-mysql-include=/usr/local/Cellar/mysql/5.5.19/include \
  --with-mysql-lib=/usr/local/Cellar/mysql/5.5.19/lib

Enjoy yourself

(l0g.in 4GhP00)

Bundler with Mercurial support

Git seems to be the de-facto tool for ruby development. Lots of gems are hosted on github, and bundler may help you to work with cutting-edge release fetched from git repositories.

WOW! That’s amazing! But what if you didn’t like to use git as scm?

I’ve nothing against git, but I prefer mercurial so I spent some time to add mercurial capabilities to bundler, the best way to manage your application’s dependencies.

How does it work?

With bundler you can start gem development with a simple command (more info at Railscast episode 201)

bundle gem gem_name

This command will create for you a gem skeleton with some premade rake tasks in a shiny git repository. Wouldn’t be wonderful if we can use mercurial instead of git?

Now you can with this patched version of bundler 1.0.10 that add the ‘-H’ switch to bundle gem

 bundle help gem
Usage:
  bundle gem GEM

Options:
  -H, [--hg=Use mercurial instead of git]
  -b, [--bin=Generate a binary for your library.]
      [--no-color=Disable colorization in output]
  -V, [--verbose=Enable verbose output mode]       

Creates a skeleton for creating a rubygem

Not enough for you?

If this is not enough for you, I’ve also a patch set for loading gems directly from mercurial repos. This patched bundler v1.1pre.1 will make you happy.

#Gemfile
gem 'eusplazio', :hg => 'http://bitbucket.org/nolith/eusplazio', :tag => 'v0.0.2'

Happy conding

Install instructions

Download the zipped source and extract it; enter the source folder and type rake install

(l0g.in 4ASLAn)

YubiRuby - Yubikey with Ruby

Some days ago, willing to learn how to extends ruby with C code, I wrote a wrapper for yubico-c library.

You can find the sourcecode of my work on bitbucket and some installation instruction on the gemmcutter page.

After installing the gem with gem install YubiRuby you can try it with the following code

require 'rubygems'
require 'YubiRuby'

key = "6df89690b5f51bd9ac912c5004781e86" #use your AES key
y = YubiRuby::Yubikey.new(key);
puts y.key
otp = gets().strip
puts y.parse(otp)
puts "Ouput: #{y}"
puts "uid: #{y.uid}"
puts "counter: #{y.counter}"
puts "capslock: #{y.triggered_by_capslock?}"
puts "timestamp low/high: #{y.timestamp_low}/#{y.timestamp_high}"
puts "session: #{y.session}"
puts "random: #{y.random}"
puts "crc: #{y.crc}"
puts "crc residue: #{y.crc_residue}"
puts "crc residue ok?: #{y.crc?} (#{y.crc_residue} == #{YubiRuby::Yubikey::CRC_OK_RESIDUE})"

I hope to find the time for writing an authlogic extension in order to use a yubikey with rails application.

(l0g.in 44EHHH)

[redirector] Sinatra + Heroku=> Micro-applicazioni di cui non preoccuparsi

Oggi mi son imbattuto in un problema che ho risolto grazie a sinatra ed heroku.

Nei giorni scorsi avevo deciso di usare il domino bb.alessiocaiazza.info come mia pagina personale su bitbucket, solo che poi ho comprato il dominio l0g.in e avrei preferito usare code.l0g.in.

Fin qui nulla di male, ma come fare con tutti i link che avevo disseminato in giro per il web? Avrebbero puntato ad una pagina di errore? No!

Mi è venuto in mente che con sinatra è possibile catturare le url con delle regexp…quindi…

#
# redirector
#
# (c) 2009 - Alessio Caiazza 

require 'rubygems'
require 'sinatra'

REDIRECT_TO='http://l0g.in'

get '/' do
    redirect REDIRECT_TO
end

get '/*' do
    redirect "#{REDIRECT_TO}/#{params[:splat][0]}"
end

e poi deploy su heroku e custom domain service …..fatto!

Ho colto l'occasione per provare hg-git, quindi ho pubblicato tutto su github.

(l0g.in 3zyK8N)
Alessio

Hello. My name is Alessio Caiazza. I'm also known as nolith. I love writing code and technology. I'm passionate about production engineering.

This is where I write my thoughts trying to follow IndieWeb principles.

Staff Backend Engineer, Delivery @ GitLab

he/him/his

IU5BON HamRadio callsign

"Il sapere umano appartiene al mondo."

An IndieWeb Webring 🕸💍