Skip to content

Instantly share code, notes, and snippets.

View fmasanori's full-sized avatar

Fernando Masanori fmasanori

View GitHub Profile
g = {}
g[1] = [2, 3, 5]
g[2] = [1, 6, 4]
g[3] = [1, 4, 7]
g[4] = [2, 3, 8]
g[5] = [1, 6, 7]
g[6] = [2, 5, 8]
g[7] = [3, 5, 8]
g[8] = [4, 6, 7]
removidos = [True] + 8 * [False]
@fmasanori
fmasanori / JS Chess
Last active August 29, 2015 14:04
JS Chess
#@gwidion code
print"".join(u"\x1b[%dm%c%s"%((42+y%2^y>>3&1),((1,3,2,-1,0,2,3,1)+(4,)*8+32*(-9781,)+8*(10,)+(7,9,8,5,6,8,9,7))[y]+9813,(y+1)%8and" "or" \x1b[48m\n")for y in range(64))
@fmasanori
fmasanori / mergesort.py
Last active August 29, 2015 14:05
mergesort
def merge(e, d):
r = []
i, j = 0, 0
while i < len(e) and j < len(d):
if e[i] <= d[j]:
r.append(e[i])
i += 1
else:
r.append(d[j])
j += 1
@fmasanori
fmasanori / mergesortI.py
Created September 3, 2014 13:57
Python Interactive Mergesort
def merge(p, q, r, v):
w = []
i, j = p, q
while i < q and j < r:
if v[i] <= v[j]:
w.append(v[i])
i += 1
else:
w.append(v[j])
j += 1
@fmasanori
fmasanori / Copa2014.py
Last active August 29, 2015 14:23
Gastos da Copa 2014
#The context of this program is a course of an hour to journalists who know nothing about programming in a lab with Python 3 only.
import urllib.request
url = 'http://www.portaltransparencia.gov.br/copa2014/api/rest/empreendimento'
resp = urllib.request.urlopen(url).read().decode('utf-8')
total = 0
j = 0
and1 = '<andamento>'
and2 = '</andamento>'
abre = '<valorTotalPrevisto>'
fecha = '</valorTotalPrevisto>'
@fmasanori
fmasanori / pi.py
Last active October 11, 2015 10:52
pi_generator
#Pi Generator ref https://mail.python.org/pipermail/edu-sig/2015-September/011317.html
def pi_digits():
k, a, b, a1, b1 = 2, 4, 1, 12, 4
while True:
p, q, k = k*k, 2*k+1, k+1
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
d, d1 = a//b, a1//b1
while d == d1:
yield int(d)
a, a1 = 10*(a%b), 10*(a1%b1)
@fmasanori
fmasanori / gist:4120037
Last active October 13, 2015 01:47
Python Twitter Client
#
# API DEPRECATED AT JUNE 2013
# https://dev.twitter.com/docs/faq#17750
#
import urllib, json
def busca_tweets(texto='python'):
url = 'http://search.twitter.com/search.json?q=' + texto
resp = urllib.urlopen(url).read()
data = json.loads(resp)
@fmasanori
fmasanori / gist:4121001
Last active October 13, 2015 01:57
Python Twitter Trending Topics
#
# API DEPRECATED AT JUNE 2013
# https://dev.twitter.com/docs/faq#17750
#
import urllib, json
def trend_topics():
url = 'https://api.twitter.com/1/trends/1.json'
resp = urllib.urlopen(url).read()
@fmasanori
fmasanori / gist:4121690
Created November 20, 2012 22:28
Python Graph Facebook basic
import urllib
import json
url = 'https://graph.facebook.com/19292868552'
resp = urllib.urlopen(url).read()
data = json.loads(resp)
url_logo = data['cover']['source']
imagem = urllib.urlopen(url_logo).read()
@fmasanori
fmasanori / gist:4124876
Created November 21, 2012 13:40
Facebook Download Friends Photos
import urllib
import json
def grava_imagem(amigo):
url = 'https://graph.facebook.com/' + amigo['id'] + '/picture?type=large'
figura = urllib.urlopen(url).read()
f = open (amigo['name'] + '.jpg', 'wb')
f.write (figura)
f.close()