Redirect a Python import by using a dummy Python module that deletes its own reference and replaces it with relative module or package.
Allows more control over a relative directory structure
# Taken from here: | |
# https://github.com/creationix/nvm#zsh | |
# place this after nvm initialization! | |
autoload -U add-zsh-hook | |
load-nvmrc() { | |
local node_version="$(nvm version)" | |
local nvmrc_path="$(nvm_find_nvmrc)" | |
if [ -n "$nvmrc_path" ]; then |
from django.core.handlers.wsgi import WSGIRequest | |
from StringIO import StringIO | |
from django.contrib.auth.models import AnonymousUser | |
def GetFakeRequest(path='/', user=None): | |
""" Construct a fake request(WSGIRequest) object""" | |
req = WSGIRequest({ | |
'REQUEST_METHOD': 'GET', | |
'PATH_INFO': path, | |
'wsgi.input': StringIO()}) |
# Taken from http://taketwoprogramming.blogspot.com/2009/06/subclassing-jsonencoder-and-jsondecoder.html | |
class DateTimeAwareJSONEncoder(JSONEncoder): | |
""" | |
Converts a python object, where datetime and timedelta objects are converted | |
into objects that can be decoded using the DateTimeAwareJSONDecoder. | |
""" | |
def default(self, obj): | |
if isinstance(obj, datetime): | |
return { |
var x = [1,2,3] | |
//back to front | |
while(x.length){ | |
var value = x.pop(); | |
console.log(value); | |
} | |
//array is now empty, lets replace it | |
var x = [1,2,3] |
# Execute docker run with --rm --network shared | |
# The shared network will be created if it dosn't already exist | |
dr () { | |
docker network inspect shared > /dev/null 2>&1 | |
if [ $? -ne 0 ] | |
then | |
docker network create shared > /dev/null 2>&1 | |
fi | |
local DOCKER_CMD="docker run --rm --network shared $@" | |
echo |
// var depPairs = [ | |
// "KittenService: ", | |
// "Leetmeme: Cyberportal", | |
// "Cyberportal: Ice", | |
// "CamelCaser: KittenService", | |
// "Fraudstream: Leetmeme", | |
// "Ice: " | |
// ]; | |
// | |
// Turn that into: `'KittenService, Ice, Cyberportal, Leetmeme, CamelCaser, Fraudstream'` |
const storedTemplate = (a,b,c) => `a:${a}, b:${b}, c:${c}` | |
storedTemplate(1,2,3) |
""" Additional collections to augment Python's collections module. | |
""" | |
from collections import namedtuple | |
def defaultnamedtuple( | |
typename, | |
field_names, | |
verbose=False, | |
rename=False, |
""" Interview question | |
Write a method that takes a string, and returns the string in reverse. | |
For instance, if passed abc123 it should return 321cba | |
""" | |
class StringUtil(object): | |
""" Utility for strings |