Skip to content

Instantly share code, notes, and snippets.

View berinhard's full-sized avatar
👾
let's play that

berin berinhard

👾
let's play that
View GitHub Profile
@berinhard
berinhard / main_loop.py
Created August 9, 2010 19:42
A short decorator used to clean main loop functions. I use it in my pygame projects.
def main_loop(f):
def func():
while True:
f()
return func
@main_loop
def main_loop_function():
print "Whoooo! I'm in loop!"
@berinhard
berinhard / ipdb_breakpoint.vim
Created August 13, 2010 19:30
A script to enable easy ipdb usage for Vim users.
" Author: Bernardo Fontes <falecomigo@bernardofontes.net>
" Website: http://www.bernardofontes.net
" This code is based on this one: http://www.cmdln.org/wp-content/uploads/2008/10/python_ipdb.vim
" I worked with refactoring and it simplifies a lot the remove breakpoint feature.
" To use this feature, you just need to copy and paste the content of this file at your .vimrc file! Enjoy!
python << EOF
import vim
import re
ipdb_breakpoint = 'import ipdb; ipdb.set_trace()'
#!/bin/sh
PROJECT_ROOT="$VIRTUAL_ENV/src"
MEDIA_DIR="$VIRTUAL_ENV/.git/media"
python $PROJECT_ROOT/manage.py test
if test "$?" -ne 0
then
notify-send 'Hammertime!' -t 3000 -i $MEDIA_DIR/hammertime.gif
@berinhard
berinhard / line_walker
Created April 13, 2011 12:16
A script to enable walking lines to your vim
python << EOF
import vim
def line_up():
current_line_number = int(vim.eval('line(".")'))
current_line = vim.current.line
dest_line_number = current_line_number - 1
if current_line_number != 1:
vim.current.buffer.append(current_line, dest_line_number - 1)
@berinhard
berinhard / django_test_signal.py
Created May 6, 2011 13:00
Testing Django Signals
from django.test import TestCase
from your_app.signals import your_signal
class YourTestClass(TestClass):
@classmethod
def setUpClass(cls):
# Save original receivers
cls.signal_receivers = your_signal.receivers
# Erase them
@berinhard
berinhard / mongoengine_fuel_usage.py
Created May 30, 2011 13:35
Exemplo de uso do mongoengine_fuel
from mongoengine import *
from mongoengine_fuel import MongoFuel
class Person(Document):
name = StringField()
age = IntField()
def __unicode__(self):
return u'%s - %d years' % (self.name, self.age)
@berinhard
berinhard / gist:1054748
Created June 29, 2011 19:50
Vim resizing windows
map <C-S-Left> <c-w><
map <C-S-Right> <c-w>>
map <C-S-Up> <c-w>-
map <C-S-Down> <c-w>+
@berinhard
berinhard / lazy-slider.js
Created April 3, 2012 03:39
Javascript slider with lazyload
$(function(){
//Lazyload function
$.fn.lazyload = function(){
var image = $(this);
if (image.attr('real-src')){
image.attr('src', image.attr('real-src'));
image.removeAttr('real-src');
}
return this;
@berinhard
berinhard / django-social-auth-basic.py
Created May 8, 2012 02:33
django-social-auth-basic
########################################
############ SETTINGS.PY ###############
########################################
TEMPLATE_CONTEXT_PROCESSORS = (
...,
'social_auth.context_processors.social_auth_by_type_backends',
)
INSTALLED_APPS = (
@berinhard
berinhard / django-social-auth-basic.py
Created May 8, 2012 02:46
django-social-auth-plus
########################################
########## MEU_PIPELINE.PY #############
########################################
def populate_user_profile(*args, **kwargs):
response = kwargs['response']
user = kwargs['user']
month, day, year = [int(x) for x in response['birthday'].split('/')]
kwargs = {
'user': user,
'hometown': response['hometown']['name'],