Skip to content

Instantly share code, notes, and snippets.

View timofurrer's full-sized avatar
Commits are my own. Powered by coffee.

Timo Furrer timofurrer

Commits are my own. Powered by coffee.
View GitHub Profile
@timofurrer
timofurrer / gist:2124450
Created March 19, 2012 19:07
Python packed arguments
def draw_point(x, y):
# do some magic
point_foo = (3, 4)
point_bar = {'y': 3, 'x': 2}
draw_point(*point_foo)
draw_point(**point_bar)
@timofurrer
timofurrer / gist:2119854
Created March 19, 2012 17:17
Python simple decorator example
#!/usr/bin/python
def decorator( fn ):
def wrapper( ):
print( "Befor the function is called" )
fn( )
print( "After the function is called" )
return wrapper
@timofurrer
timofurrer / gist:2118622
Created March 19, 2012 16:41
Python function returns another function
def getTalk(type="shout"):
# We define functions on the fly
def shout(word="yes"):
return word.capitalize()+"!"
def whisper(word="yes") :
return word.lower()+"...";
# Then we return one of them
@timofurrer
timofurrer / gist:2118548
Created March 19, 2012 16:39
Python functions are objects
def shout(word="yes"):
return word.capitalize()+"!"
print shout()
# outputs : 'Yes!'
# As an object, you can assign the function to a variable like any
# other object
scream = shout
@timofurrer
timofurrer / gist:1865658
Created February 19, 2012 20:41
Assambler code in intel flavor to print hello world 10 times in a for
00000000004004f4 <main>:
4004f4: 55 push rbp
4004f5: 48 89 e5 mov rbp,rsp
4004f8: 48 83 ec 10 sub rsp,0x10
4004fc: c7 45 fc 00 00 00 00 mov DWORD PTR [rbp-0x4],0x0
400503: eb 0e jmp 400513 <main+0x1f>
400505: bf 0c 06 40 00 mov edi,0x40060c
40050a: e8 e1 fe ff ff call 4003f0 <puts@plt>
40050f: 83 45 fc 01 add DWORD PTR [rbp-0x4],0x1
400513: 83 7d fc 09 cmp DWORD PTR [rbp-0x4],0x9