Skip to content

Instantly share code, notes, and snippets.

View valdergallo's full-sized avatar
🏠
Working from home

Valder Gallo valdergallo

🏠
Working from home
View GitHub Profile
@valdergallo
valdergallo / sorteio.py
Last active August 29, 2015 13:57
Classe para um sorteio rápido :D
# -*- coding: utf-8 -*-
"""
Classe para um sorteio rápido :D
run test: python -m doctest sorteio.py
>>> s = DoorPrize([1,2,3])
>>> s[0]
1
>>> s.shuffle() != [1,2,3]
True
@valdergallo
valdergallo / jquery.slugify.js
Created April 5, 2014 02:05
jquery.slugify.js
$.fn.slugify = function(options){
var defaults = {
separator: '_',
};
var opts = jQuery.extend(defaults, options);
var map = {"2d":"_","20":"_","24":"s","26":"and","30":"0","31":"1","32":"2","33":"3","34":"4","35":"5","36":"6","37":"7","38":"8","39":"9","41":"A","42":"B","43":"C","44":"D","45":"E","46":"F","47":"G","48":"H","49":"I","50":"P","51":"Q","52":"R","53":"S","54":"T","55":"U","56":"V","57":"W","58":"X","59":"Y","61":"a","62":"b","63":"c","64":"d","65":"e","66":"f","67":"g","68":"h","69":"i","70":"p","71":"q","72":"r","73":"s","74":"t","75":"u","76":"v","77":"w","78":"x","79":"y","100":"A","101":"a","102":"A","103":"a","104":"A","105":"a","106":"C","107":"c","108":"C","109":"c","110":"D","111":"d","112":"E","113":"e","114":"E","115":"e","116":"E","117":"e","118":"E","119":"e","120":"G","121":"g","122":"G","123":"g","124":"H","125":"h","126":"H","127":"h","128":"I","129":"i","130":"I","131":"i","132":"IJ","133":"ij","134":"J","135":"j","136":"K","137":"k","138":"k","139":"L"
@valdergallo
valdergallo / search_catalog.py
Last active August 29, 2015 14:01
Design Patterns Catalog
class SearchCatalog(object):
"""
- Design Patterns Catalog
- https://github.com/faif/python-patterns/blob/master/catalog.py
"""
def __new__(self, request, application, keywords):
search_function = getattr(self, '%s_search' % application, False)
if keywords == 'Search...':
keywords = ''
@valdergallo
valdergallo / Geometria.py
Created July 5, 2014 18:22
Algoritmos de Geometria Analítica
# -*- coding: cp1252 -*-
from math import *
def DotProduct(v, w): #Produto Escalar
try:
result = reduce(lambda x, y: x+y, map(lambda x, y: x*y, v, w))
return result
except TypeError as error:
print "Verifique se foram digitados dois vetores de mesma dimensão:", error
# -*- coding: utf-8 -*-
from django.db import models
import uuid
ANIMALS = (('DO', 'Dog'), ('CA', 'Cat'))
class Animal(models.Model):
tipo = models.CharField(max_length=2, choices=ANIMALS)
@valdergallo
valdergallo / get_currency_number_strings.py
Last active August 29, 2015 14:25
Return the currency number from one string
import re
def get_currency_number(value):
"""
>>> d = u'1Servi\xe7o'
>>> get_number_between_strings(d)
u'1'
>>> e = '78.1234,11Servi\xe7o'
>>> get_number_between_strings(e)
u'78.1234,11'
@valdergallo
valdergallo / celeryconfig.py
Created June 29, 2012 11:30
Configuration for celery with django
# List of modules to import when celery starts.
CELERY_IMPORTS = ("app.tasks", )
BROKER_HOST = "192.168.134.141"
BROKER_PORT = 5672
BROKER_VHOST = "ubuntumq"
BROKER_USER = "ubuntu"
BROKER_PASSWORD = "ubuntu"
## Worker settings
@valdergallo
valdergallo / fabfile_config.py
Created July 5, 2012 13:06
Create config with fabric example
from fabric.contrib.files import append, contains, exists
@task
def config_insert_line():
insert_this = """something"""
if exists('somefile.conf'):
if not contains('somefile.conf', insert_this):
append('somefile.conf', insert_this)
else:
@valdergallo
valdergallo / my.cnf
Created July 17, 2012 16:40
MySQL config with InnoDB
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
socket=/tmp/mysql.sock
tmp_table_size = 32M
max_heap_table_size = 32M
@valdergallo
valdergallo / .gitconfig
Created August 22, 2012 17:16 — forked from igorski89/.gitconfig
git confing
[alias]
st = status
ci = commit
co = checkout
di = diff
dc = diff --cached
amend = commit --amend
aa = add --all
ff = merge --ff-only
pullff = pull --ff-only