Skip to content

Instantly share code, notes, and snippets.

@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 / jenkins_timestamped_buildstep.sh
Last active December 6, 2015 20:36
prefix jenkins shell build step output with timestamps
#!/bin/bash
#
# Requirements: moreutils (see https://joeyh.name/code/moreutils/)
set -e
function buildstep {
# perform all your actual build things inside this function.
# Don't halt on errors so we can clean up after ourselves.

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 / 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):
@evilchili
evilchili / models.py
Created October 30, 2013 19:24
monkeypatching pagemanager.published to honor protected assets' users/groups
from copy import deepcopy
from django.db import models
from django.db.models import Q
from mezzanine.pages.models import Page
from mezzanine.core.models import RichText
from django.contrib.auth.models import Group, User
from mezzanine.pages.managers import PageManager
from django.utils.timezone import now
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
@evilchili
evilchili / logstash-emitter.conf
Created October 18, 2013 19:08
logstash emitter config for jenkins server logs
input {
file {
path => "/var/log/jenkins/*"
type => "jenkins-server"
start_position => "beginning"
}
}
# The first filter munges the logs into discrete events.
filter {
sh-3.2# puppet resource x_user fnord ensure=present
2013-08-28 09:36:12.919 ruby[73195:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff92f37b06 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff99da73f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff92eea117 -[__NSPlaceholderArray initWithObjects:count:] + 119
3 RubyCocoa 0x0000000105697f2c set_octypes_for_format_str + 1900
4 RubyCocoa 0x0000000105696163 rbobj_to_nsobj + 595
5 RubyCocoa 0x0000000105696648 rbobj_to_ocdata + 328
@evilchili
evilchili / pwdhash.sh
Created August 27, 2013 21:58
Trying to extract a PBKDF2-HMAC-SHA1 from user plist on mountain lion; failing. What am I missing?
#!/bin/sh
USER=$1
# get the shadow hash from the user entry
dscl . read /Users/$USER dsAttrTypeNative:ShadowHashData | tail -1 \
# remove everything but hex data and spaces
| tr -dc '0-9a-f ' \
@evilchili
evilchili / delete_oldest_dirs.sh
Created March 22, 2013 17:00
Deleted the N oldest directories in the current directory
#!/usr/bin/env bash
# find . -maxdepth 1 -type d -printf '%T@ %p\0'
# -- For every directory in the current directory, print a numeric timestamp, a space, the filename, and a null
#
# sort -z -n
# -- Split the output on nulls (-z) and sort numerically (-n)
#
# gawk 'BEGIN {RS="\0";ORS="\0";FS=" "} NR<=3 {print $2}' | \
# -- Print first (ie, oldest) three filenames in the list, separated by nulls.
#
--- opencart.php 2013-01-24 09:15:54.000000000 -0800
+++ /tmp/opencart.php 2013-01-24 09:16:53.000000000 -0800
@@ -115,6 +115,7 @@
if (!$setting['serialized']) {
self::$config->set($setting['key'], $setting['value']);
} else {
+ $setting['value'] = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $setting['value'] );
self::$config->set($setting['key'], unserialize( $setting['value'] ) );
}
}