Skip to content

Instantly share code, notes, and snippets.

View robertklep's full-sized avatar

Robert Klep robertklep

View GitHub Profile

Keybase proof

I hereby claim:

  • I am robertklep on github.
  • I am robertklep (https://keybase.io/robertklep) on keybase.
  • I have a public key whose fingerprint is F5E0 E8F1 5938 70C3 501D 2896 3CAF 44BE 0135 D038

To claim this, I am signing this object:

@robertklep
robertklep / EventStreamMiddlewareWrapper.py
Created June 13, 2012 19:49
Wrapper function for Django middleware classes so they handle text/event-stream
# 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
@robertklep
robertklep / strip-diacritics.py
Created June 14, 2012 05:51
Strip diacritics from Python string
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)])
@robertklep
robertklep / stopwords.py
Created June 14, 2012 05:53
Regular expression matching most common Dutch, German, English and Spanish stopwords
# -*- 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
@robertklep
robertklep / softbreak.js
Created October 6, 2012 09:16
Allow a browser to soft break a string by inserting soft hyphens
String.prototype.softbreak = function(minimum_size) {
return this
.toString()
.replace(
new RegExp('(.{' + (minimum_size || 5) + '})', 'g'),
'$1­'
);
};
@robertklep
robertklep / gist:3844465
Created October 6, 2012 09:18
Create a humanized age string from a Javascript Date instance
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' ]
];
@robertklep
robertklep / gist:3844473
Created October 6, 2012 09:19
Create a humanized size string from a Javascript Number instance
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';
@robertklep
robertklep / dabblet.css
Created November 29, 2012 11:03
Pure CSS "dubstep forbidden" sign...
/**
* Pure CSS "dubstep forbidden" sign...
*/
html, body {
margin : 0;
padding : 0;
width : 100%;
height : 100%;
font-family : sans-serif;
@robertklep
robertklep / dabblet.css
Created November 29, 2012 12:35
CSS3 dialog experiment
/**
* CSS3 dialog experiment
*/
html, body {
margin : 0;
padding : 0;
width : 100%;
height : 100%;
font-family : 'Montserrat Alternates';
@robertklep
robertklep / dabblet.css
Created November 29, 2012 14:06
Nyancats like to run in circles...
/**
* Nyancats like to run in circles...
*/
html, body {
margin : 0;
padding : 0;
width : 100%;
height : 100%;
font-family : sans-serif;