RBrainz - Musicbrainz API for Ruby !


Today I've decided to test a simple API for Ruby, so I look for something in the Rubyforge.I found the Rbrainz, how the title describe, a MusicBrainz API, I really don't know what was MusicBrainz, I only know that amarok use it. I search about this in the Wikipedia. It's a music library, well I love music and Ruby, so I start to program with it. Now let's see a small tutorial:

First, download the API in the official website(http://rbrainz.rubyforge.org/) or using the gems:

gem install rbrainz

Starting our script, read the comments:

_________________________________________________________________

#/usr/bin/env ruby

require 'rubygems'

require 'rbrainz'

include MusicBrainz

#we required the dependencies

artists_includes = Webservice::ArtistIncludes.new(

 :aliases=>true,

 :releases=>['Album', Official'],

 :artist_rels=>true,

 :release_rels=>true,

 :track_rels=>true,

 :label_rels=>true,

 :url_rels=>true,

#We created a Hash with informations

query = Webservice::Query.new
id = '
ba853904-ae25-4ebb-89d6-c44cfbd71bd2'
artista = query.get_artist_by_id(id, artist_includes)

#Variables for describe the webservice(query), the artist ID, you can see the information searching in the musicbrainz's website and we put the object called artist the id and the hash called artist_includes.

#Now we will print the informations

print <     <     eof

ID number(número de id):#{artista.id.uuid}

Name(nome):#{artista.name}

Begin date(data de início):#{artista.begin_date}

End date(data do fim):#{artista.end_date}

Aliases(participantes):#{artista.aliases.to_a.join('; ')}

Releases(Álbuns):#{artista.releases.to_a.join('; ')}

EOF

_________________________________________________________________

End of the script, now see the output:

ID : ba853904-ae25-4ebb-89d6-c44cfbd71bd2
Name : Blur
Begin date : 1989
End date : 
Aliases : Albarn James Coxon Rowntree
Releases : Modern Life Is Rubbish; Modern Life Is Rubbish; Leisure; Leisure; Modern Life Is Rubbish; Modern Life Is Rubbish; Parklife; Parklife; Leisure; The Great Escape; The Great Escape; The Great Escape; Blur; Blur; 13; 13; Think Tank; Think Tank

Yes, ba853904-ae25-4ebb-89d6-c44cfbd71bd2is the Blur's ID

I take the ID here: http://musicbrainz.org/show/artist/details.html?artistid=361

Python?

Rock, paper, scissor... and Ruby



Well, I wrote this game in a stressed day. Ruby make me feel better.
Now, see the code:

#!/usr/bin/env ruby
#Pedra, papel, tesoura e Ruby ;D
def pedra
b = rand(3)
if b == 0
puts "Pedra, empate"
return menu()
elsif b == 1
puts "Tesoura, você ganhou"
return menu()
elsif b == 2
puts "Papel, você perdeu"
return menu()
end
end
def tesoura
b = rand(3)
if b == 0
puts "Pedra,Você perdeu"
return menu()
elsif b == 1
puts "Tesoura, empate"
return menu()
elsif b == 2
puts "Papel, você ganhou"
return menu()
end
end
def papel
b = rand(3)
if b == 0
puts "Pedra, você ganhou"
return menu()
elsif b == 1
puts "Tesoura, você perdeu"
return menu()
elsif b == 2
puts "Papel, empate"
return menu()
end
end

def menu
puts "Opcao: \n[1] Pedra \n[2] tesoura \n[3] papel \n[Qualquer numero] sair"
print ">>"
a = gets.chomp.to_i
case (a)
when 1
pedra()
when 2
tesoura()
when 3
papel()
end
end

menu()

Ruby, Gtk+ and Txt's

Well, I create a script in Ruby that you write a thing in the Text Box and you can read it in a txt file. Look ate the image and scripts:


#!/usr/bin/env ruby
# Escrito por Carlos Junior Félix Rodrigues; Licença: GPL v2
require 'gtk2'
window = Gtk::Window.new
window.title = "Text Box"
button = Gtk::Button.new("Salvar")
text = Gtk::Entry.new
hbox = Gtk::HBox.new(false, 10)
hbox.pack_start(text)
hbox.pack_start(button)
window.add(hbox)
window.signal_connect("destroy"){Gtk.main_quit}
button.signal_connect("clicked"){
arquivo = File.new("arquivo.txt", "a")
arquivo.puts "#{text.text}"
arquivo.close
}
window.show_all
Gtk.main

See you latter

Arts

This year I'm being so creative. I'm using the Vim to program, I'm drawing more in the gimp and I'm reading more texts in English. Well, I'm here to show my small gallery:
Old screenshots, Kde-mod and Xfce



































The new:

















And the art: