Skip to content

Instantly share code, notes, and snippets.

View ptigas's full-sized avatar
🐙

Panagiotis Tigas ptigas

🐙
View GitHub Profile
@ptigas
ptigas / memento_fib.py
Created March 6, 2012 20:17
memento decorator applied on fibonacci
class Memento :
__mem__ = {}
def __init__(self, f) :
self.f = f
def __call__(self, arg) :
if arg not in self.__mem__ :
self.__mem__[arg] = self.f(arg)
return self.__mem__[arg]
@ptigas
ptigas / gist:2036981
Created March 14, 2012 14:48
bash animations
while true; do echo -n "◐\r"; sleep .1; echo -n "◓\r"; sleep .1; echo -n "◑\r"; sleep .1; echo -n "◒\r"; sleep .1; done
while true; do echo -n "◜\r"; sleep .1; echo -n "◠\r"; sleep .1; echo -n "◝\r"; sleep .1; echo -n "◞\r"; sleep .1; echo -n "◡\r"; sleep .1; echo -n "◟\r"; sleep .1; done
while true; do a=$a" "; echo -n "\r" $a "✈ "; sleep .1; done
while true; do a=$a" "; echo -n "\r" $a "\xcf\x80\xce\xbf\xcf\x8d\xcf\x84\xcf\x83\xce\xb1 "; sleep .1; done
@ptigas
ptigas / gist:2820165
Created May 28, 2012 17:21
linked list implementation in python
class Node :
def __init__( self, data ) :
self.data = data
self.next = None
self.prev = None
class LinkedList :
def __init__( self ) :
self.head = None
@ptigas
ptigas / gist:2829701
Created May 29, 2012 17:45
intersection algorithm in python
def intersection( *A ) :
res = []
while True :
# check if the heads are the same
all_same = True
for i in range(1, len(A)) :
if len(A[i]) > 0 and len(A[i-1]) > 0 and A[i-1][0] == A[i][0] :
pass
else :
all_same = False
@ptigas
ptigas / gist:2835530
Created May 30, 2012 11:04
change base of integer
'''
convert a number (given in string format) from a base f to base t
'''
import string
def convertbase( n, f, t ) :
digits = list(string.digits+string.uppercase)
rev_digits = {}
@ptigas
ptigas / latency.txt
Created May 31, 2012 13:14 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
@ptigas
ptigas / latex_escape.py
Created August 31, 2012 12:44
latex escape
# -*- encoding: utf-8 -*-
def latex_decode( s ) :
'''
A simple function which taks a latex escaping command
and returns the appropriate unicode character according
to this table (via wikipedia):
LaTeX command Sample Description
\`{o} ò grave accent
@ptigas
ptigas / gist:4052387
Created November 10, 2012 20:30
bootstrap django
Django==1.4
South==0.7.6
django-dbsettings==0.2
django-grappelli==2.3.8
pyechonest==4.2.21
simplejson==2.6.0
@ptigas
ptigas / gist:4155731
Created November 27, 2012 17:32
unifying python api response
import json
class API :
ERROR = -1
OK = 0
class APIResponse(API) :
def __init__(self, code, data) :
self.code = code
self.data = data
@ptigas
ptigas / message.html
Created January 28, 2013 20:37
the message behind the voice
<html>
<head>
</head>
<body>
</body>
</html>