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 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): |
| 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 |
| 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 |
| #!/usr/bin/env python | |
| # Monitor for new questions on StackOverflow | |
| # Author: Xueqiao Xu <xueqiaoxu@gmail.com> | |
| 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)L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns
Compress 1K bytes with Zippy ............. 3,000 ns = 3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs
SSD random read ........................ 150,000 ns = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs
| #!/usr/bin/perl | |
| # | |
| # Brad's el-ghetto do-our-storage-stacks-lie?-script | |
| # | |
| sub usage { | |
| die <<'END'; | |
| Usage: diskchecker.pl -s <server[:port]> verify <file> | |
| diskchecker.pl -s <server[:port]> create <file> <size_in_MB> | |
| diskchecker.pl -l [port] |
| ''' 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.''' |
| #!/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" |
| """ | |
| 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 |