tag:blogger.com,1999:blog-354286282960197152024-03-13T05:16:53.748-07:00Spejman On RailsRuby, Ruby on Rails, Artificial Intelligence and something more ...Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-35428628296019715.post-14494116302146167412007-09-21T09:57:00.000-07:002007-09-21T10:02:00.320-07:00Making Rails More (Artificially) Intelligent slides & source codeI have just posted the session slides and source code of the RailsConf Europe talk Making Rails More (Artificially) Intelligent that Santiago Bel and me did last Tuesday. You can download them all at <a href="http://bee.com.es">bee.com.es</a><br /><br />We hope you find them useful. Please note that the ones that are at the railsconfeurope.com web are out of date, now I will send the updated slides to o'reilly.Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.com4tag:blogger.com,1999:blog-35428628296019715.post-11805156409867354062007-09-14T02:42:00.000-07:002007-09-14T02:48:39.859-07:00Railsconf Europe talk: Making Rails More (Artificially) IntelligentNext Tuesday, my colleague Santiago Bel and me will talk about Artificial Intelligence (AI) at the RailsConf Europe. Should you attend the conference, you are invited to our talk too.<br /><br />We will show you how easily you can introduce AI algorithms into your rails applications in order to improve them. We will talk about 3 kinds of AI algorithms: Bayesian Networks to make predictions, Naïve Bayes Classifier to classify data, and Genetic Algorithms to solve complex problems as automatical optimization of web ads placement.<br /><br />We hope you find this session interesting and that you enjoy it!Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.com0tag:blogger.com,1999:blog-35428628296019715.post-7821682953272541522007-09-03T13:18:00.000-07:002007-09-03T13:22:36.581-07:00The Talking Rails ApplicationAfter a long time without publishing anything, I have finished an example of what you can do with <a href="http://festivaltts4r.rubyforge.org/">festivaltts for Ruby</a>: A Ruby on Rails application that talks!<br /><br />You can test it at: <a href="http://thetalkingrailsapp.sergioespeja.com/">http://thetalkingrailsapp.sergioespeja.com/</a><br /><br />I hope it gives you ideas for your RoR applications!Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.com0tag:blogger.com,1999:blog-35428628296019715.post-49180674275421492822007-06-12T07:41:00.000-07:002007-06-11T22:46:36.636-07:00Text to speech for Ruby on Rails applicationsI just published the first usable festivaltts4r version, it comes with its plugin for Ruby on Rails, festivalttsOnRails. With this library and this plugin you can make talk your Ruby and your Ruby on Rails applications.<br /><br />The rails plugin is so easy to use in Ubuntu linux:<br /><ol><li>Install tts and mp3 generation libraries:<br /><pre><code><br />sudo apt-get install festival lame<br /></code></pre></li><br /><li>Install the festivalttsOnRails plugin for Ruby on Rails:<br /><pre><code><br />script/plugin install \<br />svn://rubyforge.org/var/svn/festivaltts4r/plugins/festivaltts_on_rails<br /></code></pre></li><br /><li>Use text_to_flash_player(text) method in your views:<br /><pre><code><br /><%= text_to_flash_player "Talk me!" %><br /></code></pre></li></ol><br />At the moment the plugin works with a simple english voice but can be very useful as a proof of concept. If people found it interesting it could be improved.<br /><br />It works so well in Ubuntu Linux, testing in other platforms will be appreciated.<br /><br />You can also use the festivaltts4r gem in order to make local voice applications with Ruby:<br /><ol><li>Install tts and mp3 generation libraries:<br /><pre><code><br />sudo apt-get install festival lame<br /></code></pre></li><br /><li>Install festivaltts4r gem:<br /><pre><code><br />sudo gem install festivaltts4r<br /></code></pre></li><br /><li>Include required gems and call to_speech method defined into the String class by festivaltts4r:<br /><pre><code><br />require "rubygems"<br />require "festivaltts4r"<br /> <br />"I'm talking".to_speech<br /></code></pre></li></ol><br />This project has been developed using <a href="http://www.cstr.ed.ac.uk/projects/festival/">Festival TTS</a> and <a href="http://lame.sourceforge.net/index.php">lame</a> libraries.<br /><br />The flash mp3 player used to play the voice has been developed by <a href="http://www.estvideo.com/dew/index/2005/02/16/370-player-flash-mp3-leger-comme-une-plume">dew</a> under <a href="http://creativecommons.org/licenses/by-sa/2.0/fr/deed.fr">Creative Commons Attribution-ShareAlike License France</a> license.<br /><br />More info about festivaltts4r and festivalttsOnRails: <a href="http://festivaltts4r.rubyforge.org/">festivaltts4r.rubyforge.org</a>Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.com3tag:blogger.com,1999:blog-35428628296019715.post-52567843997506860712007-06-05T06:42:00.000-07:002007-06-05T06:47:36.064-07:00Draw with Ruby and Scribble!Looking at the new blog of _why (<a href="http://hackety.org">http://hackety.org</a>) I found <a href="http://nex3.leeweiz.net/posts/3">Scribble!</a> that it's a Ruby version of <a href="http://nodebox.net/code/index.php/Home">NodeBox</a>. Its aim is to make cool graphics using Ruby.<br /><br />If you want to test it using windows, you can follow the instructions at <a href="http://nex3.leeweiz.net/posts/3">http://nex3.leeweiz.net/posts/3</a><br /><br />I wanted to test it in Linux but I didn't found related information, then I did some research on how to install it. Finally, I made it work in Ubuntu following these steps:<br /><ol><li>Install cairo and gtk2 ruby libraries and get the scribble code:<br /><pre><code><br />sudo apt-get install libcairo-ruby1.8 libgtk2-ruby<br />svn co svn://hamptoncatlin.com/scribble/trunk scribble<br /></code></pre></li><br /><li>Execute scribble:<br /><pre><code><br />cd scribble<br />bin/scribble<br /></code></pre></li></ol><br />With these steps we'll execute Scribble! and we can do graphs like this:<br /><br /><img src="http://farm1.static.flickr.com/222/516610626_0766a79444.jpg" width="435" height="500" alt="Scribble! Screenshot" /><br /><br />This drawing is uniq because it is randomly generated from this code:<br /><pre><code><br />brush.fill = rand(0.1) + 0.9, rand(0.4) + 0.6, rand(0.1) + 0.9, rand(0.1)+0.1<br />blanket<br /><br />brush.fill = rand(0.1) + 0.9, rand(0.4) + 0.6, rand(0.1) + 0.9, rand(0.1)+0.1<br />brush.stroke = rand(0.4) + 0.6, 0, 1, 0.2<br />brush.width = 2<br /><br />100.times do<br />circle :center => [rand(size[0]), rand(size[1])], :radius => rand(50) + 10<br />end<br /></code></pre><br /><br />If you like Scribble! and make some cool graphics, share it putting its code as a comment in this post ;)Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.com0tag:blogger.com,1999:blog-35428628296019715.post-85212963413634763482007-05-28T02:13:00.000-07:002007-05-28T03:26:27.276-07:00Using MySQL reserved words as model namesThe generation of a model with a migration in a ruby on rails application lets to the creation of a database table with the pluralization form of the desired model name. In MySQL, a migration will generate a sql statement like:<br /><pre><code><br />CREATE TABLE model_name_pluralized (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY,<br /> `created_on` date DEFAULT NULL, `name` varchar(255) DEFAULT NULL) ENGINE=InnoDB<br /></pre></code><br />As you can notice column names are quoted but table name doesn't. If you use as a model name a sigularized form of a MySQL reserved word, the migration that creates this model will generate a statement that will lead to an error like:<br /><pre><code><br />Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your<br /> MySQL server version for the right syntax to use near 'databases (`id` int(11) DEFAULT NULL <br />auto_increment PRIMARY KEY, `created_on` da' at line 1: CREATE TABLE databases (`id` int(11) <br />DEFAULT NULL auto_increment PRIMARY KEY, `created_on` date DEFAULT NULL, `name` varchar(255)<br /> DEFAULT NULL) ENGINE=InnoDB<br /></pre></code><br />Last week I read the <a href="http://hasmanythrough.com">Josh Susser</a> <a href="http://hasmanythrough.com/layingtracks/LayingTracks.pdf">Laying Tracks slides</a> who<br />encourages me to write a patch for this issue.<br /><br />Before writing anything I tried to find if someone has made something related and I found some tickets related in <a href="dev.rubyonrails.org">Rails trac</a>:<br /><ul><li><a href="http://dev.rubyonrails.org/ticket/7850"><span style="text-decoration: line-through">#7850</span>: [PATCH] Added missing backticks to mysql adapter</a></li><br /><li><a href="http://dev.rubyonrails.org/ticket/4905"><span>#4905</span>[PATCH] Rails should backtick table names automagically</a></li><br /><li><a href="http://dev.rubyonrails.org/ticket/3631"><span style="text-decoration: line-through">#3631</span>: table names should be quoted</a></li><br /><li><a href="http://dev.rubyonrails.org/ticket/1633"><span style="text-decoration: line-through">#1633</span>: [PATCH] quote_column_name in ActiveRecord::ConnectionAdapters ...</a></li></ul><br /><br />The most interesting of this tickets is #4905 which fix all MySQL statements to prevent reserved words crash, but I don't know why isn't included in the code because it's last history is from 05/25/2006. #7850 is closed as duplicated because of #4905. And #3631 history finishes with "don't use reserved words" what in my opinion isn't the best solution.<br /><br />In brief, the problem exists (I can't name my models with names like "database", "exist", ...) and the patch too (#4905). Then, what should we do to fix this problem?Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.com0tag:blogger.com,1999:blog-35428628296019715.post-65729633346552324462007-05-14T23:14:00.000-07:002007-05-15T02:04:23.768-07:00Backup of Bloglines keep new itemsIf you are a <a href="http://www.bloglines.com">Bloglines</a> user, you probably save the interesting posts using "keep new" feature.<br /><br />If you have use this reader for a time, the quantity of post saved could be large... Some day I thought that won't be funny to loose all this data, then I build a ruby script to backup bloglines "keep new" items into a xml file.<br /><br />With this script I learned better <a href="http://mechanize.rubyforge.org/mechanize/">Mechanize</a> and <a href="http://code.whytheluckystiff.net/hpricot/">Hpricot</a> Ruby libraries.<br />Este script me ha servido para probar dos librerías muy útiles de Ruby: <a href="http://mechanize.rubyforge.org/mechanize/">mechanize</a> y <a href="http://code.whytheluckystiff.net/hpricot/">hpricot</a>.<br /><br />You need these libraries in order to use the script:<br /><pre><code><br />gem install json<br />gem install activesupport<br />gem install hpricot<br />gem install mechanize<br /></code></pre><br /><br />And here you have the script. I think is very understandable. I hope it helps you to backup your bloglines account (remember to change EMAIL and PASSWORD values with yours) or to understand better how mechanize and hpricot works.<br /><pre><code><br />require "rubygems"<br />require "hpricot"<br />require "json"<br />require "mechanize"<br />require "active_support"<br /><br /># Reads a bloglines javascript tree structure that has all<br /># feeds data.<br />def read_tree( tree_base, label = "" )<br /> tree_base.each do |tree|<br /> if tree["kids"]<br /> read_tree tree["kids"], label + "/" + tree["n"]<br /> else<br /> @feeds << [tree["n"], label, tree["kn"], "http://www.bloglines.com/myblogs_display?sub=#{tree["id"]}&site=#{tree["sid"]}"]<br /> end<br /> end<br />end<br /><br /># Add more memory to hpricot otherwise couldn't load some webs.<br />Hpricot.buffer_size = 262144<br /><br />agent = WWW::Mechanize.new<br />page = agent.get 'http://www.bloglines.com/login'<br /><br />form = page.forms[1]<br />form.email = 'EMAIL'<br />form.password = 'PASSWORD'<br /><br />page = agent.submit form<br /><br /># Get the bloglines sindicated feeds<br />menu_page = agent.get "http://www.bloglines.com/myblogs_subs"<br />start_text = "var initTreeData = "<br />end_text = "\n;\n"<br />js_feeds_tree_str = menu_page.content[menu_page.content.index(start_text)+start_text.size..menu_page.content.index(end_text)]<br />feeds_tree = JSON.parse js_feeds_tree_str.gsub("\\","")<br />@feeds = []<br />read_tree(feeds_tree["kids"])<br /><br />puts "<bloglines_saves>"<br />@feeds.each do |feed|<br /><br /> page = agent.get feed[3]<br /> doc= Hpricot(page.content)<br /><br /> # get the content of all saved feed posts<br /> content = ((doc/"body")/"td.article")<br /> next if content.empty?<br /> puts "<feed name=\"#{feed[0].strip}\" folder=\"#{feed[1].strip}\">"<br /> <br /> # Iterate each saved feed post<br /> ((doc/"body")/"a.bl_itemtitle").each_with_index do |title, index|<br /> puts "<feed_save title=\"#{title.inner_html.strip}\" href=\"#{title.attributes["href"]}\">"<br /> puts content[index].inner_html.to_xs<br /> puts "</feed_save>"<br /> end<br /> puts "</feed>"<br /><br />end<br />puts "</bloglines_saves>"<br /></code></pre><br />Más información:<br /><ul><li>Hpricot: <a href="http://code.whytheluckystiff.net/hpricot/">http://code.whytheluckystiff.net/hpricot/</a></li><li>Mechanize: <a href="http://mechanize.rubyforge.org/mechanize/">http://mechanize.rubyforge.org/mechanize/</a></li></ul>Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.com33tag:blogger.com,1999:blog-35428628296019715.post-45950347601578820872007-03-29T01:48:00.000-07:002007-05-12T11:24:01.525-07:00General Genetic Algorithms for Ruby (gga4r) release 0.9General Genetic Algorithms for Ruby (gga4r) is a library for executing generic algorithms easily.<br /><br />Only 3 steps are needed in order to work with gga4r:<br /><ol><li>Choose a clase to evolve and define for her the <code>fitness</code>, <code>combine</code> and <code>mutate</code> methods.</li> <br /><li>With an array of last defined class instances (initial population), create a GeneticAlgorithm object.</li><br /><li>Call GeneticAlgorithm's <code>evolve</code> method as many times as you want.</li></ol><br /><br />More info:<br /><ul><li>gga4r website: <a href="http://gga4r.rubyforge.org">http://gga4r.rubyforge.org</a></li><br /><li>gga4r rubyforge project: <a href="http://rubyforge.org/projects/gga4r">http://rubyforge.org/projects/gga4r</a></li><br /><li>gga4r spanish site: <a href="http://gga4r.rubyforge.org/es">http://gga4r.rubyforge.org/es</a></li></ul>Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.com0tag:blogger.com,1999:blog-35428628296019715.post-86585264948733088812007-03-08T12:26:00.000-08:002007-03-08T12:33:25.273-08:00DEISA Sessions (Distributed European Infrastructure for Supercomputing Applications)This week I'm taking DEISA training sessions in Barcelona, they are teaching us how to submit tasks into most powerful supercomputers of Europe (<a href="https://www.deisa.org/grid/architecture.php">DEISA Architecture</a>). <br /><br />Within this supercomputers we can meet <a href="http://en.wikipedia.org/wiki/MareNostrum">Marenostrum</a>, nowadays is the most powerful supercomputer in Europe and the World's fifth most powerful as you can see in <a href="http://www.top500.org">www.top500.org</a>. It's made of 10.240 CPUs Power PCs, 20 TeraBytes of RAM and 370 TeraBytes of disk. It's placed in a old chapel which gives it a special feeling.<br /><br />Today I've been lucky and I could visit inside <a href="http://es.wikipedia.org/wiki/MareNostrum">Marenostrum</a> as you can see in this photos:<br /><br /><a href="http://www.flickr.com/photos/spejman/414859166/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/167/414859166_139c5d89db_m.jpg" width="180" height="240" alt="Marenostrum" /></a><br /><br /><a href="http://www.flickr.com/photos/spejman/414859160/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/183/414859160_80c434aa91_m.jpg" width="240" height="180" alt="Marenostrum" /></a><br /><br /><a href="http://www.flickr.com/photos/spejman/414859174/" title="Photo Sharing"><img src="http://farm1.static.flickr.com/126/414859174_c26b9b7e47_m.jpg" width="240" height="180" alt="Marenostrum Core" /></a><br /><br />More photos: <a href="http://www.flickr.com/photos/spejman/tags/marenostrum/">http://www.flickr.com/photos/spejman/tags/marenostrum/</a>Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.com0tag:blogger.com,1999:blog-35428628296019715.post-87813375669509113892007-01-22T11:16:00.000-08:002007-05-12T11:24:36.416-07:00Bayesian Networks for Ruby release 0.9Bayesian Networks for Ruby (bn4r) permits create, modify, solve, import and export Bayesian Networks, give it a try and infer some probabilities with them!<br /><br />This release includes suport for discrete variable nodes, now you can use nodes with values like {small, normal, big} instead of {true, false}.<br /><br />Export to <a href="http://research.microsoft.com/dtas/msbn/default.htm">Microsoft Belief Network</a> has been improved.<br /><br />As previous releases you can solve your networks with enumeration_ask, prior_sample, rejection_sampling and likelihood_weighting algorithms.<br /><br />Testing work will be appraised, if you are interested please contact me in <a href="http://rubyforge.org/projects/bn4r">http://rubyforge.org/projects/bn4r</a> or at sergio.espeja (you know what ...) gmail.com.<br /><br />More info:<br /><ul><li>bn4r Website: <a href="http://bn4r.rubyforge.org">http://bn4r.rubyforge.org</a></li><li>bn4r Rubyforge project: <a href="http://rubyforge.org/projects/bn4r">http://rubyforge.org/projects/bn4r</a></li><li>bn4r spanish website: <a href="http://bn4r.rubyforge.org/es">http://bn4r.rubyforge.org/es</a></li></ul>Spejmanhttp://www.blogger.com/profile/08456968654669529943noreply@blogger.com3