The Atom Exerciser on Heroku 0

Posted by david

From some time I've been getting some visits in this blog from Tim's page and I didn't know why, until this morning when I needed to use his Ape instance and I came across it was down.

I needed to use it from outside my private network, I thought on deploy it on Google App Engine, so I took the oportunity to move the repository to a more cool home, get rid of the old mongrel code and use a Rackable framework to manage its server and move its realeases to gemcutter.

All in all, after almost an hour trying to deploy it in GAE I realized I couldn't use it because its restrictions policy, so in the 10 minutes between I wrote these two tweets, I downloaded heroku gem, wrote a rack config file and deploy Atom Exerciser on Heroku. Enjoy it.

Jeweler vs rubyforge 0

Posted by david

Last week I released the first version of Trinidad, a project that I develop with the help of Jeweler, a gem that gives you the tools to release a gem in github quickly, and with some options it also helps you to release your gem in rubyforge, but here my problems started.

In the Jeweler's wiki there is a page with the first problem I bumped into, and in its issues tracker there is also a thread with the problem that almost went me nuts, and any solution didn't solve my problems.

My solution, start from the begining, step by step. First step, configure rubyforge, the best guide you can find to configure rubyforge is in the newgem generator's page. Second step, release your gem with jeweler.

All in all, if you want to release a gem in rubyforge with jeweler, run these commands and forget to edit rubyforge configuration's files, it worked for me, at least:


$ rubyforge config
$ rubyforge login
$ rubyforge names
$ rubyforge create_package #project_name# #gem_name#

$ rake rubyforge:release

European Ruby Konference 2009 in Barcelona 0

Posted by david

I'm glad to announce that we have dates and venue for the next Euruko 2009 in Barcelona, May 9 and 10 in the Citilab, a beatiful place that hosted other big international conferences like DrupalConf or OpenOffice.org Conference.

You can see the official announce in the Euruko web page, we'll open the call for papers in the next weeks, stay in touch!

rubyMetrics 1.2 supports Rails stats 4

Posted by david

I've just released the version 1.2 of the rubyMetrcics plugin for Hudson, and I've added support for Rails stats, so, if you check the right option hudson generates the report and its trend graph:

You can find more info into the plugin page.

Ruby Metrics plugin for Hudson 1

Posted by david

I couldn't keep quiet after I read this Arun Gupta's post, so I've just released the first version of the Ruby metrics plugin for Hudson.

This plugin aims to collect a bunch of ruby metrics tools and integrate them with Hudson. The first release allows to integrate Rcov reports into Hudson and builds a trend graph with the coverage of your project between releases.

You can find more screenshots in the plugin wiki page. Enjoy it!

The APE meets RubyGems 18

Posted by david

When I talked about the ape in the past Conferencia Rails 07 I remarked that it wasn't quite easy to install and configure. Today I can announce that this is no longer true.

We've transformed a lot of scripts in a ruby gem that provides a Mongrel based server. Once the ape gem is installed and this server is running, the web interface is available in the port 4000 of your localhost.


  $ sudo gem install ape && ape_server

Moreover, the new ape gem uses the erubis library to load the atom entry templates that it uses to test the atomPub server. These templates can be overrided by the user, the gem searchs the APE_HOME enviromment variable or the .ape directory into the user home directory. Within this directory the user can leave his atom entry templates with the names mini_entry.eruby, basic_entry.eruby or unclean_xhtml_entry.eruby.

We are excited with this release and we are working hard to eliminate possible bugs and add documentation in addition to new capabilities in order to test any atomPub server behaviour.

Enjoy it!

Update: I just put an instance of The Ape running on Heroku to use it online, you can see more details in the announcement.

AtomPub, ruby y la api de 11870.com 2

Posted by david

Así se titula la charla que imparto en la segunda conferencia rails. Pretende ser una introducción a atomPub, la api de 11870 y todo esto mezclado con un poco de ruby.

Ya podéis descargar la presentación en formato pdf. Agradezco cualquier comentario, espero que sea útil.

Actualización: he subido la presentación a SlideShare para que se pueda ver desde aquí.

Ruby y Ejabberd 2

Posted by david

Ejabberd es uno de los servidores jabber más populares que existen y una de sus características más destacable es la posibilidad de autenticar usuarios de forma externa. Con esta opción podremos integrar mensajería jabber en nuestra aplicación sin tener que modificar nuestra base de datos o migrar nuestros usuario ya registrados a la base de datos del servidor.

En la página del proyecto podemos encontrar varios scripts para autenticar usuarios contra distintas bases de datos o servicios de directorio.

En este artículo vamos a ver como configurar el servidor para que autentique a los usuarios a través de un script en Ruby contra una base de datos Mysql.

La configuración del servidor es sencilla, dentro del directorio donde tenemos instalado ejabberd abrimos el archivo "conf/ejabberd.cfg" comentando la línea donde se indica la autenticación interna:

%{auth_method, internal}

y descomentando las líneas donde se indica la autenticación externa y el path al script que vamos a utilizar:

{auth_method, external}.
{extauth_program, "/var/www/apps/trunk/config/ejabberdAuth.rb"}.

A la hora de introducir los parámetros de conexión con nuestra base de datos tenemos varias opciones, pero si estamos desarrollado una aplicación con Ruby on Rails podemos recoger estos datos directamente de nuestra configuración:

environment = 'development'
#PATH ABSOLUTO AL FICHERO DE CONFIGURACION
config_file = '/var/www/apps/trunk/config/database.yml'
cfg = YAML.load_file(config_file)[environment]

Para conectarnos con la base de datos usaremos el módulo DBI para ruby:

host = cfg['host'] || '127.0.0.1'
db_con = "DBI:Mysql:#{cfg['database']}:#{host}"
@db = DBI.connect db_con, cfg['username'] , cfg['password']

Los paquetes que el servidor ejabberd envia y recibe del script tienen un formato determando. Cuando el script recibe un paquete dentro de sus dos primeros bits se encuentra la longitud de la cadena de datos que tenemos que leer. Esta cadena tiene un formato determinado:

operación : usuario : nombre del servidor jabber : contraseña

Por ejemplo:

auth:david:thinkincode.net:david

La respuesta al servidor debe ser 1 en caso de que la operación sea correcta o 0 en caso contrario. Esta respuesta también está empaquetada con los dos primeros bits libres para su longitud.

buffer = String.new
while STDIN.sysread(2, buffer) && buffer.length == 2

  length = buffer.unpack('n')[0]
  operation, username, domain, password = 
      STDIN.sysread(length).split(':')	      
	      
  response = case operation 
      when 'auth'
          auth username, password.chomp
      when 'isuser'              
          isuser username
      else
          0
      end
				    
  STDOUT.syswrite([2, response].pack('nn'))
end

Una vez que hemos obtenido los datos introducidos por el usuario sólo tendremos que validarnos contra nuestra base de datos según la operación que hayamos recibido. El método para autenticar el usuario podría quedar así:

def auth(username, password)
  row = @db.select_one("select password from users"
    " where user_name = ? and activated_at IS NOT NULL", 
    username)
    
  return (1 if row and row['password'] == password) || 0
end

Una vez terminado el script tendríamos que arancar el servidor jabber para que nuestros usuarios puedan conectarse con su cliente favorito usando el usuario y contraseña que han introducido en nuestra aplicación.

Un pequeño truco para ver si el servidor ha arrancado correctamente es ver si tenemos un proceso corriendo con el script que hemos configurado.

Dejo el código completo del script para poder ver el ejemplo más detalladamente.