Skip to content

Instantly share code, notes, and snippets.

View rochacbruno's full-sized avatar
🛠️
Working on Galaxy_ng and Dynaconf

Bruno Rocha rochacbruno

🛠️
Working on Galaxy_ng and Dynaconf
View GitHub Profile
def guess_time(s):
"""
>>> guess_time('20:00')
(20, 0)
>>> guess_time('23:59')
(23, 59)
>>> guess_time('20:00foo')
(20, 0)
>>> guess_time('9pm')
@rochacbruno
rochacbruno / gist:872645
Created March 16, 2011 15:17
Sobrecarga na classe Mail
### MODEL
from gluon.tools import *
########################################################################
# Sobrecarga do método send da classe Mail
########################################################################
class Mail(Mail):
def send(
self,
@rochacbruno
rochacbruno / gist:872690
Created March 16, 2011 15:40
db.py web2py com sobrecarga da classe Mail
# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations
#########################################################################
## This scaffolding model makes your app work on Google App Engine too
#########################################################################
if request.env.web2py_runtime_gae: # if running on Google App Engine
db = DAL('gae') # connect to Google BigTable
session.connect(request, response, db = db) # and store sessions and tickets there
@rochacbruno
rochacbruno / downloadfiles.py
Created March 29, 2011 02:33
download files with Python
#python rocks!
import os
from urllib import urlretrieve
for item in ['http://coelba.sma-se.com.br/pdfs/055ECD0A.pdf','http://coelba.sma-se.com.br/pdfs/11E2C46D.pdf']:
os.system('mkdir %s' % item.split('/')[-1].replace('.pdf',''))
urlretrieve(item,'/home/rochacbruno/%s/%s' % (item.split('/')[-1].replace('.pdf',''), item.split('/')[-1]))
@rochacbruno
rochacbruno / myapi.py
Created May 27, 2011 22:19
Trying to create an app ORM inside modules folder
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import os
import sys
import unittest
sys.path.append(os.path.realpath('../../../'))
from gluon import *
@rochacbruno
rochacbruno / controller.py
Created May 27, 2011 23:55
ORM inside web2py modules
import myapi
orm = myapi.ORM() #database created, migrated, defined
company = orm.new_company(name='Google Inc.') #New company created or validation errors returned
client = orm.new_client(name='John', company_id=company.id) # new client created
# you could call inline
client = orm.new_client(name='John', company_id=orm.new_company('Google Inc.'))
@rochacbruno
rochacbruno / 1humano.py
Created May 29, 2011 11:55
Seres humanos comuns e a reprodução desenfreada orientada a objetos
#--*-- coding: UTF-8 --*--
class Humano(object):
"""Human Being"""
def __init__(self, nome, pai=None, mae=None):
print "alguém fez besteira e colocou mais um ser Humano no mundo \n"
self.nome = nome
self.pai = pai
self.mae = mae
self.filhos = 0
@rochacbruno
rochacbruno / 1humano.py
Created May 30, 2011 23:43 — forked from douglascamata/1humano.py
Seres humanos comuns e a reprodução desenfreada orientada a objetos
#encoding: utf-8
class Humano(object):
"""Human Being"""
def __init__(self, nome, pai=None, mae=None):
print "alguem fez besteira e colocou mais um ser Humano no mundo \n"
self.nome = nome
self.pai = pai
self.mae = mae
@rochacbruno
rochacbruno / 0_with_subprocess_and_password_as_function.py
Created June 3, 2011 06:29
Executar comando do OS (unix) como root usando sudo no Python - run a command as root using sudo from Python
import subprocess
echo = subprocess.Popen(['echo','123'],
stdout=subprocess.PIPE,
)
sudo = subprocess.Popen(['sudo','-S','iptables','-L'],
stdin=echo.stdout,
stdout=subprocess.PIPE,
)
@rochacbruno
rochacbruno / 0validate_and_update.py
Created June 3, 2011 19:41
Include validate_and_update in web2py DAL
def validate_and_update(self, **update_fields):
tablename = self.db._adapter.get_table(self.query)
response = Row()
response.errors = self.db[tablename]._validate(**update_fields)
fields = self.db[tablename]._listify(update_fields,update=True)
if not fields:
raise SyntaxError, "No fields to update"
self.delete_uploaded_files(update_fields)
if not response.errors:
response.updated = self.db._adapter.update(tablename,self.query,fields)