Skip to content

Instantly share code, notes, and snippets.

View gilsondev's full-sized avatar
💼
Work

Gilson Filho gilsondev

💼
Work
View GitHub Profile
#auth table
# Custom Auth table definition
db.define_table(auth.settings.table_user_name,
Field('name', length=128, default='', comment='required'),
Field('email', length=128, default='', unique=True),
Field('phone', length=64, default=''),
Field('homepage', requires=IS_EMPTY_OR(IS_URL())),
Field('bio', 'text', default=''),
Field('twitter'),
Field('facebook'),
########################################################################
# IMAGE METHODS
########################################################################
class RESIZE(object):
def __init__(self,nx=160,ny=80,error_message=' image resize'):
(self.nx,self.ny,self.error_message)=(nx,ny,error_message)
def __call__(self,value):
if isinstance(value, str) and len(value)==0:
return (value,None)
from PIL import Image
########################################################################
# TWITTER IMAGE
########################################################################
def get_twitter_image(username):
from urllib2 import urlopen
from xml.dom.minidom import parse as domparse
apiurl = 'http://twitter.com/users/show/%s'
dom = domparse(urlopen(apiurl % username))
twitter_image = ''
@rochacbruno
rochacbruno / rss.py
Created July 14, 2011 22:49
web2py RSS template
def booksfeed():
r = dict()
r['title'] = "Books Feed"
r['link'] = "http://google.com"
r['description'] = "All My books"
r['entries'] = []
books = db().select(db.books.ALL)
for book in books:
r['entries'].append(dict(title=book.titulo, link="http://books/%s" % book.id, description=book.autor))
@rochacbruno
rochacbruno / caller.sh
Created July 15, 2011 00:32
Webservices with web2py
#soap
from gluon.contrib.pysimplesoap.client import SoapClient
client = SoapClient(wsdl="http://localhost:8000/app/default/call/soap?WSDL")
print client.MyFunction(a=1,b=2)
#{'result': 3}
#xmlrpc
from xmlrpclib import ServerProxy
server = ServerProxy(
@rochacbruno
rochacbruno / routes.py
Created July 15, 2011 21:55
router example
#!/usr/bin/python
# -*- coding: utf-8 -*-
# default_application, default_controller, default_function
# are used when the respective element is missing from the
# (possibly rewritten) incoming URL
#
default_application = 'init' # ordinarily set in base routes.py
default_controller = 'default' # ordinarily set in app-specific routes.py
default_function = 'index' # ordinarily set in app-specific routes.py
@mattgorecki
mattgorecki / facedetect.py
Created July 21, 2011 02:14
Detecting faces with SimpleCV
#!/usr/bin/python
import SimpleCV
import time
import simplejson as json
import sys
if __name__ == "__main__":
captureDir = '/opt/display/applications/tldisplayclient/static'
ofilename = '%s/webcam-original.png' % captureDir
dfilename = '%s/webcam-detected.png' % captureDir
@bragil
bragil / geolocalizacao.py
Created August 25, 2011 18:16
Dado o endereço, obter localização, latitude e longitude
def dados_do_local(endereco):
"""
Dado o endereco, retorna o endereco processado, a latitude e a longitude do local.
Exemplo:
place, (lat, lng) = dados_do_local(endereco)
"""
from geopy import geocoders
if hasattr(settings, "EASY_MAPS_GOOGLE_KEY") and settings.EASY_MAPS_GOOGLE_KEY:
g = geocoders.Google(settings.EASY_MAPS_GOOGLE_KEY)
else:
@rochacbruno
rochacbruno / web2py_ajax.js
Created September 6, 2011 21:30
web2pyajax
function popup(url) {
newwindow=window.open(url,'name','height=400,width=600');
if (window.focus) newwindow.focus();
return false;
}
function collapse(id) { jQuery('#'+id).slideToggle(); }
function fade(id,value) { if(value>0) jQuery('#'+id).hide().fadeIn('slow'); else jQuery('#'+id).show().fadeOut('slow'); }
function ajax(u,s,t) {
query = '';
if (typeof s == "string") {
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt