Skip to content

Instantly share code, notes, and snippets.

@sebastibe
sebastibe / module_pattern.js
Created January 9, 2013 05:25
The pattern known as module of Addy Osmani.
var Module = (function() {
var privateMember = "secret";
return {
publicMember: function() {
return privateMember;
}
};
})();
@sebastibe
sebastibe / warnings_to_exceptions.py
Created February 19, 2013 10:13
During development, you can turn such warnings into exceptions and get a traceback by adding the following to your settings file
import warnings
warnings.filterwarnings(
'error', r"DateTimeField received a naive datetime",
RuntimeWarning, r'django\.db\.models\.fields')
@sebastibe
sebastibe / eletric-pairs.el
Created February 27, 2013 10:15
auto-close any kind of brackets
;; setting for auto-close brackets for electric-pair-mode regardless of current
;; major mode syntax table
(setq electric-pair-pairs '(
(?\" . ?\")
(?\{ . ?\})
) )
;; auto-close any kind of brackets
(add-hook 'after-change-major-mode-hook 'electric-pair-mode)
# credits to http://glowingpython.blogspot.jp/2013/03/bubble-sort-visualized.html
import pylab
from random import shuffle
def bubblesort_anim(a):
x = range(len(a))
imgidx = 0
# bubble sort algorithm
pb-kill-line () {
zle kill-line
echo -n $CUTBUFFER | pbcopy
}
pb-kill-whole-line () {
zle kill-whole-line
echo -n $CUTBUFFER | pbcopy
}
User = Backbone.Model.extend({
url: function() {
var origUrl = Backbone.Model.prototype.url.call(this);
return origUrl += origUrl.endsWith('/') ? '' : '/';
}
});
@sebastibe
sebastibe / unzip_wsgi.py
Created May 31, 2013 11:35
A simple WSGI middleware to unzip HTTP requests when the Content-Encoding header is set to 'gzip'
import logging
from StringIO import StringIO
import zlib
class UnzipRequestMiddleware(object):
"""A middleware that unzips POSTed data.
For this middleware to kick in, the client must provide a value
for the ``Content-Encoding`` header. The only accepted value is
"""
Two things are wrong with Django's default `SECRET_KEY` system:
1. It is not random but pseudo-random
2. It saves and displays the SECRET_KEY in `settings.py`
This snippet
1. uses `SystemRandom()` instead to generate a random key
2. saves a local `secret.txt`
@sebastibe
sebastibe / ui-router-debug.coffee
Created March 12, 2014 13:52
A snippet do debug angular ui-router
$rootScope.$on "$stateChangeStart", (event, toState, toParams, fromState, fromParams) ->
console.log "$stateChangeStart to " + toState.to + "- fired when the transition begins. toState,toParams : \n", toState, toParams
$rootScope.$on "$stateChangeError", (event, toState, toParams, fromState, fromParams) ->
console.log "$stateChangeError - fired when an error occurs during transition."
console.log arguments_
$rootScope.$on "$stateChangeSuccess", (event, toState, toParams, fromState, fromParams) ->
console.log "$stateChangeSuccess to " + toState.name + "- fired once the state transition is complete."
class _Missing(object):
def __repr__(self):
return 'no value'
def __reduce__(self):
return '_missing'
_missing = _Missing()