Skip to content

Instantly share code, notes, and snippets.

@macndesign
macndesign / time_dict_value_max.py
Created December 4, 2012 11:47 — forked from perone/time_dict_value_max.py
Python max dict value
import timeit
t = timeit.Timer("v=sorted(d.items(), key=lambda x: x[1])[-1]",
"d = {'a': 1000, 'b': 3000, 'c':100}")
print t.timeit()
# 1.648s
t = timeit.Timer("v=max(d.iteritems(), key = operator.itemgetter(1))[0]",
"import operator; d = {'a': 1000, 'b': 3000, 'c':100}")
print t.timeit()
@macndesign
macndesign / tw_trends.py
Created September 8, 2012 22:53 — forked from fabiocerqueira/tw_trends.py
Get and save Twitter Trends
@macndesign
macndesign / .zshrc.sh
Created August 9, 2012 17:43 — forked from lucasvo/.zshrc.sh
Automatically activate your python virtualenvironment
function auto_activate {
SEARCHPATH=`pwd`
function activate_env {
# ZSH outputs errors for the ls * command if you don't disable the nomatch output
unsetopt nomatch 2>/dev/null
ls $SEARCHPATH/*/bin/activate > /dev/null 2> /dev/null
if [ "$?" = '0' ]; then
deactivate > /dev/null 2> /dev/null
@macndesign
macndesign / gist:3146212
Created July 19, 2012 19:29
using Class Based Generic ListView to seach forms and List
....
from django.views.generic import ListView
from sgf.utils.decorators import page, permission_required_sgf
from sgf.administrativo.models import ComiteRegional
from sgf.administrativo.forms import FormComiteRegionalBusca
......
class SearchListView(ListView):