Skip to content

Instantly share code, notes, and snippets.

View jbochi's full-sized avatar

Juarez Bochi jbochi

View GitHub Profile
schedule = a_periodic_task.run_every
next = next_ocurrance(schedule.minute, schedule.hour, schedule.day_of_week)
def next_ocurrance(minutes, hours, days_of_week):
# days_of_week convention: Sunday = 0, Saturday = 6
# dateutil convention: Monday = 0, Sunday = 6
now = datetime.datetime.now()
weekday = now.isoweekday()
import csv
import urllib
le_pagina = lambda pagina: eval(urllib.urlopen("http://webservices.apontador.com.br/zap/busca.ashx?busca=alugar&uf=RIO%20DE%20JANEIRO&cidade=RIO%20DE%20JANEIRO&page=" + str(pagina)).read())[0]
numero = lambda x: float(x.replace(',', '.'))
paginas = [le_pagina(i) for i in xrange(1, 8)]
f = open('imoveis.csv', 'w')
c = csv.writer(f)
@jbochi
jbochi / expr.py
Created April 4, 2011 21:39
Reverse Polish Notation
# avaliador de expressao em notacao polonesa reversa
funcoes = {
"+": lambda a, b: a + b,
"-": lambda a, b: a - b,
"*": lambda a, b: a * b,
"/": lambda a, b: a / b
}
def avalia(expressao):
@jbochi
jbochi / gist:1409684
Created November 30, 2011 16:26
Cool dict
>>> class CoolDict(dict):
... def __getattr__(self, attr):
... return self[attr]
...
>>> c = CoolDict()
>>> c['a']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'a'
>>> c['a'] = 3
@jbochi
jbochi / gist:1564904
Created January 5, 2012 11:35
Instalação NGINX v1.0.11 com módulo redis2 v0.07 e perl v5.14.2 e lua 2.0
cd /tmp
wget http://nginx.org/download/nginx-1.0.11.tar.gz
tar -xzvf nginx-1.0.11.tar.gz
wget https://github.com/agentzh/redis2-nginx-module/tarball/v0.07 -O redis2-nginx-module-0.07.tar.gz
tar -xzvf redis2-nginx-module-0.07.tar.gz
wget http://www.cpan.org/src/5.0/perl-5.14.2.tar.gz
tar -xzvf perl-5.14.2.tar.gz
@jbochi
jbochi / croot.lisp
Created January 17, 2012 01:17
Cube root in lisp (SICP ex 1.8)
(define (croot x)
(croot-iter 1.00 x))
(define (croot-iter guess x)
(if (good-enough? guess x)
guess
(croot-iter (improve guess x)
x)))
(define (improve guess x)
@jbochi
jbochi / gist:1992304
Created March 7, 2012 09:54
Coursera total minutes / section
$('.item_section_list').each(function(i, section) {
var saw = 0;
var total = 0;
for (var i = 0; i < section.childNodes.length; i++) {
var row = section.childNodes[i];
console.log(row);
var viewed = row.classList.contains('viewed');
var minutes = parseInt(row.firstChild.text.match(/\((\d+) min\)/)[1], 10);
if (viewed) {
saw += minutes;
@jbochi
jbochi / lazy.py
Created June 10, 2012 18:07
Lazy quick sort in python
import itertools
import random
import heapq
def lazy_sort(col):
def swap(i, j):
if i != j:
col[j], col[i] = col[i], col[j]
def prepare_pivot(l, r):
@jbochi
jbochi / gist:3264872
Created August 5, 2012 13:41
POSCOMP 2012 - Conteúdos Programáticos por Área de Conhecimento

Área de Matemática

Álgebra Linear

Sistemas de Equações Lineares: método de eliminação de Gauss para sistemas lineares. Espaços vetoriais. Subespaços. Bases.

@jbochi
jbochi / fibonacci.plx
Created August 5, 2012 22:01
Solution for dailykata.com - Fibonacci in Perl
#!/usr/bin/perl
use strict;
use warnings;
my $a = 0;
my $b = 1;
while ($a < 100) {