Rock & Gol es troba amb streamripper

Hola

Desde fa un temps estic escoltant cada dia mentre treballo un programa de radio via internet (cosa que no es pot fer a totes les feines bé perque no deixen o bé perque no pots estar desconnectat del món experior) que es diu Rock&Gol on posen música de tot tipus desde els anys 50 fins ara (no només rock sinó tambe soul, funk, country, etc) excepte porqueries com els Jonas brothers o la Celine Dione. Ja que molta gent preguntava quina cançó havia sonat em vaig decidir a començar una petita web, amb la qual em vaig entretenint i reforçant la programació en Ruby on Rails, on anar anotant la gent les cançons que coneixia perque la resta pogués consultar-ho i localitzar la cançó.

Com que soc un friki, tant de la música com de la informática, vaig pensar de gravar el programa cada dia per oferir-los en descarrega lliure desde la web i vaig buscar un programa de consola per gravar streaming en mp3 (si, ja se que el ogg es superior i que el mp3 es propietari, però es el que coneix més gent mal ens pesi)…i vaig trobar el streamripper que cubreix totes les meves necessitats.

La veritat es que es molt senzill i va molt bé perque el puc iniciar amb un script cridat per el cron i després renombrar l’arxiu resultant amb la data del dia.

Si no el coneixieu (jo no fins ara) espero que us pugui servir algun dia.

Salut

M.

 

Override table’s primary key using migrations in rails.

Hi

When a migration is created, rails add a column named id, which is defined as an integer, as table’s primary key column. Sometimes can happen that you don’t want to name your primary key column id using rails. The way you have to write your migration is this one (rails use integer type by default):


def self.up
create_table :airport, :primary_key => :airport_id do |t|
t.string :iso_code, :limit =>3, :null => false
t.string :name, :limit =>150, :null => false
t.integer :city_id, :null => false
end
end

If you have a “many to many” table probably you don’t want to have this id column in your table and you want to define two columns as primary key. This is the way you have to write a migration if you want to define this primary key:


def self.up
create_table :airports_cities, :primary_key => [:airport_id, city_id] do |t|
t.integer :distance, :null => false
end
end

In both examples, columns defined as primary key don’t have to be defined because rails do it for you. Using this, you won’t have an id column in your table and you’ll be able to use whatever you want as primary key (even strings).

Hope this helps (to my fish-like memory or to somebody else’s brain).

M.

 

Things to remember 2010-01-12 (former Something I always forget)

Howto create the table to store sessions in Rails

rake db:sessions:create

Howto truncate all *.log files in log/ to zero bytes

rake log:clear

M.

 

Incredible Guitar & Bass performance

It’s amazing

M.

 

Something I always forget II

I always forget how to dump my blog’s mysql database. It’s :

mysqldump db_name -u username -p > filename

That's all

M.

 

Something I always forget

I always forget how to add a source using rubygems. It’s (using ‘http://gems.github.com’ as example) :

gem sources -a http://gems.github.com

That’s all

M.

 

Debian is not easy to install

18:30 – Donwload Debian stable netinst and burn a CD (15-20 minutes).
19:00 – Installing netinst (over 20 minutes).
19:30 – Reboot, /etc/apt/sources.list changed from stable to unstable && aptitude update && aptitude dist-upgrade (over 25 minutes).
20:00 – aptitude install kde-full (I don’t know, I was having dinner).
22:15 – System configured and running perfectly.
22:20 – Copying data from the old filesystem (ext3) to the new filesystem (ext4).
23:15 – Old system replaced completely by new system.

Sure?

M.

 

18 years

18 years ago Freddie Mercury left us. God save the Queen.

M.

 

will_paginate problem

Sometimes, a search has to be coded in an application and if you are using rails, probably you’ll use will_paginate. It is a good piece of software, easy to install and easy to use but, if it’s not used correctly, problems may appear.

I use it using a form_for rails’s tag and four search criteria in it. After coding it, I added will_paginate and after doing my first search, I paginated to the second page…it came empty. After googling a little, I noticed that I was sending info using POST method and will_paginate needs GET method to work properly, so the only thing needed was:

:html => { :method => :get}

and it worked perfectly, passing parameters to the next pagination.

Hope this helps, it’s something silly but sometimes silly things made people go into the dark side of coding ;-)

M.

 

Problem installing rmagick (using ruby 1.9.1)

Hi dudes

I’m coding my web application and I need to use the simple_captcha gem, which uses rmagick to generate captchas. I’m trying to install it, I already have imagemagick installed in my debian sid, and I found the following problem


ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for cc... yes
checking for Magick-config... no
Can't install RMagick 2.12.2. Can't find Magick-config in /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin

Googling a little I found this page which explains what to do, which is ‘apt-get install libmagickcore-dev‘ as root or using sudo.

After this, a new error appears


Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for cc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.3.5... yes
checking for HDRI disabled version of ImageMagick... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... no

Can't install RMagick 2.12.2. Can't find MagickWand.h.

And a new action is taken ‘apt-get install libmagickwand-dev‘.

Problems solved and gem installed.

M.