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
""" | |
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` |
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 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 |
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
User = Backbone.Model.extend({ | |
url: function() { | |
var origUrl = Backbone.Model.prototype.url.call(this); | |
return origUrl += origUrl.endsWith('/') ? '' : '/'; | |
} | |
}); |
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
pb-kill-line () { | |
zle kill-line | |
echo -n $CUTBUFFER | pbcopy | |
} | |
pb-kill-whole-line () { | |
zle kill-whole-line | |
echo -n $CUTBUFFER | pbcopy | |
} |
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
# 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 |
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
;; 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) |
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 warnings | |
warnings.filterwarnings( | |
'error', r"DateTimeField received a naive datetime", | |
RuntimeWarning, r'django\.db\.models\.fields') |
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
var Module = (function() { | |
var privateMember = "secret"; | |
return { | |
publicMember: function() { | |
return privateMember; | |
} | |
}; | |
})(); |
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
// Assuming we are working with the ASCII character set. 256 unique values. | |
// | |
// First, check that the length of the string is under the number of unique values. | |
// If it is greater, the string does not have all unique characters | |
// | |
// Second, create an array of boolean values of size of unique characters. | |
// Traverse the string and flag the array value from false to true when a character is hit. | |
// When the character is hit a second time, return false. | |
bool hasUniqueChars(char * 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
import sys | |
from os.path import abspath, join, dirname | |
DOC_ROOT = abspath(dirname(dirname(__file__))) | |
BASE_PATH = dirname(DOC_ROOT) | |
PROJECT_PATH = join(BASE_PATH, 'api') | |
sys.path.append(BASE_PATH) | |
sys.path.append(PROJECT_PATH) |