Monthly Archives: November, 2008
Injecting javascript with Firebug
Sometimes you may want to include a Javascript file on a live web page to see how things will work or to try new things. Usually you would do this by editing the source code including the new file but there is a fastest way if you have Firefox with Firebug. Just run the following [...]
Setting up a development environment
I want to left behind the days when I was developing code without any version control system. I have been using these at work for years now, but never for my personal projects. So know I use/have two SVN repositories: enekoalonso.com/svn for my personal projects and tests. code.google.com/u/eneko.alonso/ for more complex projects in which other [...]
JS.Class: a very nice object oriented approach
I have been using jQuery and Mootools in the last few months at work, among other libraries. So far, jQuery was my favorite because it is very fast and encapsulated (it doesn’t interfere with other librearies, etc). But I love Mootools too because of its object oriented approach and beautiful things like the Class class [...]
Making your objects sortable
Making your objects sortable in Python is very simple: add the __cmp__ function and the logic to compare the two objects and you are done! class person: def __init__(self, name, age): self.name = name self.age = age def __str__(self): return 'Person %s (%d)' % (self.name, self.age) [...]
MyGameOfLife source code
Almost a year ago I was learning some Cocoa and I decided it will be fun to implement a Cocoa based version of Conway’s Game of Life. Back then I didn’t publish the source code, not for any special reason. So now I have just uploaded it to Google Code. It’s not fully functional, since [...]
Unnecessary function calls inside loops
Calling to functions that return the same value over and over to test the exit condition on a loop is a very novel error or mistake, but I have seen it multiple times in different programming languages. At the end, the problem is the programmer relying on the compiler optimization, which I think is a [...]
Copy-constructor test in Javascript
After posting about assigning objects in Python only copies the reference and does not clone the object, I wanted to verify if the behavior happened in Javascript. Here is the code: var myClass = function() { this.text = ''; this.say = function() { console.log(this.text); } } var A = new [...]
Copying objects vs. copying references
C++ is a language that allows creation of static instances of objects, this is without using pointers. This is why copy-constructors are needed, since it is common to copy or clone objects. Other languages like Delphi don’t allow to create static variables to instantiate objects. Instead, all objects are pointers. So in C++, assignments of [...]
Fibonacci
Fibonacci is a fast growing sequence that can easily overflow your integer variables. Fortunately, Python doesn’t have this problem, since it can handle huge integer numbers. #!/usr/bin/env python def fib(n): if n==0 or n==1: ret = n else: ret = fib(n-1) + fib(n-2) return ret for i [...]
Presentation
dev.enekoalonso.com is a new blog where I plan to publish my notes, code, tests, exercises and studies in Javascript & Python among other languages.