Skip to content

Instantly share code, notes, and snippets.

View herberthamaral's full-sized avatar

Herberth Amaral herberthamaral

View GitHub Profile
def meu_decorador(f):
def funcao(*args):
print 'vem antes'
f(*args)
print 'vem depois'
return funcao
@meu_decorador
def teste(*args):
def minhafunc(argumento1, argumento2):
if argumento1 > argumento2:
raise Exception('Erro: argumento1 precisa ser menor que argumento2')
args = (3,2)
minhafunc(*args) #erro
kwargs = {'argumento1':1, 'argumento2':2}
minhafunc(**kwargs) # ok :)
@herberthamaral
herberthamaral / gist:1350957
Created November 9, 2011 09:30
Exemplo de uso de args e kwargs no Python
# -*- coding: utf8 -*-
#exemplo de uso de args e kwargs
class Solido(object):
"""
Isso é um comentário multilinha no Python.
O método __init__ é o construtor da classe, ou seja
é o método que será executado quando a classe for instanciada.
Notem que eu tou usando o argumento 'volume' para esse método.
@herberthamaral
herberthamaral / requirements.txt
Created October 24, 2011 11:33
spider receita
"""
Simple script to get the citzen name by its CPF (Brazil's SSN)
"""
from BeautifulSoup import BeautifulSoup as bs
import requests
import urllib2
with requests.session() as session:
url = 'http://www.receita.fazenda.gov.br/aplicacoes/atcta/cpf/ConsultaPublica.asp'
response = session.get(url)
@herberthamaral
herberthamaral / server.py
Created August 19, 2011 20:44
Django + Tornado example
#!/usr/bin/python
import django.core.handlers.wsgi
import os, signal, functools, time
import tornado.httpserver
import tornado.ioloop
import tornado.wsgi
from tornado.options import options, define
try:
define("port", default=8888, help="run on the given port", type=int)
@herberthamaral
herberthamaral / vaga.md
Created May 13, 2011 17:54
Vaga de estagiário @DeskMetricsBR

Quer trabalhar numa das 10 startups mais promissoras da américa latina? Então venha para DeskMetrics!

A DeskMetrics é uma startup global que fornece informações estratégicas em tempo real sobre o uso de sofware. Somos uma startup bem jovem, com menos de um ano de vida e logo nesse início, conseguimos dois destaques no TechCrunch, um dos maiores blogs sobre startups do mundo.

Atualmente estamos com uma sede na Savassi em Belo Horizonte e estamos abrindo um outro escritório em Nova Iorque.

Quem está usando a DeskMetrics?

#shows your current git branch in bash in blue. Very cool :)
#Put this at the end of your ~/.bashrc file under Linux
function bash_git_branch
{
git branch 2> /dev/null | grep \* | python -c "print '['+raw_input()[2:]+']'" 2> /dev/null
}
PS1="${debian_chroot:+($debian_chroot)}[\u@\h:\w]\[\033[1;34m\]\$(bash_git_branch)\[\033[0m\]\$"
package familiajboss;
/**
*
* @author herberth
*
* Código com alguma repetição, mas funciona. Refatorar depois.
* Não se esqueça de adicionar no XML de configuração as seguintes linhas antes do </server>:
"""
Exemplo simples de uso do JNDI com o Jython.
Nota: coloque os seguintes JARs no CLASSPATH:
jboss-4.2.2.GA\client\jnp-client.jar
jboss-4.2.2.GA\client\jboss-client.jar;
jboss-4.2.2.GA\client\jboss-common-client.jar
Coloca-los no sys.path *NÃO* vai funcionar :)
"""
# Hey coops..
#
# Imagine yourself on the other side of the table: two job openings, hundreds of resumes,
# _all of which_ look friggin' identical. Yeah, the HR departments at your MegaCorp XYZ are using
# automated tools to scan for keywords, and the coop department at your school is trying to beat
# you into submission to follow some "predefined template".. But, unless what you're aspiring to
# is to be an automaton at MegaCorp XYZ, relegated to writing test harnesses for code that will
# never see the light of day.. please do yourself a favor, and _be different_! Be bold, dammit.
#
# (Frankly, I'm falling asleep while reading your resumes.. Wake me up! Srsly.)