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: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
@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: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: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: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:2124946
Created March 19, 2012 19:18
Python permutations of a list
#!/usr/bin/python3.2
import itertools
print( list( itertools.permutations( [1, 2, 3, 4], 2) ) )
@timofurrer
timofurrer / asm.s
Created April 21, 2012 10:07
Minimal Assembly "Hello World"
.data
hello:
.string "Hallo, Welt!\n"
.text
.global _start
_start:
movl $4, %eax /* write() */
movl $1, %ebx /* 1 = stdout */
movl $hello, %ecx /* Adresse von hello */
@timofurrer
timofurrer / compile with g
Created May 5, 2012 11:50
range-based for loop in c++11
g++ -o for for.cpp -std=c++0x -Wall
@timofurrer
timofurrer / gist:2725779
Created May 18, 2012 15:11
C++ convert string to every type using template function
template <typename T>
T ConvertString( const std::string &data )
{
if( !data.empty( ))
{
T ret;
std::istringstream iss( data );
if( data.find( "0x" ) != std::string::npos )
{
iss >> std::hex >> ret;
@timofurrer
timofurrer / gcc call
Created June 4, 2012 12:29
make use of anonym union in struct in c
gcc -Wall -o union union.c