|\| | |-| € [)

Category: Ruby

Récupération des BokBok avec Ruby

Nous avons mis ce script ruby pour télécharger le maximum d’images BokBok du site lapresse

Ce script utilise un GET pour récupérer le flux HTTP et l’écrire dans un fichier

  1. require ‘net/http’
  3. for i in  (1347).downto(1)
  4.     Net::HTTP.start("www.lapresse.tn") do |http|
  5.         resp = http.get("/images/upload_files/au_gre_des_jour/#{i}.jpg")
  6.         open("#{i}.jpg", "wb") do |file|
  7.             file.write(resp.body)
  8.         end
  9.     end
  10. end
  11. puts "Done."

Apprendre Ruby et Rails

Pour apprendre un nouveau langage de programmation rien de mieux que de l’installer 🙂 mais par la suite il faudrait penser à chercher un bon livre et de bons tutoriels sur internet.
Aujourd’hui, je vais partager avec vous deux liens que je trouve très intéréssant et indispensable pour commencer.
Le premier, http://tryruby.org/ est un interpréteur en ligne capable de vous aider à découvrir la richesse du langage ruby.

Le deuxième est un site de formation, http://www.codeschool.com/,offrant un cour gratuit de Rails ayant pour nom Rails for Zombies. Ce cour est très bien fait pour commencer et comprendre la logique du framework Ruby on Rails.
Pour finir, il faudrait faire un tour du coté des bibliothèques pour dénicher un bon livre.

Ruby on Rails Support Discontinued in NetBeans IDE

I just receive an email :

Dear NetBeans Community:

After thorough consideration, we have taken the difficult step to discontinue support for Ruby on Rails in the NetBeans IDE. Two main issues underpin this decision:

Java SE 7 and Java Development Kit 7 (JDK 7) are the next major releases of the Java SE platform, which Oracle is committed to deliver in 2011. A key objective of the NetBeans IDE has always been to offer superior support for the Java platform. To maintain that objective and capitalize on the JDK 7 release themes--multi-language support, developer productivity and performance--it is necessary that our engineering resources are committed to a timely and quality release of NetBeans IDE 7.0.

Second: Although our Ruby support has historically been well received, based on existing low usage trends we are unable to justify the continued allocation of resources to support the feature.

As of January 27, the Ruby on Rails module will be gone from development builds of NetBeans IDE 7.0. Developers who want to continue to use Ruby on Rails functionality in the NetBeans IDE should please visit the NetBeans Ruby Support page for details on how to do so going forward.

We remain committed to delivering a first-class product to our community of developers and users, and we encourage your feedback on our mailing lists and forums, on Twitter, or by writing to us.

Thank you for your continued support of NetBeans.
The NetBeans Team

My question now :

  • is this real ??
  • why Oracle do that for RoR community ??

NetBeans is one of the best alternative to develop ruby and ruby on rails. For my last tutorials, I’m using it and love the gem’s explorer. If the support of RoR on Glassfish will be abort then many questions for Oracle practice will come.

How to retrieve Twitter account followers

Follow nihed on Twitter

With Ruby, Imagination is your limit. Our example is a way to retrieve a list of followers for an account.
For this sample, I’m using the twitter Gem.

  1. $ sudo gem install twitter

Now, we can explore our code.
First we must call our libraries (Gem).

  1. require "rubygems"
  2. require "twitter"

Next, we should configure an OAuth connexion.

  1. Twitter.configure do |config|
  2.   config.consumer_key = "AAAA"
  3.   config.consumer_secret = "BBBB"
  4.   config.oauth_token = "CCCC"
  5.   config.oauth_token_secret = "DDDD"
  6. end

(AAAA,BBBB,CCCC and DDDD) values can be retrieved on http://dev.twitter.com/apps/new when you create a new application.
After, We must initialize some variables

  1. myfile = File.new("write.txt", "w")
  2. client = Twitter::Client.new
  3. count=0
  4. cursor1=-1
  • myfile: file that be used to create a cvs file
  • client: our connexion with twitter service
  • count: number of count retrieved
  • cursor1: twitter send 100 per 100 account, this variable is used to follow this list

Finally, We can launch our code

  1. while (cursor1 != 0) do
  2. result =client.followers("Account","cursor"=>"#{cursor1}")
  3. cursor1=result.next_cursor
  4. users=result.users
  5. puts count
  6.  users.each do |follower|
  7.    count+=1
  8.     myfile.puts "\"#{count}\",\"#{follower.name}\",\"#{follower.screen_name}\",\"#{follower.url}\",\"#{follower.followers_count}\",\"#{follower.location}\",\"#{follower.created_at}\",\"#{follower.description}\",\"#{follower.friends_count}\",\"#{follower.lang}\",\"#{follower.time_zone}\",\"#{follower.verified}\""
  9.  end
  10.  sleep(5)
  11. end

While, our cursor is not equal 0, we retrieve accounts information using the request followers parameters the name of the account and the position of the cursor. We update our variables and we store the result in the our CVS file.

Facebook Graph with Ruby

The Open Graph protocol enables developers to integrate their pages into the social graph. These pages gain the functionality of other graph objects including profile links and stream updates for connected users. Documentations for facebook api are available on this link.
Ruby offer a library to communicate with Facebook Graph named “rfgraph”.
To install :

  1. $ sudo gem install rfgraph

Next, you can write your code. We will use this library to retrieve user information for a range of id. For this, we will create a loop from 610552189 ( my id) to 610552219 (another id) and show available information :

  1. require ‘rubygems’
  2. require ‘rfgraph’
  4. req = RFGraph::Request.new
  6. for i in 610552189..610552219 do
  7.   begin
  8.     res= req.get_object(i)
  9.     puts "#{res[‘id’]} #{res[‘name’]} #{res[‘first_name’]} #{res[‘last_name’]}"+
  10.       " #{res[‘gender’]} #{res[‘locale’]} #{res[‘link’]}"
  11.   rescue Exception=>e
  12.   end
  13. end

and the result will be :

  1. 610552189 Nihed Mbarek Nihed Mbarek male fr_FR http://www.facebook.com/nihed.mbarek
  2. 610552198 Stephanie Pedrin Stephanie Pedrin  es_LA http://www.facebook.com/stephanie.pedrin
  3. 610552201 Roz Rossington Roz Rossington female en_GB http://www.facebook.com/people/Roz-Rossington/610552201
  4. 610552204 Timbucktwo Hair Timbucktwo Hair  en_US http://www.facebook.com/people/Timbucktwo-Hair/610552204
  5. 610552207 Arkoun Merchant Arkoun Merchant male en_US http://www.facebook.com/arkoun
  6. 610552210 Gulcin Takmaz Gulcin Takmaz female en_GB http://www.facebook.com/people/Gulcin-Takmaz/610552210
  7. 610552213 Lara Mezzanotte Lara Mezzanotte  en_US http://www.facebook.com/people/Lara-Mezzanotte/610552213
  8. 610552217 Kita Collier-Smith Kita Collier-Smith female en_US http://www.facebook.com/people/Kita-Collier-Smith/610552217

For more information :

PS : I hope that facebook block user that try to retreive a large number of information.

Foursquare API with Ruby

Foursquare now is the most important location-based social network and used by many of my contacts. And Ruby, like for every social network offer libraries that can help developer to be more productive. Foursquare is now available as an API using basic authentication or Oauth, for more information documentation.
For Library, GEM’s are available, one of them “foursquare-ruby-api” can do for you what you want.
To install :

  1. $ sudo gem install foursquare-ruby-api

Next, you can write your code to do what you want.
To begin this sample, we must know some useful methods :

  • Checkins : Returns a list of recent checkins from friends.
  • Check-in : Allows you to check-in to a place.
  • History : Returns a history of checkins for the authenticated user.

For more information, Very rich documentation are available with ideas about parameters and results structures.
And our Example will be a list of recent checkins from our friends:

  1. require ‘rubygems’
  2. gem (‘foursquare-ruby-api’)
  3. require ‘foursquare’
  4. fq = Foursquare.new(’email’,‘password’)
  5. # fq.test is optional to test our connexion
  6. fq.test
  7. fq.checkins()[‘checkins’][‘checkin’].each do |f|
  8.    puts f[‘display’]+"   "+f[‘created’]
  9. end

For more information :

PS: This api can be used as a hack to be mayor for many places from your house or office 😀

Twitter Search with Ruby

Ruby is one of the most powerful language with the number of GEM’s (Packages) that can be used to connect on every component of internet.
For twitter, GEM’s are available, one of them “twitter” can do for you what you want.
To install :

  1. $ sudo gem install twitter

Next, you can write your code to do what you want (Search for our example) .
To begin this sample, we must know some useful option for search :

  • from(“XXXX”) : to define the sender of our messages
  • to(“XXXX”) : to define the receiver of our messages
  • since_date(“YYYY-MM-DD”) : to get tweets after a given date

For more information : http://rdoc.info/github/jnunemaker/twitter/master/Twitter/Search
And our code will be :

  1. require ‘rubygems’
  2. require ‘twitter’
  3. #search for the word nihed since 01/11/2010
  4. Twitter::Search.new(‘nihed’).since_date("2010-11-01").each do |r|
  5.   puts r.from_user+": "+r.text+"\n\n"
  6. end

Like we can see, with ruby, we have a simple and beautiful code.
For more information :
Twitter Search API Method

Tunisia on Rails 1.0

Le 15 Mai 2010 a eu lieu en Tunisie la première conférence rails ( j’espère que ce ne sera pas la dernière) organisé par JCI. Durant cet événement, nous avons eu le plaisir d’assister à deux présentations majeurs, celle de Ruby suivi celle de Rails toutes faites par Mr Richard Piacenti que nous saluons au passage pour son formidable charisme.
Pour ce qui est de Ruby, Il a donné l’envi aux présents de vouloir tester ce langage à travers des slides légers, bien expliqués et des exemples alléchants.
Quant à Rails, il n’a pas hésité à rappeler que c’est un framework et non pas un langage de programmation. Il a très bien expliqué l’architecture de ce dernier. Mais à mon avis, une démo avec des scaffold’s et des relations auraient pu donné un plus à la fin de la présentation.
Pour finir, je voudrai rappeler que s’était un plaisir d’être à la première et que d’autres présentations suivront inchallah.

PS 1 : Je sais pas pourquoi mais JCI a donné plus de valeur aux sponsors qu’au conférencier.
PS 2 : J’ai pris la photo de la page facebook event.

Ruby + Postgres on fedora

For persons who want to use postgres database on a Ruby program, a package are available.
To install this package use this command :

  1. yum install ruby-postgres

You can use this sample of code to test installation :

  1. #!/usr/bin/ruby
  2. require ‘postgres’
  4. conn = PGconn.connect("host", 5432, , , "database", "user", "password")
  6. res  = conn.exec(‘select tablename, tableowner from pg_tables’)
  8. res.each do |row|
  9.         row.each do |column|
  10.                 print column
  11.                 (20-column.length).times{print " "}
  12.         end
  13.         puts
  14. end

Ruby Extention :

Ma rencontre avec Ruby


J’ai rencontré le mec qui a fait ruby le langage de programmation, je ne sais pas pour vous mais moi, c’est comme rencontrer une star. je lui ai même demandé une photo.

Copyright © 2019 |\| | |-| € [)

Theme by Anders NorenUp ↑