Skip to content

Instantly share code, notes, and snippets.

Avatar

William Huster whusterj

View GitHub Profile
@whusterj
whusterj / wtf.py
Created May 4, 2018
Track 'WTF' moments over time. Optionally include a message.
View wtf.py
#!/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:
View gist:d7da3b9b04da9dd8fd01
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 Jan 15, 2015
Levenshtein Edit Distance
View getEditDistance.js
// 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++){
View 01-plaintext_email.py
"""
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 Nov 18, 2014
Django custom template tag useful for marking navigation links with an 'active' class.
View active.py
"""
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 Aug 29, 2015
A custom AngularJS Filter for printing a human-readable list.
View prettyListFilter.js
/**
* 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 }}
You can’t perform that action at this time.