Skip to content

Instantly share code, notes, and snippets.

@aliles
aliles / twisted_iteration.py
Created January 16, 2014 12:31
Twisted based cooperative processing of mixed iterators using deferreds. Mixed iterators produce either values, or deferreds that will produce values.
"""Cooperative, deferred based consumption and processing of mixed iterators.
Iterators may return values, or deferreds that will eventually return values.
After consuming a value from the iterator, control is voluntarily yielded to
other iterators waiting to be processed.
"""
from twisted.internet import defer, reactor, task
def iterate(iterator):
"""Consume next value from iterator
@aliles
aliles / jinja2_http_extension.py
Last active January 3, 2016 05:39
Technical proof-of-concept for using Jinja2 as a template language for API endpoints.
"""Proof of concept for adding external actions to Jinja2 templates
Demonstrates how control may be passed out of Jinja2 where additional
processing could occur and a value be passed back. Targetted use case is using
Jinja2 as a templating language for API endpoints.
"""
import os
import random
import string
import sys
@aliles
aliles / magic_ok.py
Created December 18, 2013 11:33
Demonstrate how to use Python's weakref module to ensure that filemagic Magic objects are closed before begin garbage collected when encapsulated inside a container object.
import magic
import weakref
class Container(object):
def __init__(self):
_magic = magic.Magic()
cleanup = lambda _: _magic.close()
self._magic_weakref = weakref.ref(self, cleanup)
Nick is a Boulder resident working remotely for Lab305, specializing in the
development and deployment of Python web applications using the Django web
framework. Nick's work sees him contributing open source projects in all areas
of web development. From Bootstrap CSS scaffold plugins for Django, to
presenting on using Salt as a configuration management tool with Django
deployments. Nick has earned experience in all areas of building, deploying and
maintaining web sites.
Nick's other great passion is ultra-running, a pursuit characterized by
dedication, determination and a disregard for pain and self preservation. So
@aliles
aliles / nosetest.txt
Last active December 21, 2015 12:29
Warning messages display by 'nosetests sklearn' on experimental wheel packages for OSX 10.8
(ogrisel27-2)192-168-1-7:~ aaroniles$ nosetests sklearn
/Users/aaroniles/.virtualenvs/ogrisel27-2/lib/python2.7/site-packages/sklearn/pls.py:7: DeprecationWarning: This module has been moved to cross_decomposition and will be removed in 0.16
"removed in 0.16", DeprecationWarning)
......./Users/aaroniles/.virtualenvs/ogrisel27-2/lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.py:1664: RuntimeWarning: invalid value encountered in sqrt
s = np.sqrt(eigvals)
...........................S.........................................../Users/aaroniles/.virtualenvs/ogrisel27-2/lib/python2.7/site-packages/sklearn/manifold/spectral_embedding_.py:226: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
warnings.warn("Graph is not fully connected, spectral embedding"
......./Users/aaroniles/.virtualenvs/ogrisel27-2/lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.py:193: RuntimeWarning: invalid value encountered in multiply
* coefs)
/Users/aaroniles/.v
@aliles
aliles / out1.txt
Last active December 20, 2015 01:19
Example help output generated by the new subcommands feature for the next release of begins. https://github.com/aliles/begins
$ python subcommands.py --help
usage: subcommands.py [-h] [-v | -q]
[--loglvl {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
[--logfile LOGFILE] [--logfmt LOGFMT]
{goodbye,hello} ...
Greetings and salutations
optional arguments:
-h, --help show this help message and exit
@aliles
aliles / gist:4975338
Created February 18, 2013 05:53
My favourite geeky podcasts
  • FLOSS weekly
  • Freakonomics
  • IEEE Spectrum
  • Radio Free Python
  • Risky Business
  • Security Now!
  • WNYC's Radiolab
@aliles
aliles / gist:4464680
Created January 6, 2013 01:31
The type of the type object's __new__ method differs between Python2 and PyPy. This causes the unit tests for Python3.3's function signatures tools to fail if backported to 2.7.
$ python2.7
Python 2.7.3 (default, Sep 18 2012, 21:28:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> type(type.__new__)
<type 'builtin_function_or_method'>
>>>
$ pypy
Python 2.7.2 (341e1e3821ff, Jun 07 2012, 15:42:54)
@aliles
aliles / dictobject.diff
Created October 22, 2012 09:28
Python dict hash randomisation individualised per object
diff -r 8fb438e7f738 Objects/dictobject.c
--- a/Objects/dictobject.c Sun Oct 21 18:31:25 2012 -0700
+++ b/Objects/dictobject.c Mon Oct 22 20:27:51 2012 +1100
@@ -235,6 +235,31 @@
static int dictresize(PyDictObject *mp, Py_ssize_t minused);
+/*
+Hash randomisation by repated folding controlled by a seed value. The seed
+value used is the address of the dict object. This breaks copy but avoids the
@aliles
aliles / cffi_coownership.py
Created July 14, 2012 12:01
Wrapper for cffi cdata objects to enable coownership of memory.
"""Wrapper for cffi cdata objects to enable coownership of memory.
When a cdata object that owns memory is used to set a pointer in a C structure
owned by another cdata object, references to both cdata objects must be held to
prevent memory from being released early.
Coownership enables the C structure's cdata object to hold a reference to the
cdata owner the memory it has been initialised with. Preventing the memory from
being released until it itself is garbage collected.
"""