Default paramater values with python
2 Comments

Posted by Drakonen on September 26, 2008 in Uncategorized | Short Link

Default argument values for functions are a nice shortcut in python. They save you from writing many wrapper functions and make the code more readable and also easier to use. They can be used wrong though:

>>> def foo(a=[]):
...     a.append('bar')
...     return a
...
>>> foo()
['bar']
>>> foo()
['bar', 'bar']

Like described in idiomatic python, using a value which is a refenence (like a list, dict or instance) can lead to odd results. This is because the arguments are evaluated at compile time, not at runtime when the function is called! Instead of creating an empty list as one (inexperienced) would suspect, the default value becomes a reference to a list.

This can be nasty when it is used like this:

>>> def bar(time=datetime.now()):
...     print time
...
>>> bar()
2008-09-26 12:32:23.598052
>>> bar()
2008-09-26 12:32:23.598052

Just like in idiomatic Python, this is a good fix:

>>> def bar(time=None):
...     if time == None:
...             time = datetime.now()
...     print time
...

>>> bar()
2008-09-26 12:35:02.258992
>>> bar()
2008-09-26 12:35:03.059305

Instead of the default argument datetime.now(), using None, and later setting the current time instead of None works fine!

Removing the link boxes from Latex’ Hyperref (and color)
3 Comments

Posted by Drakonen on September 26, 2008 in Tech | Short Link

Aah Latex… A love hate relation ship. Working on my thesis I use the hyperref package for some nice linking support in my document. unfortunately this also causes them to get link boxes around them. Here’s the code to remove them:

\usepackage[pdftex]{hyperref}
\hypersetup{
    colorlinks,%
    citecolor=black,%
    filecolor=black,%
    linkcolor=black,%
    urlcolor=black
}

EDIT:
Hyperref seems to offer this feature by itself, by setting hidelinks. (Thanks yolila!)
http://www.tug.org/applications/hyperref/manual.html

This makes the links use colors inststead of boxes/frames, and sets the used colors to black. Fixed! Although this should be a standard convenience option imho.

Tags: , , , , ,

HAR inspired Python Pygame fun
5 Comments

Posted by Drakonen on September 9, 2008 in Programming, Python, Tech | Short Link

I have always wanted to do some stuff with Pygame. When i saw the logo on the HAR2009 wiki I whipped up a little python program that draws squares and fades between colors. It looks pretty cool!

Needed: Python, Pygame

Downloads: har_squares

[edit]Seems i have uploaded the wrong file… My apologies to the original writer. The right file is up now.[/edit]

Tags: , ,

Drakonen.com
No Comments

Posted by Drakonen on August 1, 2008 in Connectivity | Short Link

Finally i had the impulse to buy my own domain: drakonen.com. I ‘moved’ my blog to this domain which took a simple symlink. Making Nginx do a moved permanently redirect was a bit harder though, and caused quite some frustration. But here it is:

server {
server_name     drakonen.digigen.nl;
if ($http_host = 'drakonen.digigen.nl' ) {
rewrite  ^(.*)  http://drakonen.com$1  permanent;
}
}

This can maybe be optimized a bit, but it generates a 301 status and redirects.

Tags: , , , ,

Vim remap ex-mode key
No Comments

Posted by Drakonen on June 19, 2008 in Uncategorized | Short Link

I’ve become in the habit to miss shift-a in vim (edit at end of line), and instead pressing shift-q which brings you to the ex-mode. To get out of that, you need to type the command “visual“. Quite long and annoying.

Quick look at the help pointed me to the vimrc_example.vim (:help vimrc_example.vim). And this nifty remap:

map Q gq

Problem solved!

Having fun with IRC daemons
No Comments

Posted by Drakonen on May 28, 2008 in Uncategorized | Short Link

Sooo.. after a talk with my boss, I decided to implement one of the things he once did. An IRC server module which on connect gives you a random 3L1t3 hackers handle.

1245 -!- Code-dUde [] has joined #darkwired
1245 -!- fast-Fate [] has joined #darkwired
1245 -!- wet-chillA [] has joined #darkwired
1245 -!- Crash-mC [] has joined #darkwired
1245 -!- Crash-Hate [] has joined #darkwired
1245 -!- e-dieteR [] has joined #darkwired
1245 -!- Ghetto-dUde [] has joined #darkwired

m_conn_leethandle.cpp (.bz2 11KB) for download.
Installation

New IRC daemon
No Comments

Posted by Drakonen on May 28, 2008 in Uncategorized | Short Link

Today I switched the IRC Daemon on darkwired. From old unreal to the shiny new inspircd. Inspircd is pretty easy to configure although it is a pretty big config, it is quite easy to understand and it did not take long to get it up and running. Big plus on that one!

Ofcourse no first configuration is perfect and as soon as the membrane users joined in, we all got z-lined because we all came from the same host. Fixed that easily by searching on zline in the config file and came to the exception rules.

Inspircd is pretty cool stuff with its modular approach that can load and unload modules at runtime! Someone requested to have hostname masking, configured it, /rehash and tell him to do /mode nick +x. And we have a happy user!

Germans and my Name
No Comments

Posted by Drakonen on May 20, 2008 in Uncategorized | Short Link

Germans are used to Johann I guess… But alas, my name is still Johan without the second n.

Violation
1 Comment

Posted by Drakonen on May 7, 2008 in Uncategorized | Short Link

I am in violation of german law:

http://kismac.de/

My German phone number
No Comments

Posted by Drakonen on March 25, 2008 in Uncategorized | Short Link

Keeping up with the one post per month… I present:

My new German Mobile phone number!

  • 0049 17696209986

Still using my old P900 for this. My dutch number is out of service until I find a good phone for it. (switching Sim’s once in a while) using a way back old phone for my dutch one.

Copyright © 2005-2012 Draakwired All rights reserved.
The Shades theme, version 1.7, is a BuyNowShop.com creation.

Social links powered by Ecreative Internet Marketing