Skip to content

Instantly share code, notes, and snippets.

View villares's full-sized avatar
💥

Alexandre B A Villares villares

💥
View GitHub Profile
@aparrish
aparrish / simplethread.py
Created May 1, 2011 14:45
simple threading example with processing.py
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):
@fmasanori
fmasanori / oop.py
Created January 30, 2013 12:43
OOP basic
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())
@fmasanori
fmasanori / Facebook Friends Photos Python 3x.py
Last active September 3, 2022 13:28
Python 3.x Facebook Friends Photos
#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)
@fmasanori
fmasanori / clock.py
Last active June 28, 2017 19:19
Clock GUI
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')
@Shaptic
Shaptic / Triangulate.py
Last active June 14, 2023 23:31
Fokin' triangulation.
"""
Triangluation simulator.
Left mouse button: place a vertex.
Right mouse button: finalize a shape.
T: triangulate shapes.
"""
import math
from random import randint
@hamishcampbell
hamishcampbell / polyomino.py
Created September 6, 2013 23:26
Polyomino Reference Source - PyCon 2013
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import sys
class Polyomino(object):
def __init__(self, iterable):
self.squares = tuple(sorted(iterable))
def __repr__(self):
@hamishcampbell
hamishcampbell / polyomino-obfus.py
Created September 7, 2013 01:35
Highly readable Polyomino solution
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(
@Shaptic
Shaptic / Triangulate.cpp
Last active July 11, 2021 19:32
Fokin' triangulation in C++.
#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)
{
@fmasanori
fmasanori / QEduDetalhe.py
Last active June 13, 2017 12:54
QEdu Busca alguns detalhes pelo código da escola
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'])
@drgarcia1986
drgarcia1986 / schools_async.py
Created June 29, 2015 21:59
Escolas, em funcionamento, sem água, energia e esgoto, mostrando alguns detalhes (versão asyncio) (baseado em https://gist.github.com/fmasanori/4d6b7ea38a28681a513a)
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&'