Skip to content

Instantly share code, notes, and snippets.

@rkern
rkern / gist:637806
Created October 21, 2010 02:17
Compile a code snippet while caching its contents.
import hashlib
import linecache
import time
import types
def code_name(code):
""" Compute a (probably) unique name for code for caching.
"""
hash_digest = hashlib.md5(code).hexdigest()
return '<code %s>' % hash_digest
@rkern
rkern / example.py
Created December 1, 2011 14:07
Inprocess Qt frontend for IPython
from IPython.frontend.qt.console.ipython_widget import IPythonWidget
from IPython.lib import guisupport
from qtkernelmanager import QtKernelManager
def main():
app = guisupport.get_app_qt4()
km = QtKernelManager()
@rkern
rkern / keywdarg.c
Created February 3, 2012 22:41
Keyword arg test
#include "Python.h"
static PyObject *
keywdarg_parrot(PyObject *self, PyObject *args, PyObject *keywds)
{
PyObject *foo, *bar, *baz;
int bat, blah;
foo = NULL;
@rkern
rkern / debug_layout.py
Created March 26, 2012 17:00
Layout debugging tools
from collections import defaultdict
from enable.api import (AbstractOverlay, ColorTrait,
Component as EnableComponent, Container as EnableContainer, LineStyle,
transparent_color)
from kiva.constants import FILL, STROKE
from traits.api import (Any, Bool, Float, HasTraits, Instance, List, Property,
NO_COMPARE, on_trait_change)
from casuarius import medium
@rkern
rkern / mpstack.py
Created April 10, 2012 07:56
Sampling profiler
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import cPickle
import multiprocessing
import os
import signal
import sys
import time
@rkern
rkern / segment_plot.py
Created April 30, 2012 13:42
BaseXYPlot subclass example
""" A plot made up of disconnected line segments.
"""
import warnings
import numpy as np
from enthought.chaco.base_xy_plot import BaseXYPlot
from enthought.enable.api import black_color_trait, ColorTrait, LineStyle
from enthought.traits.api import Float, List, Str, on_trait_change
@rkern
rkern / gen_data.py
Created May 9, 2012 09:56
Sparse pivot table demonstration
import datetime
import numpy as np
import pandas
dtype = np.dtype([
("Index", object),
("Symbol", object),
("Year", int),
@rkern
rkern / neighbor_lookup_mixin.py
Created May 10, 2012 15:48
Enaml backend lookup
""" Mixin to make Component classes adhere to the EnamlFactory
interface.
"""
from enaml.core.toolkit import Toolkit
from enaml.core.base_component import BaseComponent
class NeighborLookupMixin(object):
""" Mixin to provide an EnamlFactory interface for BaseComponent
@rkern
rkern / bigdata.py
Created June 26, 2012 20:51
Lots of scatter points in Chaco
"""
Demonstrates chaco performance with large datasets.
There are 10 plots with 100,000 points each. Right-click and drag to
create a range selection region. The region can be moved around and
resized (drag the edges). These interactions are very fast because
of the backbuffering built into chaco.
Zooming with the mousewheel and the zoombox (as described in simple_line.py)
is also available, but panning is not.
@rkern
rkern / multixaxes.py
Created June 29, 2012 10:18
Multiple X axes in Chaco
#!/usr/bin/env python
"""
Draws several overlapping line plots like simple_line.py, but uses a separate
Y range for each plot. Also has a second Y-axis on the right hand side.
Demonstrates use of the BroadcasterTool.
Left-drag pans the plot.
Right-click and dragging on the legend allows you to reposition the legend.