Archive for January, 2006

Fun with python

Friday, January 20th, 2006

Fun python snippets

Here is a short list of python WTF’s i often come across in my own code, debugging
those is quite hard..

Tuples are immutable ?

a = ([],[])

try:
# Modifying a tuple ?
a[0] += [1]
except:
pass

print a

Weird list references:

a = [[None]*4]*3
a[0][0] = 1

print a

Import madness:

* in mod1.py:
FOO=1

* in mod2.py:
import mod1
def set_foo(i):
mod1.FOO = i

* in mod3.py:
from mod1 import *
import mod2
mod2.set_foo(2)
print FOO

Run "python mod3.py"

Weird variable scoping:

* in mod1.py:
a = 3
def foo():
return a

if __name__ == "__main__":
for a in range(3):
print foo()

* in mod2.py
from mod1 import *
a = 6
print foo()

Compare "python mod1.py" and "python mod2.py"

Of course these snippets are a bit convoluted, but I often find these patterns appearing randomly..

How much of them have you got right without looking at the answer before?

Stock Trading, yay !

Wednesday, January 18th, 2006

On stock trading

Stock trading is fun.. well, when you make money of course. There are days when you wish you didn’t buy that crappy stock, today it’s intel.
They released apparently bad numbers yesterday and took the plunge:


Uh oh !

Invest Applet

This leads me to the introduction of Invest, a replacement/companion for gtik, the stock ticker currently in gnome applets.

Logo
Feel the Tango love

It allows one to create a portfolio, and track its progress in terms of gain/losses.
It also features a yahoo graph viewer, with the options found on their website, very nerdy !

Screenshots

In the panel
The panel applet, with the overview dropdown
Charts
The Yahoo! chart viewer, with 1337 options
Portfolio
The portfolio editor, note the particularly bad taste of mine..

Code

This is the first release, nothing official yet, but i know there are people who like these things.
I have discussed with Christopher Aillon and he gave me really nice ideas for future developpment.

Maybe this can be integrated in gnome 2.16, if I receive positive feedback 🙂

Download the invest-applet-0.1.0.tar.gz tarball !

Contribute !

I welcome any patch/comment/suggestions. The future applet will have a color indicator instead of numbers in the pane, to take les space and be less anti-private, in case someone is looking over your shoulder. Further improvements also include gconf usage and maybe general applet polishing.