Skip to content

Instantly share code, notes, and snippets.

View whusterj's full-sized avatar

William Huster whusterj

View GitHub Profile
@whusterj
whusterj / wtf.py
Created May 4, 2018 14:44
Track 'WTF' moments over time. Optionally include a message.
#!/usr/bin/env python
"""
wtf.py
Just write a timestamp to a text file, so later we can calculate the
number of 'WTFs' per minute.
Inspired by: http://www.osnews.com/story/19266/WTFs_m
Use it like this:
@whusterj
whusterj / gist:d7da3b9b04da9dd8fd01
Created January 18, 2015 02:20
Deep Get in JavaScript
function deepGet (obj, properties) {
// If we have reached an undefined/null property
// then stop executing and return undefined.
if (obj === undefined || obj === null) {
return;
}
// If the path array has no more elements, we've reached
// the intended property and return its value.
if (properties.length === 0) {
@whusterj
whusterj / getEditDistance.js
Created January 15, 2015 17:40
Levenshtein Edit Distance
// Compute the edit distance between the two given strings
function getEditDistance(a, b) {
if(a.length === 0) return b.length;
if(b.length === 0) return a.length;
var matrix = [];
// increment along the first column of each row
var i;
for(i = 0; i <= b.length; i++){
"""
An example of how to use html2text to create plaintext emails without all the headache.
"""
import html2text
from django.conf import settings
from django.core.mail.message import EmailMultiAlternatives
from django.template.loader import render_to_string
@whusterj
whusterj / active.py
Created November 18, 2014 23:35
Django custom template tag useful for marking navigation links with an 'active' class.
"""
Easily mark navigation links with an 'active' class in Django templates.
Usage::
<a href="{% url 'some_view_name' %}" class="{% active request 'some_view_name' %}">Link to Somewhere</a>
"""
from django.core.urlresolvers import reverse
from django import template
@whusterj
whusterj / prettyListFilter.js
Last active August 29, 2015 14:07
A custom AngularJS Filter for printing a human-readable list.
/**
* A custom AngularJS Filter for printing a human-readable list.
*
* Example: Use in a controller:
*
* $scope.daysOfTheWeek = ['Monday', 'Tuesday', 'Wednesday' ]
*
* Example: Use in a template:
*
* {{ daysOfTheWeek | prettyList }}