This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def printable_percent(numerator, denominator, precision=2): | |
"""Truncated readable percentage""" | |
return ('%.' + str(precision) + 'f') % (numerator * 100.0 / denominator) | |
def generate_all_binary_states(keys): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from optparse import OptionParser | |
import sys | |
vowels = 'aeiou' | |
def is_vowel(c): | |
return len(c) == 1 and c in vowels | |
def is_consonant(c): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.db.models import Q | |
class MyModelManager(models.Manager): | |
"""Define methods on MyModel.objects.""" | |
def get_queryset(self): | |
return MyModelQuerySet(self.model) | |
def __getattr__(self, name, *args): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### WHEREAMI | |
# Useful prompt | |
export PS1='$(whoami)@$(hostname):$(pwd)$ ' | |
# Rename a tab | |
function title { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Change angular templating for var interpolation | |
app.config(['$interpolateProvider', function($interpolateProvider) { | |
$interpolateProvider.startSymbol('{['); | |
$interpolateProvider.endSymbol(']}'); | |
}]); | |
app.run(function($rootScope, $http, $cookies) { | |
$http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('someObject', []); | |
app.factory('SomeObject', function($http) { | |
var SomeObject = function(someObject) { | |
angular.extend(this, someObject); | |
var self = this; | |
this.initialize = function() { | |
// pass | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Reusable Django queryset filters. Useful for filtering on complex rule sets, | |
and determining independent reasons why an object fails to pass said rules. | |
""" | |
from collections import namedtuple | |
class FilterSpec( | |
namedtuple('FilterSpec', ['message', 'kwargs', 'exclude', 'distinct'])): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cProfile | |
import pstats | |
from django.utils.functional import wraps | |
def cprofile(sort_by='cumulative', n=20): | |
"""Decorator to profile a function.""" | |
def decorator(func): | |
@wraps(func) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python -O | |
from optparse import OptionParser | |
import random | |
import string | |
import subprocess | |
import threading | |
import time | |
import re | |
# get a list of words with only ASCII characters, and surround them with ^ and $ to demarcate the word boundaries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "QuickTime Player" | |
activate | |
start (new audio recording) | |
end tell |
NewerOlder