Skip to content

Instantly share code, notes, and snippets.

View diofeher's full-sized avatar
🎯
Focusing

Diógenes Fernandes diofeher

🎯
Focusing
View GitHub Profile
class Memoization(object):
def __init__(self, func):
self.func = func
self.data = {}
def __call__(self, n, **kwargs):
if n in self.data:
return self.data[n]
self.data[n] = self.func(n)
"""Look for builtins..."""
import types
def is_builtins(v):
"""Does v seem to be the builtins?"""
if hasattr(v, "open") and hasattr(v, "__import__"):
return True
if isinstance(v, dict):
return "open" in v and "__import__" in v
import re
from base64 import b64decode
import pprint
story1 = '''
It's somewhat dark in here, but the walls (unbroken except for the door by
which I entered) encircle an area no more than eight feet in diameter.
It's horribly dank and dusty--no one can have been in here for years.
Is that an open envelope over there on the floor?
It seems there is a letter inside. Thank heavens it's in English.
@diofeher
diofeher / txt.py
Created April 24, 2012 15:28
--nerd happy birthday
import binascii
txt = [int(t,2) for t in '01001000 01100001 01110000 01110000 01111001 00100000 01000010 01101001 01110010 01110100 01101000 01100100 01100001 01111001'.split()]
print ''.join([binascii.unhexlify('%x' % c) for c in txt])
@diofeher
diofeher / count_lines.sh
Created October 8, 2011 23:33
Count lines of directory
#!/bin/bash
num=0
for arq in ` find . -type f -name "*.html" -o -name "*.css" -o -name "*.conf" -o -name "*.js" -o -name "*.xml" -o -name "*.txt" -o -name "*.py"`
do
tmp=`wc -l $arq | awk '{print $1}'`
num=`expr $num + $tmp`
done
echo Total: $num
@diofeher
diofeher / leet.py
Created July 5, 2011 05:27
leet translator hehe
#coding:utf-8
from string import maketrans
class Leet(object):
def __init__(self):
self.intab = u"013457"
self.outab = u"oleast"
def encrypter(self, text):
@diofeher
diofeher / cc_validation.py
Created July 5, 2011 04:58
cc_validation
def sum_digits(num):
"""
@param: num number as string
"""
return sum([int(digit) for digit in num])
def validate(cc_number):
"""
@param: cc_number credit card number as string
"""
#coding:utf-8
class Desktop(object):
"""
Computador novinho, ainda está todo embalado.
"""
def __init__(self, preco):
self.preco = preco or 'a combinar'
self.monitor = 'Monitor AOC Widescreen 19'' 912Vwa'
self.cpu = 'Daten'
self.extras = {'mouse':True, 'mousepad': True, 'teclado': True}