Archive for 2009

jQuery ui datepicker + jQuery editInPlace

Thursday, September 17th, 2009

The goal of this post is to show how editInPlace plugin for jQuery can be used with the ui.jQuery.datepicker. Jacob Terry already made this very good but modifying Dave Hauenstein’s editInPlace plugin.

Before show you the snippet here is the key: Use two elements, one for each widget, the datepicker hidden but with the icon option, and to trigger click & blur events for the other in the onClose callback function of the datepicker.

There’s still an important (but I think not hard) TODO: Update the datepicker value when the editInPlace widget is edited by hand. Anyone can contribute?

Consumo de ADSL por mail - ANTELDATA

Monday, August 17th, 2009

cuentagigas.info es una interfaz simple para un bot(programa) que hace tiempo quería hacer para estar al tanto de cuántos gigas voy gastando en el adsl sin tener que estar entrando al sitio de anteldata, … si quieren probarlo:

cuentagigas.info

Detalles técnicos:

  • El robot actualmente revisa el consumo 2 veces por día y decide si hay que enviar o no una notificación a cada cuenta. Está hecho en Python, es un Scrapy-spider bastante simple. Si alguien quiere ver el código lo puedo publicar.
  • La interfaz es un Django-site también bastante simple.
  • Permite dar de alta varios emails, útil cuando varias personas usan el mismo adsl. También permite cancelar el envío de notificaciones o cambiar los datos asociados. Se irá mejorando en base al feedback recibido.
  • Funciona con usuarios de adsl y adsl móvil.

Gracias.

JSP mysql tomcat5.5 debian: forbidden by default

Monday, August 10th, 2009

If you are getting this error while trying to connect to mysql from JSP in debian:

java.net.SocketPermission 127.0.0.1:3306 connect,resolve

Then you should allow the connection in tomcat policy, add this line:

java.net.SocketPermission 127.0.0.1:3306 connect,resolve” to the “grant{” block in the file “/etc/tomcat5.5/policy.d/04webapps.policy

source: http://www.linuxquestions.org/questions/programming-9/jspjava-mysql-connection-fails-218903/

trac-accountmanager in debian

Friday, August 7th, 2009

This advice is probably too late for you but: Don’t install the package trac-accountmanager in debian, seems broken. Install the plugin directly with “sudo easy-install …” as described in track-hacks.org
Corolary: why I’m using ArchLinux? Speed. And also because I have about an 80% less packages installed by hand. Also I can contrib easily with new packages in AUR.

JSP Hello World Howto

Thursday, August 6th, 2009

This can be called a howto of “How can I make a hello world in JSP without unnecessary tools like, Eclipse, struts, servlets, JBoss, etc.?” only you, your text editor, tomcat and of course, your GNU-Linux box.

1. Create a directory anywhere to store your app, let’s create one called “myapp”: mkdir myapp

2. Create your hello.jsp web page: echo ‘<% String hello=”Hello World”; %><%=hello%>’ > myapp/hello.jsp

3. Create your app’s web.xml file, you should have this file under (create it) the WEB-INF directory, under “myapp”:

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
version=”2.4″>
<display-name>Hello World</display-name>
<description>My hello world app.</description>
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
</web-app>

4. Install tomcat, for example, in Arch I’ve typed: sudo pacman -Sy tomcat

5. Make your app. available: sudo ln -s /path/to/myapp /opt/tomcat/webapps

6. Start tomcat, for example, in arch I’ve typed: sudo /etc/rc.d/tomcat start

7. Point your browser to: localhost:8080/myapp

Python: using a module written in C

Tuesday, June 9th, 2009

This is a brief tutorial for using a module written in C inside a Python program. It’s a summarized recipe fr those who want to run and test something fast without falling in reading the docs, but I recommend to read.

[1] http://docs.python.org/extending/extending.html
[2] http://docs.python.org/extending/building.html

Let’s write a module called spam, the same as the example in [1], our spammodule.c will look like this:

#include 
static PyObject *SpamError;
static PyObject *
spam_system(PyObject *self, PyObject *args){
    const char *command;
    int sts;
    if (!PyArg_ParseTuple(args, “s”, &command))
        return NULL;
    sts = system(command);
    return Py_BuildValue(”i”, sts);
}
static PyMethodDef SpamMethods[] = {
    {”system”,  spam_system, METH_VARARGS,
     “Execute a shell command.”},
    {NULL, NULL, 0, NULL}        /* Sentinel */
};
PyMODINIT_FUNC
initspam(void){
    PyObject *m;
    m = Py_InitModule(”spam”, SpamMethods);
    if (m == NULL)
        return;
    SpamError = PyErr_NewException(”spam.error”, NULL, NULL);
    Py_INCREF(SpamError);
    PyModule_AddObject(m, “error”, SpamError);
}

Ok, now, rather than compiling it by hand, let’s use an automated mechanism: distutils [2]. Edit a setup.py file which will be the “driver” for compile and make yur module in C importable from Python.

from distutils.core import setup, Extension
module1 = Extension('spam', sources = ['spammodule.c'])
setup(name = ‘PackageName’, version = ‘1.0′, description = ‘This is a demo package’,
          ext_modules = [module1])

Compile the C module using the driver: $ python setup.py build
An example of the output I get:

running build
running build_ext
building 'spam' extension
creating build
creating build/temp.linux-x86_64-2.6
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c spammodule.c -o build/temp.linux-x86_64-2.6/spammodule.o
creating build/lib.linux-x86_64-2.6
gcc -pthread -shared build/temp.linux-x86_64-2.6/spammodule.o -L/usr/lib -lpython2.6 -o build/lib.linux-x86_64-2.6/spam.so

Test it!, depending on your platform and settings you’ll get a directory tree created, I’ll cd into mine:

$ cd build/lib.linux-x86_64-2.6
$ python
>>> import spam
>>> spam.system('echo "hello world"')
hello world
0
>>>

re-quemado

Monday, June 1st, 2009

Peñarol presentará hoy ante la AUF una propuesta para que la liguilla “la jueguen todos”: que los 6 primeros clasifiquen al campeonato uruguayo y los demás a las copas

Estaría todo pronto para que en las próximas horas la dirigencia de peñarol presente ante la AUF una propuesta innovadora para el fútbol profesional uruguayo, jugar primero la liguilla y que la misma clasifique al uruguayo y los que no lleguen, vayan a las copas. “Nos parece lógico, esto está muy quieto, hay que modificar el reglamento nuevamente, ya hace casi un año que está igual!”, declaró el presidente de peñarol el sr. Damianchi en diálogo con la prensa deportiva, “tenemos que ajustarnos, en todo el mundo se está ideando algo parecido. Así podemos optar por dedicarnos a una o a otra cosa, por ejemplo, ahora estaríamos en zona de Copa Libertadores. El año que viene entramos al uruguayo y así…”.  -Pero usted ha tenido apoyo del resto de la dirigencia del club?. -”Que si he tenido apoyo? pero por favor pibe” -Pero no cree que esto perjudica a algunos equipos? -”Peñarol es peñarol” En definitiva no se pudieron obtener argumentos sólidos en favor de la propuesta, lo cual indica que la misma tiene firmes chances de ser adoptada por la AUF.

Penca de la copa libertadores 2009

Friday, March 6th, 2009

Amigos, se largó la penca de la libertadores, en predgame.com

La idea es la de siempre, divertirnos entre amigos jugando un poco. Por que un dominio nuevo? bueno, la idea es que el sitio vaya creciendo, por ahora se está desarrollando de a poco, en los ratos libres :) pero la idea es seguirlo. Django y Pinax han ayudado mucho a la rápida puesta en producción del sitio pero lógicamente se necesitan ajustes. Tenemos muchas ideas desde hace tiempo para esto con varios amigos, el sitio esta listo para jugar pero le faltan muchas features muy necesarias que iran saliendo de a poco, por ejemplo:

  • Aviso de falta de pronosticos por email
  • Scraping de partidos y resultados usando scrapy
  • Autenticacion segura
  • Multipenca support
  • Mas idiomas en la i18n
  • Muchas mejoras en la gui
  • Conseguir sponsor para que hayan premios :)

saludos !!

Playing with python-rpy2

Thursday, February 26th, 2009

The goal was to prepare a little prototype to show the potential of R (r-cran) when used via its Python bridge python-rpy2, then show the results in a web application, for example, using django.

In this example (in spanish) we take a CSV database and use R to present some calculations. The code of the example is published here, you can browse it, download or even clone using mercurial.

Thanks to Martin Sanguinetti who have motivated me and told me the R basics to make this example.

An example plot using python-rpy2

[A classical example plot using python-rpy2]

Python2.6 with mod_python in debian

Thursday, January 15th, 2009

As you may know, there are no packages yet for Python2.6 in debian or ubuntu. If you want to install it you can do it by hand and it will work perfectly (it did for me)

Google a bit and you will find this post: http://blog.pythonaro.com/2008/10/horrible-hack-to-get-python-26-on.html

You can follow the steps in the post without problem, then remember to update your supported and default versions under /usr/share/pyhton/debian_defaults

Also you can link modules available in 2.5 to be used by 2.6, for example Ipython, it works perfectly. Do symlinks from python2.6/site_packages/ pointing python2.5/site_packages. Although this is not the correct way, the correct way should be reinstall those modules under your new configuration.

But what about mod_python? it still remains to Python2.5 right? YES

Well, you have to do the same, download it from modpython.org and make and make install, be sure to install apache2-dev it will provide you with a tool needed in the compilation time.

All should work, also django is working perfectly in my new Python & mod_python 2.6 conf. under debian.

cheers!