This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.request import Request, urlopen | |
import json | |
req = Request( | |
url='https://api.chucknorris.io/jokes/random', | |
headers={'User-Agent': 'Mozilla/5.0'} | |
) | |
resp = urlopen(req).read() | |
data = json.loads(resp.decode('utf-8')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
usr = '[email protected]' | |
pwd = 'your password' | |
dst = 'destination email' | |
server = smtplib.SMTP('smtp.gmail.com:587') | |
server.starttls() | |
server.login(usr, pwd) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import lru_cache | |
@lru_cache(maxsize=None) | |
def fib(n): | |
if n <= 2: | |
return 1 | |
return fib(n-1) + fib(n-2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |