Posts in English

Emacs' 24 python.el now supports ipython

My first contribution to Emacs :)

2010 August 25 0 comments

A patch I have sent a long time ago was reworked by Chong Ydong and hit the Emacs trunk and now GNU/Emacs' python.el supports ipython!

I'm really happy with it because:

  1. This was making me to choose python-mode.el.
  2. It is my first contribution to Emacs (I hope to be more active soon :)

At the moment I'm using an own python.el I created almost from scratch with some code from Emacs original python.el. I hope to get it stable very soon and perphaps have it approved to the Emacs trunk in some future.

Tags: emacs , ipython , python Categories: English , Free Software , Programing , Python

closures

A little introduction to shortcuts.

2010 May 19 0 comments

I will take some minutes to post about closures before starting to work :)

What are closures?

Closures are a pretty neat feature you can find in languages like Scheme, Lisp, Ruby, JavaScript and Python (among others).

Closures can many times increase your code readability and cleverness. You'll find examples of use the codes samples below.

To understand what a closure is you need to understand the following concepts:

  • first-class objects: objects that can be stored in a variable, passed as argument and/or returned by a function.
  • first-class functions: if all the characteristics of the first-class objects apply to a function then it's called first-class function. This is a particularity of the programming language itself and is not up to the programmer to set this. If you come from Java, C, PHP you'll probably find some enlightment regarding closures in this article since in those languages functions are not first-class objects (c'mon don't come up with crazy pointer stuff).
  • free variable: is a variable that can be accessed from a function but this variable is not an argument or a local variable of that function.
  • lexical binding: all variables are contained in their respective environment (code block) instead of being available globally (dynamic binding).

With the definitions above, then we can define a closure as:

A lexical binded first class function which can access free variables.

I know that line probably didn't helped that much. So let's go to the...

Code examples

The most common example for a closure seems to be a counter, so lets do it with Python:

def counter(start):
# we are setting the variable start as a counter function property
# because if we don't do that `start` will be placed in the local
# scope of incr after incrementing its value.
counter.start = start
def incr():
counter.start += 1
return counter.start
return incr

# this binds the closure function incr to the c variable so we can
# call it later. Of course, before that, this will also set the
# counter.start variable to 10 but nothing else will happen as desired
c = counter(10)

print c() # will print 11
print c() # will print 12
print c() # will print 13

Here is a better real life example in JavaScript.

Let's say we want to print out the order of the links contained in a list when they are clicked (yes, I'm using jQuery in the example ;).

The first thing you'd probably try is:

var links = $('li a'); // gets all <a> elements contained in a <li>

for(var index=0; index < links.length; index++) {
// $() extends the element so the click function is available.
// $().click() allows us to bind the onClick event.
$(links[index]).click(function(event) {
alert(index);
return false
});
}

This will fail! After you click an element it will print the value of index, but its value will be the latest it got in the for loop. In this case, we have a closure (the index variable is accessed via lexical binding) but is not working as expected.

The solution for this would be rebinding each value of index in an inner lexical scope and then add the closure inside that scope. This way, the closure will be looking to that inner value of index instead of the latest state of the for loop.

var links = $('li a');

var closure = function(i) {
return function(event) {
alert(i);
}
}

for(var i=0; i < links.length; i++) {
event_handler = closure(i);
$(links[i]).click(event_handler);
}

And there we go! Now it's working as we wished. However that was just for the sake of a detailed example. The best way of doing it with jQuery will be using each like this:

var links = $('li a');

links.each(function(index) {
$(this).click(function(event) {
alert(index);
return false
});
})

Which remains on-topic because the index is accessed by the click event handler thanks to lexical binding.

Conclusions

Closures are a great language feature, they can be used for many purposes (even for a kind of poor man's object oriented programming). I'd recommend you to play with them a little to understand them better.

 

Tags: closures , patterns Categories: English , Javascript , Programing , Python

Going to Chile

On my way to las Jornadas Regionales de Software Libre in Chile

2009 October 04 0 comments

Because of the Regional Free Software Conference I'm travelling to Chile with Seba who will give a presentation about the LUGRo-Mesh Project.

I did my homework and watched Turbulence 1 and 2, and other airplane crash movies, I promess to bring pisco for everyone if we survive the four travels we need to make, yes they are four becase the airplane makes a stop in... Montevideo (as good Nerds we decided to increment our posibilities of being in an Airplane Crash than paying more :P)

See you all.

Tags: Categories: English , Free Software

1,5 minutes of fame

A little interview about the Software Freedom Day event in Rosario organized by LUGRo

2009 September 27 0 comments

Because of the Software Freedom Day Rosario 2009, I did a TV interview on a local channel. Now I'm shaved so take that into account when looking at me for an autograph :P

 

Tags: lugro , sfd Categories: English , Free Software

Software Freedom Day is coming

Software Freedom Day takes place in Rosario too!

2009 September 08 0 comments

This saturday 19th is the Software Freedom Day which is a worldwide event aimed to celebrate the public benefit of the use of Free Software.

The past year 500 teams have registered to celebrate in their respective cities, and this year (as always) the GNU/Linux User Group Rosario (LUGRo) will take charge of the event in my city.

This time the SFD of Rosario will be done at PlanetaX (Montevideo 2348) starting at 11 am. The schedule is not yet defined but my talk about Python (introduction) is confirmed :).

If you are around Rosario (Santa Fe, Argetina), I invite you to come around, the event will rock.

Tags: lugro , sfd Categories: English , Free Software

Back from PyCon Argentina

Excellent, that's the word to describe PyCon Argentina 2009

2009 September 07 2 comments

I don't have the words to describe how well organized the event was, how good talks were and how much fun I had these two days at the PyCon Argentina 2009.

On friday I had the chance to see these great talks:

  • Python as a hacking language
  • Byte twiddling
  • Do the electric serpents dream?
  • Extending PostgreSQL with PlPython
  • Hacking Django

The end of the day was the keynote given by Jacob Kaplan-Moss titled "The State of Django", as you might know Jacob is one of the creators of Django.

Aversely from what the title says, the talk was not really related to Django itself but he talked about the current state of Web Development techonologies, HTML5, the problem of concurrency in Python and what we should do to make python the language of the Web on the 2020. A really perfect keynote.

On saturday I started the day with:

  • PyQT, wxPython, PyGTK
  • from wiimote import fun
  • Python 3000
  • Twisted for human beings
  • Python development with buildout and virtualenv

This time the end of the day was on charge of Collin Winter, who works for Google and who is one of the guys working on a project called unladen-swallow, which is a CPython implementation which has as main objective to be completely compatible with CPython and (at least) run 5 times faster.

This presentation has blown our minds off. He talked about how this speed increase could be achieved, what's the status of the project and which are the future plans.

I really hope this project continues doing well so we can see this project merged with the CPython 2.x upstream in a no too far future.

Closing thoughts, you should notice the conference was really great, I have to say that even the lightning talks were excelent!

A weekend to remember, I take this oportunity to give thanks to all the colaborators, they did an outstanding job to make this conference the nice it was.

See you next year in Córdoba ;)

Tags: pyar , pycon , python Categories: English , Python

On the road to PyCon Argentina 2009

Yes, that's right, a PyCon in Argentina!

2009 September 03 0 comments

Tomorrow starts PyCon, the most important event for the Python community in the University of Belgrano in Buenos Aires (Argentina).

I already have the bus tickets and I'll be traveling at dawn together with some friends and colleagues to arrive just an hour before the beginning of the event.

Among others important guys from the community, will be Jacob Kaplan-Moss, one of the creators of Django, so if you have time and you are able to reach the conference I really recommend you to come.

Tags: pyar , pycon , python Categories: English , Python

Sansa, USB, Linux and Rockbox 3.3

Getting your Sansa player to work again when plugin it in to your computer

2009 September 01 2 comments

I'm a happy owner of a Sansa e280 mp3 player, this player is able to run the amazing Rockbox firmware of whom I will talk in another post sometime.

The thing is that since Rockbox 3.3 the USB stack for Sansa players is supported and now the player doesn't need to restart with the original firmware to mount the player on your filesystem. However this was not working for me, I was forced to boot the original firmware and then plug the usb cable to be able to change my song collection.

Fortunately I found the solution at the Rockbox site, the issue was caused by a bug on libgphoto and GNU/Linux systems with this library were having the same problem.

The fix is really simple you will only need to remove/comment all XML groups which have the word Sansa contained in the file /usr/share/hal/fdi/information/20thirdparty/10-camera-libgphoto2.fdi

For the sake of simplicity I attached the file so you can just replace your own with mine.

Note: As the Rockbox wiki says this solution is applicable to Gigabeat players too, however my file is not patched for those.

Tags: linux , rockbox Categories: English