Skip to content

Instantly share code, notes, and snippets.

View dionimf's full-sized avatar

Dioni dionimf

View GitHub Profile
import time, random
N = 1000000
NL = 1 #100000 10 1
origem = [random.randrange(N) for x in range(N)]
lista = list(origem)
t = time.time()
lista.sort(reverse=True)
print (time.time() - t)
def hack1(n, k):
def f(s):
return s.count('1')
binaries = []
for x in range(2**n):
binaries.append(bin(x))
binaries.sort(key=f, reverse = True)
return binaries[k - 1]
def hack(n, k):
import time
from functools import wraps
def tempo(func):
@wraps(func)
def wrapper(*args, **kwargs):
t1 = time.time()
result = func(*args, **kwargs)
t2 = time.time()
print(func.__name__, t2 - t1)
return result
@dionimf
dionimf / unicode.py
Last active August 29, 2015 14:06 — forked from fmasanori/unicode.py
a = 'Co\u00f1o!'
b = 'Con\u0303o!'
print (a, b, a == b, len(a), len(b))
print ()
import unicodedata
print ('Fully Composed')
a1 = unicodedata.normalize('NFC', a)
b1 = unicodedata.normalize('NFC', b)
print (a1, b1, a1 == b1, len(a1), len(b1))
@dionimf
dionimf / gamename.py
Last active August 29, 2015 14:06 — forked from fmasanori/gamename.py
import random
nomes = '''Júlia Sophia Isabella Manuela Giovanna Alice Laura
Luiza Beatriz Mariana Yasmin Gabriela Rafaela Isabelle Lara
Letícia Valentina Nicole Sarah Vitória Isadora Lívia Helena
Lorena Clara Larissa Emanuelly Heloisa Marina Melissa Gabrielly
Eduarda Rebeca Amanda Alícia Bianca Lavínia Fernanda Ester
Carolina Emily Cecília Pietra Milena Marcela Laís Natália
Maria Bruna Camila Luana Catarina Olivia Agatha Mirella
Sophie Stella Stefany Isabel Kamilly Elisa Luna Eloá Joana
Mariane Bárbara Juliana Rayssa Alana Caroline Brenda Evelyn
@dionimf
dionimf / clock.py
Last active August 29, 2015 14:06 — forked from fmasanori/clock.py
import tkinter
from time import strftime
#by Luciano Ramalho
clock = tkinter.Label()
clock.pack()
clock['font'] = 'Helvetica 120 bold'
clock['text'] = strftime('%H:%M:%S')
import bottle
#this is the handler for the root address on the web browser
@bottle.route('/')
def home_page():
return 'Hello Bottle World'
@bottle.route('/testpage')
def test_page():
return 'Testing page'
@dionimf
dionimf / fibcache.py
Last active August 29, 2015 14:06 — forked from fmasanori/fibcache.py
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
if n <= 2:
return 1
return fib(n-1) + fib(n-2)
@dionimf
dionimf / gmail.py
Last active August 29, 2015 14:06 — forked from fmasanori/gmail.py
import smtplib
usr = 'your_user@gmail.com'
pwd = 'your password'
dst = 'destination email'
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(usr, pwd)
import urllib
import json
url = 'http://api.icndb.com/jokes/random?limitTo=[nerdy]'
resp = urllib.urlopen(url).read()
data = json.loads(resp)
print (data['value']['joke'])