Skip to content

Instantly share code, notes, and snippets.

View Calzzetta's full-sized avatar

Calzzetta Calzzetta

  • São Paulo, Brazil
View GitHub Profile
print('Ola mundo!')
from unidecode import unidecode
no_diacritics = unidecode('á')
print no_diacritics
@Calzzetta
Calzzetta / post_soap.py
Created June 2, 2015 19:21
POST SOAP using urllib2
import urllib2
REQUEST_URL = 'url do server'
HEADERS = {'content-type':'text/x-xml'}
def post_soap(msg):
req = urllib2.Request(REQUEST_URL, msg, HEADERS)
r = urllib2.urlopen(req)
returned_line = ''.join(r.readlines())
return returned_line
@Calzzetta
Calzzetta / bootle_webserver_get.py
Created April 14, 2015 13:50
Bootle Webserver Get example
from bottle import get, request, run
@get('/')
def index():
name = request.GET.get('name')
return 'Hello %s!' % name
run(host='0.0.0.0', port=8080)
@Calzzetta
Calzzetta / logger_time_rotate.py
Created January 30, 2015 20:39
Logging with TimedRotatingFileHandler
from logging.handlers import TimedRotatingFileHandler
import logging
logHandler = TimedRotatingFileHandler('file_name.log', when="midnight")
logFormatter = logging.Formatter('%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
logHandler.setFormatter(logFormatter)
logger = logging.getLogger('time_rotate_logger')
logger.addHandler(logHandler)
logger.setLevel(logging.DEBUG)
@Calzzetta
Calzzetta / pool_cx_oracle.py
Created January 30, 2015 19:50
Connection pool with cx_Oracle
import cx_Oracle
def perform_query(query, bind_variables):
connection = db_pool.acquire()
cursor = connection.cursor()
cursor.execute(query, bind_variables)
result = cursor.fetchall()
cursor.close()
db_pool.release(connection)
return result
@Calzzetta
Calzzetta / post_pool_urllib3.py
Last active August 29, 2015 14:14
Connection pool urllib3
import urllib3
pool = urllib3.PoolManager(num_pools=10)
for i in range(100):
resp = pool.urlopen('POST', 'your-url.com', headers = {...}, body = '...')
print(resp.data)