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/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: |
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
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) { |
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
// 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++){ |
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
""" | |
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 |
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
""" | |
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 |
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
/** | |
* 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 }} |