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
# wrapper for middleware classes (I'm using this in combination with django-sse) | |
def EventStreamMiddlewareWrapper(original): | |
original_method = getattr(original, 'process_response', None) | |
if not original_method: | |
return original | |
def new_method(self, request, response): | |
# return immediately when the response is an event stream | |
if 'text/event-stream' in response.get('Content-Type', ''): | |
return response |
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
from datetime import datetime | |
import email | |
# convert RFC822 timestamp string to datetime object | |
def rfc822(timestamp): | |
return datetime.fromtimestamp(email.Utils.mktime_tz(email.Utils.parsedate_tz(timestamp))) | |
if __name__ == '__main__': | |
import sys |
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
import re | |
# functions to detect/fix double-encoded UTF-8 strings | |
# Based on http://blogs.perl.org/users/chansen/2010/10/coping-with-double-encoded-utf-8.html | |
DOUBLE_ENCODED = re.compile(""" | |
\xC3 (?: [\x82-\x9F] \xC2 [\x80-\xBF] # U+0080 - U+07FF | |
| \xA0 \xC2 [\xA0-\xBF] \xC2 [\x80-\xBF] # U+0800 - U+0FFF | |
| [\xA1-\xAC] \xC2 [\x80-\xBF] \xC2 [\x80-\xBF] # U+1000 - U+CFFF | |
| \xAD \xC2 [\x80-\x9F] \xC2 [\x80-\xBF] # U+D000 - U+D7FF | |
| [\xAE-\xAF] \xC2 [\x80-\xBF] \xC2 [\x80-\xBF] # U+E000 - U+FFFF |
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
import unicodedata | |
def remove_diacritics(s): | |
nkfd_form = unicodedata.normalize('NFKD', unicode(s)) | |
return u"".join([c for c in nkfd_form if not unicodedata.combining(c)]) |
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
# -*- coding:utf-8 -*- | |
import re | |
STOPWORDS = re.compile(r'(?u)\b(?:a(?:(?:an|b(?:er|o(?:ut|ve))|fter|gain(?:st)?|l(?:(?:g(?:un(?:as|os)|o)|l(?:e[mnrs]?)?|so?|tijd))?|n(?:(?:d(?:er(?:(?:e[mnrs]?|[mnrs]))?)?|tes?|y))?|re|u(?:ch|[fs])|[mst]))?|b(?:e(?:(?:cause|en|fore|i(?:ng)?|low|tween|n))?|i(?:st?|[jn])|oth|ut|y)|c(?:o(?:mo|n(?:tra)?)|ua(?:ndo|l))|d(?:a(?:(?:ar|mit|nn?|s(?:selbe)?|zu|[tß]))?|e(?:(?:in(?:e[mnrs]?)?|m(?:selben)?|n(?:(?:selben|n))?|r(?:(?:er|selben?))?|s(?:(?:de|se(?:lben|n)))?|ze|l))?|i(?:ch|e(?:s(?:e(?:(?:lben?|[mnrs]))?)?)?|[drt])|o(?:(?:ch|e[ns]|ing|nde|or|rt|wn))?|u(?:(?:r(?:ante|ch|ing)|s))?)|e(?:(?:ach|ens?|in(?:(?:e[mnrs]?|ig(?:e[mnrs]?)?|mal))?|l(?:l(?:as?|os))?|n(?:tre)?|r(?:(?:a(?:(?:is|[ns]))?|es))?|s(?:(?:as?|os?|t(?:a(?:(?:ba(?:(?:is|[ns]))?|d(?:(?:as?|os?))?|mos|ndo|r(?:(?:emos|á[ns]?|é(?:is)?|ía(?:(?:is|mos|[ns]))?))?|s))?|e(?:mos)?|o[sy]?|uv(?:i(?:e(?:r(?:a(?:(?:is|[ns]))?|on)|se(?:(?:is|[ns]))?)|mos|ste(?:is)?|é(?:ramos|semos))|[eo])|á(?:(?:bamos|is|[ns]))?|é(?:(?:is|[ns]))?)|e |
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
String.prototype.softbreak = function(minimum_size) { | |
return this | |
.toString() | |
.replace( | |
new RegExp('(.{' + (minimum_size || 5) + '})', 'g'), | |
'$1­' | |
); | |
}; |
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
Date.prototype.AGE_TABLE = [ | |
[ 60, 'second' , 'seconds' ], | |
[ 3600, 'minute' , 'minutes' ], | |
[ 86400, 'hour' , 'hours' ], | |
[ 604800, 'day' , 'days' ], | |
[ 2628030, 'week' , 'weeks' ], | |
[ 31557600, 'month' , 'months' ], | |
[ 4294967295, 'year' , 'years' ] | |
]; |
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
Number.prototype.sizify = function(precision) { | |
if (precision === undefined) | |
precision = 1; | |
if (this > 1200000000) | |
return (this / 1000000000.0).toFixed(precision) + ' G'; | |
if (this > 1200000) | |
return (this / 1000000.0).toFixed(precision) + ' M'; |
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
/** | |
* Pure CSS "dubstep forbidden" sign... | |
*/ | |
html, body { | |
margin : 0; | |
padding : 0; | |
width : 100%; | |
height : 100%; | |
font-family : sans-serif; |
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
/** | |
* CSS3 dialog experiment | |
*/ | |
html, body { | |
margin : 0; | |
padding : 0; | |
width : 100%; | |
height : 100%; | |
font-family : 'Montserrat Alternates'; |
OlderNewer