This article is now published on my website: Prefer Subshells for Context.
This file contains hidden or 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
# THIS VERSION IS OUTDATED | |
# see .inplace(), .cloning(), ._clone() and .clone() methods of QuerySetMixin | |
# in https://github.com/Suor/django-cacheops/blob/master/cacheops/query.py | |
from django.conf import settings | |
from django.db.models import Model, Manager | |
MUTATING_QUERYSETS = getattr(settings, 'MUTATING_QUERYSETS', False) | |
class QuerySetMixin(object): | |
def __init__(self, *args, **kwargs): |
This file contains hidden or 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
class MyCallable(object): | |
def __init__(self, urlparts, callable): | |
self.urlparts = urlparts | |
self.callable = callable | |
def __call__(self, **kwargs): | |
print kwargs | |
print self.urlparts | |
def __getattr__(self, name): | |
# Return a callable object of this same type so that you can just keep | |
# chaining together calls and just adding that missing attribute to the |
This file contains hidden or 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 django.views.generic.base import View, TemplateResponseMixin | |
from django.views.generic.edit import FormMixin, ProcessFormView | |
class MultipleFormsMixin(FormMixin): | |
""" | |
A mixin that provides a way to show and handle several forms in a | |
request. | |
""" | |
form_classes = {} # set the form classes as a mapping |
This file contains hidden or 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
#!/usr/bin/env python | |
# Monitor for new questions on StackOverflow | |
# Author: Xueqiao Xu <[email protected]> | |
import time | |
import json | |
import gzip | |
import pprint | |
import urllib | |
import urllib2 |
Here's a few things I tried to write output to a python subprocess pipe.
from subprocess import Popen, PIPE
p = Popen('less', stdin=PIPE)
for x in xrange(100):
p.communicate('Line number %d.\n' % x)
This file contains hidden or 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
''' metatuple - Recursive namedtuple from arbitrary dict | |
After 2 hours of intensive coding and some tequila sips I found | |
a "simple" solution to create a namedtuple from any dictionary, | |
recursivelly creating any necessary namedtuple. | |
Probably there are tons of easiest ways of doing that, like some | |
well documented method or standart function in the python library, | |
but that wouldn't be fun.''' |
This file contains hidden or 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
#!/bin/sh | |
# Usage: . testlib.sh | |
# Simple shell command language test library. | |
# | |
# Tests must follow the basic form: | |
# | |
# begin_test "the thing" | |
# ( | |
# set -e | |
# echo "hello" |
This file contains hidden or 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
""" | |
An example of minimum requirements to make MultiValueField-MultiWidget for Django forms. | |
""" | |
import pickle | |
from django.http import HttpResponse | |
from django import forms | |
from django.template import Context, Template | |
from django.views.decorators.csrf import csrf_exempt |
This file contains hidden or 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
#!/usr/bin/awk -e { if (/^```/) { i++; next } if ( i % 2 == 1) { print } } | |
# mdlp - agnostic literate programming for github flavored markdown. | |
# I release this script into the public domain. | |
# Rich Traube, Fri Feb 15 09:07:27 EST 2013 |
OlderNewer