Skip to content

Instantly share code, notes, and snippets.

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

Bruno Cesar Rocha rochacbruno

🛠️
Working on Galaxy_ng and Dynaconf
View GitHub Profile
@rochacbruno
rochacbruno / IS_EMAIL_LIST.py
Created July 6, 2011 08:41
IS EMAIL LIST validator for web2py
class IS_EMAIL_LIST(object):
def __init__(self, error_message="Email %s is invalid", sep=","):
self.error_message = error_message
self.sep = sep
def __call__(self, value):
emails = value.strip().replace('\n','').replace('\t','').split(self.sep)
for email in emails:
email = email.strip()
if IS_EMAIL()(email)[1] != None:
@pcardune
pcardune / .gitignore
Created September 5, 2011 04:55
Facebook command-line client helper
.fb_access_token
.fbconsole.py
@cyberdelia
cyberdelia / mixin.py
Created September 21, 2011 08:26
Django class based view mixins
# -*- coding: utf-8 -*-
from django.contrib.auth.decorators import login_required
from django.utils.cache import patch_response_headers
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page, never_cache
from django.views.decorators.csrf import csrf_exempt
class NeverCacheMixin(object):
@method_decorator(never_cache)
@rduplain
rduplain / app.py
Created November 10, 2011 15:44
Customize Flask to select a template based on some criteria.
"Customize Flask to select a template based on some criteria."
import os
from flask import Flask, request, render_template
from flask.helpers import locked_cached_property
from jinja2 import FileSystemLoader, TemplateNotFound
# Import a detection utility from your project, not defined here.
# Takes a request object and returns True if browser is mobile.
@stefanv
stefanv / sparks.py
Created November 17, 2011 00:25
Command line sparks in Python
#!/usr/bin/python
# coding=utf-8
# Python version of Zach Holman's "spark"
# https://github.com/holman/spark
# by Stefan van der Walt <[email protected]>
"""
USAGE:
import Tkinter
from time import strftime
relogio = Tkinter.Label()
relogio.pack()
relogio['font'] = "Helvetica 120 bold"
relogio['text'] = strftime("%H:%M:%S")

Django-celery + Redis notes

Installation and Setup

  1. Install redis on OSX (10.7) Lion I used:

     $ brew install redis
    
  2. In the project and virtualenv I wanted to use django-celery in I installed the following.

@rochacbruno
rochacbruno / contenttypes.py
Created January 9, 2012 22:23
Movuca content type
class Product(ContentModel):
tablename = "product_data"
def set_properties(self):
ckeditor = CKEditor()
T = current.T
self.fields = [
Field("price", "double", notnull=True, default=0),
Field("manufacturer", "string", notnull=True),
Field("in_stock", "boolean", notnull=True, default=True),
@moby1br
moby1br / exercicio1.py
Created January 14, 2012 18:41
Exercicio 1
# -*- coding: utf-8 -*-
################################################################################
#
# CONSTANTES
#
################################################################################
TEXTO_CATEGORIA = {'1': 'Eletronicos', '2': 'Moveis', '3': 'Alimentos', '4': 'Roupas', '5': 'Outros'}
TEXTO_UNIDADE = {'1': 'Unidade', '2': 'Caixa/Pcte', '3': 'Duzia'}
@carlzulauf
carlzulauf / haversine.sql
Created February 2, 2012 16:47
PostgreSQL function for haversine distance calculation, in miles
-- Haversine Formula based geodistance in miles (constant is diameter of Earth in miles)
-- Based on a similar PostgreSQL function found here: https://gist.github.com/831833
-- Updated to use distance formulas found here: http://www.codecodex.com/wiki/Calculate_distance_between_two_points_on_a_globe
CREATE OR REPLACE FUNCTION public.geodistance(alat double precision, alng double precision, blat double precision, blng double precision)
RETURNS double precision AS
$BODY$
SELECT asin(
sqrt(
sin(radians($3-$1)/2)^2 +
sin(radians($4-$2)/2)^2 *