Popular recipes by Benjamin Sergeant http://code.activestate.com/recipes/users/4039626/2010-10-11T06:18:42-07:00ActiveState Code RecipesSimple way to execute multiple process in parallel (Python)
2010-08-31T00:11:00-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/577376-simple-way-to-execute-multiple-process-in-parallel/
<p style="color: grey">
Python
recipe 577376
by <a href="/recipes/users/4039626/">Benjamin Sergeant</a>
(<a href="/recipes/tags/multiprocessing/">multiprocessing</a>, <a href="/recipes/tags/process/">process</a>).
Revision 4.
</p>
<p>Does not require multiprocessing, easy to hack, maybe not optimal but did the job for a make like tool I wrote.</p>
Creating a tar archive (without using the tarfile module) (Python)
2010-10-11T06:18:42-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/577422-creating-a-tar-archive-without-using-the-tarfile-m/
<p style="color: grey">
Python
recipe 577422
by <a href="/recipes/users/4039626/">Benjamin Sergeant</a>
(<a href="/recipes/tags/compression/">compression</a>, <a href="/recipes/tags/tar/">tar</a>, <a href="/recipes/tags/unix/">unix</a>).
</p>
<p>Creating a tar file is easy if you read the spec (you can look it up on wikipedia). Not every kind of files are supported (it support regular files, folders ans symlinks) and it's generating archives for the original tar file format (path length are limited to 100 chars, no extended attributes, ...). It wasn't tested very much but it was a fun hack :) ... I cheated just a little by looking at the python tarfile code from the stdlib for the checksum computation.</p>
<p>A tar file is very simple, it's a list of header/payload for each entry (file|folder|symlink) you want to archive. There's only a payload for file contents. The header is 512 bytes long and can be written in ascii. Numbers (attributes) needs to be written in octal. The files themselves needs to be written in chunks of 512 bytes, which mean you have to fill the last chunk with zeros when the file size is not a multiple of 512 bytes.</p>
<p>Use it like that: </p>
<pre class="prettyprint"><code>python batar.py /tmp/foo.tar `find .` && tar tf /tmp/foo.tar # or xf if you want to extract it
</code></pre>
Reorganize mp3 from an ipod to a Artist/Album{s}/songs structure (Python)
2010-04-20T23:24:57-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/577204-reorganize-mp3-from-an-ipod-to-a-artistalbumssongs/
<p style="color: grey">
Python
recipe 577204
by <a href="/recipes/users/4039626/">Benjamin Sergeant</a>
(<a href="/recipes/tags/ipod/">ipod</a>, <a href="/recipes/tags/music/">music</a>, <a href="/recipes/tags/rip/">rip</a>).
</p>
<p>mp3 that you copied from an ipod are weirdly organized on disk. This recipe will move them to a sane and classic structure (the one iTune use). Written during a boring / long meeting :)</p>
Keep a process up and running (Python)
2009-09-23T11:55:46-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/576911-keep-a-process-up-and-running/
<p style="color: grey">
Python
recipe 576911
by <a href="/recipes/users/4039626/">Benjamin Sergeant</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
Revision 2.
</p>
<p>If you have a long running process that can be killed for strange and unknown reason, you might want it to be restarted ... this script does that.</p>
Delete all message older than a given date in a pop account (Python)
2009-10-05T12:56:13-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/576922-delete-all-message-older-than-a-given-date-in-a-po/
<p style="color: grey">
Python
recipe 576922
by <a href="/recipes/users/4039626/">Benjamin Sergeant</a>
(<a href="/recipes/tags/delete/">delete</a>, <a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/pop/">pop</a>).
</p>
<p>I was using the keep option in fetchmail, so I had a huge number of emails that seems to slow down mails retrieval / pop connection. I wanted a way to </p>
Listing the package/patches dependencies of a binary on Solaris (Python)
2008-07-30T04:30:44-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/576397-listing-the-packagepatches-dependencies-of-a-binar/
<p style="color: grey">
Python
recipe 576397
by <a href="/recipes/users/4039626/">Benjamin Sergeant</a>
(<a href="/recipes/tags/solaris/">solaris</a>, <a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/unix/">unix</a>).
Revision 2.
</p>
<p>Print (1) packages used by a binary, and (2) the list of installed patches
related to these packages. If you have a binary that works with Solaris 10 update N, but doesn't with Solaris 10 update N-2, run this script on both platform and it will help you to find the patches you're looking for.</p>
<p>(1) is retrieved:</p>
<ul>
<li>By using pldd(pid) on the process you want to trace to get a list of loaded
shared library </li>
<li>By retrieving in the main /var/sadm/install/contents database
the list of package related to these shared libraries</li>
</ul>
<p>(2) is retrieved by parsing the output of the showrev -p command, given as
input of this script</p>