Skip to content

Instantly share code, notes, and snippets.

View ramalho's full-sized avatar
🏠
Working from home

Luciano Ramalho ramalho

🏠
Working from home
View GitHub Profile
# coding: utf-8
'''
Uma carta tem atributos valor e naipe::
>>> c = Carta('A','ouros')
>>> c
<A de ouros>
Dado um baralho... ::
@ramalho
ramalho / picirc.py
Created March 9, 2011 20:36
Calculating pi via stochastic method
import sys
from math import sqrt
from random import uniform
TOTAL_DEFAULT = 10**6
if len(sys.argv) == 2:
total = int(sys.argv[1])
else:
total = TOTAL_DEFAULT
@ramalho
ramalho / picirc2.py
Created March 10, 2011 01:25
improved version, using a complex number to represent a point
#!/usr/bin/env python
import sys
from random import uniform
TOTAL_DEFAULT = 10**6
total = int(sys.argv[1]) if len(sys.argv) == 2 else TOTAL_DEFAULT
dentro = 0
@ramalho
ramalho / newton.py
Created March 10, 2011 16:31
Raiz quadrada pelo método de Newton
def media(x, y):
return float(x + y)/2
def raizq(x):
''' raiz quadrada pelo metodo de Newton '''
chute = 1.0
while abs(chute * chute - x) >= 0.0001:
chute = media(chute, float(x)/chute)
return chute
@ramalho
ramalho / gist:1299473
Created October 19, 2011 19:54 — forked from pydanny/gist:1298848
PyCon random review script
#!/usr/bin/python
import random
import webbrowser
target = random.randrange(3, 483)
url = 'http://us.pycon.org/2012/review/%s/' % target
webbrowser.open(url)
@ramalho
ramalho / pycon-pc-irc-report.py
Created November 8, 2011 20:38
Generate report from pycon-pc IRC log - DOES NOT HANDLE SKIPPED TALKS
import sys
from itertools import dropwhile
import re
START = re.compile(r'''<pycon_bot> ==== Talk (\d{1,3}): (.*?) now, (http://.*?) ====''')
VOTES = re.compile(r'''<pycon_bot> Talk Votes: (\d+) yays, (\d+) nays, (\d+) abstentions''')
DECISION = re.compile(r'''<pycon_bot> ==== Chair decision: talk (\w+)''')
LINE_FORMAT = '{talk_id:>3} {decision} {yays:>2} {nays:>2} {abst:>2} {title}'
@ramalho
ramalho / pycon-pc-irc-report.py
Created November 8, 2011 21:11
Generate report from pycon-pc IRC log (hard coded skipping)
import sys
from itertools import dropwhile
import re
START = re.compile(r'''<pycon_bot> ==== Talk (\d{1,3}): (.*?) now, (http://.*?) ====''')
VOTES = re.compile(r'''<pycon_bot> Talk Votes: (\d+) yays, (\d+) nays, (\d+) abstentions''')
DECISION = re.compile(r'''<pycon_bot> ==== Chair decision: talk (\w+)''')
LINE_FORMAT = '{talk_id:>3} {decision} {yays:>2} {nays:>2} {abst:>2} {title}'
@ramalho
ramalho / pycon-pc-irc-report.py
Created November 9, 2011 18:47
Generate report from pycon-pc JSON
import sys
import json
LINE_FORMAT = '{id:>3} {mark} {yay:>2} {nay:>2} {abstain:>2} {name}'
with open(sys.argv[1]) as json_in:
talks = json.load(json_in)
for talk in talks:
mark = {'rejected':'-', 'accepted': '+', 'poster': 'p'
@ramalho
ramalho / pycon-pc-irc-report.py
Created November 10, 2011 03:04
Generate report from pycon-pc JSON
import sys
import json
from itertools import dropwhile
LINE_FORMAT = '{id:>3} {mark} {yay:>2} {nay:>2} {abstain:>2} {name}'
with open(sys.argv[1]) as json_in:
talks = json.load(json_in)
for talk in dropwhile(lambda x:x['id']<264, talks):
@ramalho
ramalho / on the bash shell...
Created November 21, 2011 21:23
from 0 to Web in 35 lines
luciano@vogon:~$ sudo easy_install bottle
[sudo] password for luciano:
Searching for bottle
Reading http://pypi.python.org/simple/bottle/
Reading http://bottlepy.org/
[...]
Reading http://github.com/defnull/bottle
Best match: bottle 0.9.7
Downloading http://pypi.python.org/packages/source/b/bottle/bottle-0.9.7.tar.gz#md5=eb4faa6a519251928e4bb737db4217ae
Processing bottle-0.9.7.tar.gz