Popular recipes by Dima Tisnek http://code.activestate.com/recipes/users/4068698/2013-03-03T18:05:42-08:00ActiveState Code RecipesSave and restore SHA-512 internal state (Python)
2013-03-03T18:05:42-08:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/578479-save-and-restore-sha-512-internal-state/
<p style="color: grey">
Python
recipe 578479
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/inner/">inner</a>, <a href="/recipes/tags/pickle/">pickle</a>, <a href="/recipes/tags/restore/">restore</a>, <a href="/recipes/tags/sha512/">sha512</a>, <a href="/recipes/tags/state/">state</a>).
</p>
<p>If you have a very long input to hash, you may want to save your progress.</p>
<p>CPython doesn't normally let you, but it's easy to hack around via ctypes</p>
GAE Matplotlib Demo (Python)
2012-12-31T17:39:14-08:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/578393-gae-matplotlib-demo/
<p style="color: grey">
Python
recipe 578393
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/app_engine/">app_engine</a>, <a href="/recipes/tags/gae/">gae</a>, <a href="/recipes/tags/google_app_engine/">google_app_engine</a>, <a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Google App Engine python 2.7 runtime includes support for numpy and matplotlib since 13-Dec-2012, however, by default, matplotlib is not supported on the development server.
This workaround let you run both in developer mode and deployed on google app engine:</p>
Peek at Python value stack (Python)
2013-01-08T22:15:21-08:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/578412-peek-at-python-value-stack/
<p style="color: grey">
Python
recipe 578412
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/stack/">stack</a>).
</p>
<p>Poking at value stack, a.k.a. evaluation stack is not allowed in Python, however everything is doable with ctypes.</p>
<p>I think this could be useful in debugging complex statements.</p>
Linux ioctl numbers in Python (Python)
2012-07-25T12:25:26-07:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/578225-linux-ioctl-numbers-in-python/
<p style="color: grey">
Python
recipe 578225
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/fcntl/">fcntl</a>, <a href="/recipes/tags/ioctl/">ioctl</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Copy _IOR/_IOWR constants from kernel headers and use with fcntl.iocl()</p>
NBD server in python (Python)
2011-02-08T20:59:23-08:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/577569-nbd-server-in-python/
<p style="color: grey">
Python
recipe 577569
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/analyze/">analyze</a>, <a href="/recipes/tags/block/">block</a>, <a href="/recipes/tags/device/">device</a>, <a href="/recipes/tags/disk/">disk</a>, <a href="/recipes/tags/io/">io</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/nbd/">nbd</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Linux Network Block Device server in Python</p>
<p>This is a simplified version based on Kragen Sitaker's <a href="http://lists.canonical.org/pipermail/kragen-hacks/2004-May/000397.html" rel="nofollow">http://lists.canonical.org/pipermail/kragen-hacks/2004-May/000397.html</a></p>
<p>Close is never actually called, at least not on the same connection -- linux C nbd-client -d seems to stall, perhaps it tries to open another socket?</p>
<p>This code doesn't check for error conditions, failed reads/writes, past end of disk, etc.</p>
<p>It prints io requests, you can analyze filesystem and user program io patterns.</p>
Monkey-patch execnet with more ssh settings, port, identity file, non-interactive (Python)
2011-01-15T16:35:00-08:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/577545-monkey-patch-execnet-with-more-ssh-settings-port-i/
<p style="color: grey">
Python
recipe 577545
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/batchmode/">batchmode</a>, <a href="/recipes/tags/execnet/">execnet</a>, <a href="/recipes/tags/identity/">identity</a>, <a href="/recipes/tags/key/">key</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/noninteractive/">noninteractive</a>, <a href="/recipes/tags/port/">port</a>, <a href="/recipes/tags/public/">public</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/ssh/">ssh</a>).
</p>
<p>execnet ( <a href="http://codespeak.net/execnet/" rel="nofollow">http://codespeak.net/execnet/</a> ) is pretty cool, but its ssh support needs a few tweaks, here they are.</p>
<p>This snipped is a monkey patch, not a diff, import it and you can use execnet.makeportgateway instead of makegateway.</p>
<p>Adapt to your needs even more!</p>
Simple BER decoding in python (Python)
2010-05-26T10:05:22-07:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/577244-simple-ber-decoding-in-python/
<p style="color: grey">
Python
recipe 577244
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/ber/">ber</a>, <a href="/recipes/tags/ber_tlv/">ber_tlv</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Splits a string into BER TLV's and returns a dict of {type(hex): value(binary)}
Doesn't interpret tags, Descend into compound tags.</p>
pycurl-7.19.0 python3 patch (1 of 2) (Python)
2010-04-27T13:00:10-07:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/577209-pycurl-7190-python3-patch-1-of-2/
<p style="color: grey">
Python
recipe 577209
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/patch/">patch</a>, <a href="/recipes/tags/pycurl/">pycurl</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/python3_1/">python3_1</a>).
</p>
<p>Patches needed to install pycurl into python3</p>
Interrogating linux /dev/usb/hiddev0 in python (Python)
2009-07-07T01:32:17-07:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/576834-interrogating-linux-devusbhiddev0-in-python/
<p style="color: grey">
Python
recipe 576834
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/hid/">hid</a>, <a href="/recipes/tags/hiddev/">hiddev</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/usb/">usb</a>).
</p>
<p>What this recipe does:</p>
<p>Maps linux usb hid ioctls and related C structs to python;
Call ioctls, make some sense of output.
Prints all reports for the device with some info.</p>
<p>Works with python 2.4 (tested python 2.4.6 on linux amd64).
Would need changes (e.g. print) for python 3.0.
Might need changes (ioctl signed/unsigned "FIX") for newer python than tested.</p>
unset engine in gtkrc; unset widget style in gtk (Python)
2009-07-13T06:51:51-07:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/576840-unset-engine-in-gtkrc-unset-widget-style-in-gtk/
<p style="color: grey">
Python
recipe 576840
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/engine/">engine</a>, <a href="/recipes/tags/gtkp/">gtkp</a>, <a href="/recipes/tags/gtkrc/">gtkrc</a>, <a href="/recipes/tags/pixbuf/">pixbuf</a>, <a href="/recipes/tags/pygtk/">pygtk</a>, <a href="/recipes/tags/rc/">rc</a>, <a href="/recipes/tags/rcstyle/">rcstyle</a>, <a href="/recipes/tags/style/">style</a>, <a href="/recipes/tags/theme/">theme</a>).
</p>
<p>Example shows how to unset gtk engine'd look for a particular widget.</p>
<p>gtk.Widget.modify_xx allows you to override simple properties, like backgrounds (unless theme uses an engine) and text color (sometimes (?))
gtkrc allows you to override most properties for all or selected widgets, like sizes, faces, and so on.
some parts of widget appearance are set through engine stanzas in gtkrc, these can be unset too, if you know how...</p>
<p>here it is!</p>
Shrink pygtk window (Python)
2007-07-16T05:10:49-07:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/523049-shrink-pygtk-window/
<p style="color: grey">
Python
recipe 523049
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
.
</p>
<p>When you change content of a gtk.Window it expands automatically, but does not shrink automatically. Here is a small workaround.</p>