Skip to content

Instantly share code, notes, and snippets.

@douglascamata
douglascamata / gist:2878100
Created June 5, 2012 21:23 — forked from bernardobarreto/gist:2877446
Sete Atitudes para Hackear a Indústria de Software
Sete Atitudes para Hackear a Indústria de Software
By Klaus Wuestefeld
1) Torne-se excelente.
Seja realmente bom em alguma coisa. Não fique só choramingando ou
querendo progredir às custas dos outros. Não pense q pq vc sentou 4
anos numa faculdade ouvindo um professor falar sobre software q vc
sabe alguma coisa. Jogador de futebol não aprende a jogar bola tendo
@andrewsmedina
andrewsmedina / gist:4128579
Created November 21, 2012 23:41
annotations
def hello(name: str, age: int) -> int:
print(name, age)
hello.__annotations__
from concurrent.futures import ProcessPoolExecutor
with ProcessPoolExecutor(max_workers=4) as executor:
future = executor.submit(pow, 323, 1235)
print(future.result())
@andrewsmedina
andrewsmedina / gist:4128588
Created November 21, 2012 23:44
futures2
from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor(max_workers=1) as executor:
future = executor.submit(pow, 323, 1235)
print(future.result())
@andrewsmedina
andrewsmedina / gist:4128516
Created November 21, 2012 23:23
custom context manager
import sys
from StringIO import StringIO
class redirect_stdout:
def __init__(self, target):
self.stdout = sys.stdout
self.target = target
def __enter__(self):
@andrewsmedina
andrewsmedina / gist:4128574
Created November 21, 2012 23:40
ordered dict
from collections import OrderedDict
d = OrderedDict()
d["ble"] = "bla"
d["bla"] = "x"
@andrewsmedina
andrewsmedina / gist:4128582
Created November 21, 2012 23:42
memoryview
a = b"Heelo World"
v = memoryview(a)
import io
f = io.FileIO("texto.txt", "w")
f.write("ble")
f.close()
@andrewsmedina
andrewsmedina / gist:4128591
Created November 21, 2012 23:45
lru_cache
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
@hltbra
hltbra / optimization.py
Created November 22, 2012 20:01
tail call optimization decorator
import sys
def tail_recursion_with_stack_inspection(g):
'''
Version of tail_recursion decorator using stack-frame inspection.
'''
loc_vars ={"in_loop":False,"cnt":0}
def result(*args, **kwd):
if not loc_vars["in_loop"]: