November, 2007


27
Nov 07

Contributing

I recently found myself with the need to get past the office firewall to listen to some last.fm tunage. To such end I created a ssh tunnel to my server and proceeded to configure the official last.fm player to work through the proxy. Imagine my surprise when it didn’t work! Shocked I was. Shocked and surprised. And cursing.

After much ngrep-ing I came to the conclusion that the last.fm player was not implementing the SOCKS protocol but was just doing straight-forward proxy. A quick google search revealed that Qt has a proxy connection managment class called QNetworkProxy which meant all the work was done for me. I copy-and-pasted the code and it worked. Proud of my deductive skills, programming ability and boyish good looks I sent them an email with my patch, expecting some sort of answer.

A ‘kay cool would have done.

But not only did those bastards* not hire me, they also ignore my emails.

So here goes the patch. It’s against 1.3.1.1 though, but I think it should work just fine against 1.3.2.13 which is the one I originally fixed. (I downgraded because 1.3.2.13 wasn’t working correctly and because it wasn’t on SVN at the time)

svn co svn://svn.audioscrobbler.net/client/Audioscrobbler/tags/1.3.1.1 lastfm
cd lastfm
patch -p0 < /path/to/socks.patch
./configure
make && make install

The patch is hard coded to work with SOCKS 5, I haven’t tested it with anything else.

* but in a good way. I like them. Really, I do.


27
Nov 07

Cita XIII

A mi me encanta el queso… es lo mejor… pero le falta algo… que sea crujiente

Alex (compañero de piso) – mientras pone tres Pringles en un pedazo de queso


26
Nov 07

Como hacer un HEAD request en Python

Estuve el domingo unas cuantas horas buscando por internet como hacer esto y me estaba frustrando. Mi nuevo mini-proyecto secreto requiere monitorizar unas imágenes regularmente para ir actualizándolas a medida que van cambiando mediante un cron script que se ejecuta cada 15 minutos. Hay dos opciones:

  1. Bajarnos las imágenes todas las veces y comparar el md5sum para ver si han cambiado
  2. o hacer un pedido HEAD en vez de GET y hacer uso de las cabeceras Last-Modified y ETag.

¿Que cuales son las ventajas del punto dos? Lo más importante es que nos ahorramos ancho de banda nosotros y a los que le estemos bajando las imágenes, tampoco es cuestión de abusar del servidor de otra persona. Ojo que esto no aplica sólo a las imágenes, cualquier servidor moderno de hoy en día tiene soporte para estas cabeceras y las devolverá con cualquier tipo de archivo, incluso los que estén generados dinámicamente. Nos ahorramos ancho de banda porque sólo pedimos la cabecera del archivo que exceptuando casos extremos será mucho más pequeño que el resto del documento. Esto es especialmente útil para el contenido estático (js, imagenes, css, etc) y contenido que se baja regularmente como feeds RSS. Además de ahorrar ancho de banda también hacemos que el script vaya más rápido ya que no tiene que procesar todo el documento.

La idea es que hacemos un pedido HEAD inicial y guardamos el Last-Modified y ETag, luego en los subsiguientes pedidos enviamos pedidos GET con las cabeceras If-Modified-Since y If-None-Match. If-Modified-Since se usa con la fecha que guardamos anteriormente y If-None-Match con el ETag. Si ambos campos son los mismos en el archivo actual del lado del servidor entonces este debe responder con un ’304 Not Modified’

import StringIO
import pycurl

c = pycurl.Curl()
s = StringIO.StringIO()

c.setopt(pycurl.URL, 'http://theragingche.com/images/hand_made_cms.gif')
c.setopt(pycurl.HEADER, True) # estas dos lineas son las que importan
c.setopt(pycurl.NOBODY, True) # para hacer un pedido HEAD
c.setopt(pycurl.WRITEFUNCTION, s.write)

c.perform()
print s.getvalue()

Nos devuelve solo la cabecera:

$ python head.py
HTTP/1.1 200 OK
Date: Mon, 26 Nov 2007 12:29:50 GMT
Server: Apache/2.0.54 (Fedora)
Last-Modified: Thu, 16 Mar 2006 19:02:45 GMT
ETag: "303247c3-105-40f21566a7f40"
Accept-Ranges: bytes
Content-Length: 261
Connection: close
Content-Type: image/gif
X-Pad: avoid browser bug

Si luego hacemos:

import StringIO
import pycurl 

c = pycurl.Curl()
s = StringIO.StringIO()

c.setopt(pycurl.URL, 'http://theragingche.com/images/hand_made_cms.gif')

# especificamos las cabeceras
c.setopt(pycurl.HTTPHEADER,
    ['If-Modified-Since: Thu, 16 Mar 2006 19:02:45 GMT',
    'If-None-Match: "303247c3-105-40f21566a7f40"'])

c.setopt(pycurl.WRITEFUNCTION, s.write)
c.perform()

print c.getinfo(pycurl.RESPONSE_CODE)

Nos da:

$ python head.py
304

17
Nov 07

2 + 1 = 3

Hace unas semanas estaba ayudando a la compañera de piso instalar el eMule cuando me di cuenta de lo poco que pesaba su portátil. Esto me refresco la idea que tenía desde hace tiempo de comprarme un portátil verdaderamente portátil. La que tengo ahora, que es la que me lleve conmigo cuando me mudé a Inglaterra, es más una de esas portátiles de sobremesa y pesa 3.7kg. Me ha roto una mochila y casi me rompe la espalda en uno de los viajes que me hice con ella.

Por casualidad justo el fin de semana anterior había estado ayudando a un amigo mío a revender unos portátiles Dell y se me ocurrió la brillante idea de comprarle uno de los suyos. Así que por menos de 300€ me llevé un Dell Latitude C400. No es una portátil último modelo pero no necesito más para lo que la quiero: programar mientras viajo en Metro.

Lo primero fue quitarle el Windows XP con el que venía pre-instalado y reemplazarlo con Ubuntu 7.10. Como venía con una unidad de cdrom externa que se negaba a cargar el cd de Ubuntu tuve que hacer la instalación usando PXE y el netboot que viene en el cd. También aproveché la nueva utilidad del instalador alternativo y encripté todo el disco duro. Ya que voy a estar llevando la portátil por lugares muy públicos lo último que quiero es que alguien me la robe y tenga acceso a todos los servidores que uso y todas mis cuentas en las que estoy logeado permanentemente.

La portátil va sorpendentemente bien para tener un procesador un tanto antiguo (Pentium III Mobile @ 800mHz reales) y sólo 256MB de memoria RAM. Incluso venía con Compiz funcionando por defecto e iba bien, lo cual me sorprendió mucho. Deja un poco de desear la batería ya que es vieja y dura menos de una hora.

La estrené el viernes y me pasé los 25 minutos de viaje en Metro programando un script para tener un repositorio centralizado de documentos en mi servidor. Así que estoy muy feliz con la nueva compra y espero que me cunda.

En honor al disfraz que llevé este Halloween la llame ‘joker’.


12
Nov 07

Nuevo! Semicir.cl 1.1

Ahora con más FOAF, RSS 2.0, 11870.com y menos bugs en el proceso de registro. Lenta pero seguramente estoy volviendo a entrar en la dinámica de programar, asi que habrá más cambios pronto!


4
Nov 07

Wait… what?

I watched Primer last night and I had no fucking clue what was going on. It didn’t help that I watched it in spanish after getting it from eMule and the dubbing was not very good. I need to watch it again in English. From the wikipedia page there’s a link to the movie on Google Video, but the quality sucks. I might try to get both copies running and mute the spanish one.

The idea of the movie is two engineers accidentally discover how to time travel. Initially they using the machine to win money in the stock market, but as they start to realize how the machine lets them change different aspects of their life things start to get out of control.

What’s interesting about the movie is the way the time machines work. Without giving much away the basic concept is you have to already know you are going to want to timetravel back to some point in time at that same point in time. Unlike other time travel movies, you can’t just go back to whenever you want. Plus, you have to sit in the time machine for as long as you want to go back.

If you’ve already watched the movie here’s a few things that might help understand it:

Seriously, watch it.


1
Nov 07

Holly sweet flying monkeys!

Tim Berners-Lee me acaba de mandar un email. Jodido Tim yo-invente-la-www Berners-Lee.

Mail

Bueno, no me ha mandado un correo a mi. Lo ha mandado a la lista de correo de Social Network Portability y a la que yo estoy apuntado, pero da igual. Cuando vi que tenía un correo nuevo de parte de el… se me hizo el culo pepsicola como dicen por estos fueros.

Yo siempre digo que eso de idolatrar a los famosos es una chorrada, pero parece que yo solo soy una quinceañera enloquecida más.