Skip to content

Instantly share code, notes, and snippets.

@evilchili
evilchili / models.py
Created June 25, 2014 16:36
unique values from a django model field containing CSVs
from django.db import models
class Record(models.Model):
types = models.CharField(db_index=True)
# ... some other stuff ...
@classmethod
def distinct_types(cls):

Keybase proof

I hereby claim:

  • I am evilchili on github.
  • I am evilchili (https://keybase.io/evilchili) on keybase.
  • I have a public key whose fingerprint is 5C84 9002 AF90 54A5 B0AC 59C9 7F71 CCBA 31ED 33DD

To claim this, I am signing this object:

@evilchili
evilchili / count_syllables.py
Created December 2, 2014 16:20
count syllables in a word (poorly)
# -*- coding: UTF-8 -*-
import re
from unidecode import unidecode
from nltk.corpus import cmudict
# the cmu corpus contains syllable counts
cmu_dict = cmudict.dict()
# compile the regexes we'll use to try to count syllables
vowels = u"aeiou"
@evilchili
evilchili / read_fixture.py
Created December 8, 2014 15:31
load django fixtures into memory
from django.core import serializers
from django.core.management.commands.loaddata import Command as LoadDataCommand
import os
def read_fixture(file_name):
"""
Read a fixture and return a list of objects without updating the database.
This method is derived from django.core.management.commands.Command.load_label(),
@evilchili
evilchili / success_rate.sh
Created December 9, 2014 15:28
execute a command n times and report the percentage of success
#!/bin/bash
ITER=10
SCALE=3
CMD=$*
bc <<< "scale=$SCALE; $(for i in `seq 1 $ITER`; do $CMD &>/dev/null && echo $?; sleep 1; done | wc -l)/$ITER * 100"
@evilchili
evilchili / coffee.coffee
Created February 5, 2015 05:16
coffee module for hubot
# Description:
# Drink better coffee.
#
# Commands:
# hubot make me some coffee - Serve up a cup of joe
# hubot get coffee <name> from <roaster> @ <url> - add a coffee to the bar
# hubot sell me that coffee - provide source URL for the last coffee served
#
sizes = ['6oz','8oz','12oz','16oz','24oz']
Several years ago I worked for a company that had a lot of very senior engineers, many of whom had worked quite closely for many years. When the company started hiring new talent, many of whom were younger, frictions arose. One such problem was the ongoing, entrenched issue of tab widths. The senior engineers, true to their idiosyncratic nature, preferred three spaces for tabs. The newer engineers generally preferred four, and being young, often held an attitude of superiority and a certain contempt for their elders. They continually committed changes with tabs four spaces wide, which the senior engineers would revert. Tensions flared, increasingly antagonistic commit messages were logged, and flamewars erupted between proponents of three-wide tabs ("the threes") and those of four-wide tabs ("the 4ists").
This went on for some time, until at last an exasperated engineering manager called an all-hands meeting, and got everyone in a room. He said that they would put it to a vote, and sure enough, when he asked
@evilchili
evilchili / pssh
Created November 5, 2010 16:31
persistent SSH wrapper for autossh
#!/usr/bin/perl
# pssh
# -- "persistent SSH" wrapper for autossh
#
# Copyright 2010 Greg Boyington. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
@evilchili
evilchili / watchsync
Created November 5, 2010 16:57
watch a directory structure for changes and sync changes to another location every 30 seconds.
% while true; do i="`du |tail -1|cut -f1` `find . |cksum`" && [[ $i != $j ]] && rsync -aq --delete . ~/tmp/; j="$i"; sleep 30; done
@evilchili
evilchili / .vimrc
Created November 5, 2010 17:15
vimrc for perl/mason/js editing
" Embedded() is a function that will parse a text buffer
" looking for embedded vim commands, and execute them.
" Call it with a range of lines to check, eg to check the whole
" file:
"
" :%call Embedded()
"
" Commands should be prefixed by the sequence :vim: .
"
function Embedded() range