This file contains 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 threading import Thread | |
import random | |
import time | |
def random_wait(max_seconds, callback): | |
seconds = random.randrange(max_seconds) | |
time.sleep(seconds) | |
callback(seconds) | |
class Sketch(object): |
This file contains 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 datetime | |
class Pessoa(): | |
def __init__(self, nome, nascimento): | |
self.nome = nome | |
self.nascimento = nascimento | |
def idade(self): | |
delta = datetime.date.today() - self.nascimento | |
return int(delta.days/365) | |
def __str__( self ): | |
return '%s, %d anos' %(self.nome, self.idade()) |
This file contains 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
#Sorry, in April 30, 2015, with Facebook 2.0 API update only friends that use the app will be show | |
import urllib.request | |
import json | |
def save_image(friend): | |
size = '/picture?width=200&height=200' | |
url = 'https://graph.facebook.com/'+ friend['id'] + size | |
image = urllib.request.urlopen(url).read() | |
f = open(friend['name'] + '.jpg', 'wb') | |
f.write(image) |
This file contains 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 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
""" | |
Triangluation simulator. | |
Left mouse button: place a vertex. | |
Right mouse button: finalize a shape. | |
T: triangulate shapes. | |
""" | |
import math | |
from random import randint |
This file contains 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
# -*- coding: utf-8 -*- | |
#!/usr/bin/env python | |
import sys | |
class Polyomino(object): | |
def __init__(self, iterable): | |
self.squares = tuple(sorted(iterable)) | |
def __repr__(self): |
This file contains 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 sys, itertools | |
class Polyomino(tuple): | |
def __hash__(_):return(getattr(_,'',''))or[setattr(_,'',setattr(_,'_',map(min,zip( | |
*(setattr(_,'p',_.__class__((c[1],m-c[0]-1)for(c)in(_.p))if'p'in(_.__dict__)else(_)) | |
or(getattr(_,'p'))))))or(min(getattr(_,'',hash(tuple(sorted(setattr(_,'p',_.__class__( | |
[(x-_._[0],y-_._[1])for(x,y)in(_.p)])if(_._[0]or(_._[1]))else(_.p))or(_.p))))), | |
hash(tuple(sorted(_.p))))))for(m)in(itertools.repeat(max(max(_,key=max)),4))]and(getattr(_,'')) | |
def __eq__(*_):return(1&len(set(map(hash,_)))) | |
def __call__(_,__):return[_.__class__(((__,__),))]if(not(1%__))else(set(itertools.chain(*[set([_.__class__ | |
(_+tuple([a]))for(a)in(set((c[0]+x,c[1]+y)for(c,(x,y))in(itertools.product( |
This file contains 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
#include <cstdint> | |
#include <list> | |
#include <vector> | |
#include <algorithm> | |
// This code uses C++11 features like "auto" and initializer lists. | |
// Compare two floating point numbers accurately. | |
bool compf(float a, float b, float threshold=0.00001f) | |
{ |
This file contains 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 urllib.request | |
import json | |
url = 'http://educacao.dadosabertosbr.com/api/escola/' | |
codigo = '35141240' | |
resp = urllib.request.urlopen(url+codigo).read() | |
resp = json.loads(resp.decode('utf-8')) | |
print (resp['nome']) | |
print ('Salas:', resp['salasExistentes']) | |
print ('Computadores:', resp['computadores']+resp['computadoresAdm']+resp['computadoresAlunos']) | |
print ('Formação Docente:', resp['formacaoDocente']) |
This file contains 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 asyncio | |
import json | |
import aiohttp | |
SCHOOL_URL_FMT = 'http://educacao.dadosabertosbr.com/api/escola/{}' | |
SEARCH_SCHOOL_URL = ( | |
'http://educacao.dadosabertosbr.com/api/escolas/buscaavancada?' | |
'situacaoFuncionamento=1&energiaInexistente=on&aguaInexistente=on&' |
OlderNewer