Popular recipes by Noufal Ibrahim http://code.activestate.com/recipes/users/4173873/2013-04-29T14:04:20-07:00ActiveState Code RecipesCreate a temporary mailbox (Python) 2013-04-29T14:04:20-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/578514-create-a-temporary-mailbox/ <p style="color: grey"> Python recipe 578514 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/mail/">mail</a>, <a href="/recipes/tags/mbox/">mbox</a>). </p> <p>Generates a mailbox with lots of messages.</p> JSON pretty printer (Python) 2011-06-28T11:23:13-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577772-json-pretty-printer/ <p style="color: grey"> Python recipe 577772 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/json/">json</a>). </p> <p>Simple script to be used as a shell pipeline to pretty print JSON output. Quite useful when using couchdb with curl.</p> <p>This is a shell function which uses Python to do all ork.</p> Display a git repository (Ruby) 2012-07-05T17:01:53-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577572-display-a-git-repository/ <p style="color: grey"> Ruby recipe 577572 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/git/">git</a>, <a href="/recipes/tags/graphviz/">graphviz</a>, <a href="/recipes/tags/grit/">grit</a>, <a href="/recipes/tags/visualisation/">visualisation</a>). Revision 2. </p> <p>A tiny script to display the entire contents of a medium sized git repository. It will display tags, branches and commits with different shapes and colours and the commits messages in a dimmed colour. </p> <p>It relies on graphviz to do the plotting. Use it like so </p> <pre class="prettyprint"><code> ruby plotrepo.rb /path/to/repository | dot -Tpng | display -antialias </code></pre> Counting decorator (Python) 2011-01-07T11:22:55-08:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577534-counting-decorator/ <p style="color: grey"> Python recipe 577534 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/testing/">testing</a>). </p> <p>To be used as a decorator for a function that will maintain the number of times it was called. Here is an example use. </p> <pre class="prettyprint"><code>&gt;&gt;&gt; def test(): ... print "Hello" ... &gt;&gt;&gt; test = counter(test) &gt;&gt;&gt; test() Hello &gt;&gt;&gt; test() Hello &gt;&gt;&gt; test() Hello &gt;&gt;&gt; test() Hello &gt;&gt;&gt; test() Hello &gt;&gt;&gt; test.invocations 5 &gt;&gt;&gt; test() Hello &gt;&gt;&gt; test.invocations 6 &gt;&gt;&gt; </code></pre> Pomodoro timer (Python) 2010-08-14T11:48:18-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577358-pomodoro-timer/ <p style="color: grey"> Python recipe 577358 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/gtd/">gtd</a>, <a href="/recipes/tags/pomodoro/">pomodoro</a>, <a href="/recipes/tags/timer/">timer</a>). </p> <p>A simple script that works as a pomodoro timer. Useful to enhance ones focus while working on something. The Pomodoro technique is described at <a href="http://www.pomodorotechnique.com/" rel="nofollow">http://www.pomodorotechnique.com/</a></p> <p>This script is an offline version of <a href="http://www.focusboosterapp.com/live.cfm" rel="nofollow">http://www.focusboosterapp.com/live.cfm</a></p> <p>It requires the <a href="http://www.mpg123.de/">Mpg123</a> program to play the audio and I obtained the ticking sounds from <a href="http://www.soundjay.com/clock-sounds-1.html" rel="nofollow">http://www.soundjay.com/clock-sounds-1.html</a></p> getattr with arbitrary depth. (Python) 2010-08-05T07:02:29-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577346-getattr-with-arbitrary-depth/ <p style="color: grey"> Python recipe 577346 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/attributes/">attributes</a>, <a href="/recipes/tags/getattr/">getattr</a>). Revision 2. </p> <p><code>getattr</code> allows one to obtain an attribute from an object given it's name as a string. <code>multi_getattr</code> does the same thing but with dotted strings that can represent nested attributes.</p> Simple tabulator (Python) 2010-11-09T12:50:06-08:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577458-simple-tabulator/ <p style="color: grey"> Python recipe 577458 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/text_processing/">text_processing</a>). </p> <p>This is a simple script to covert a top to bottom list of items into a left to right list.</p> <pre class="prettyprint"><code> a b c d e f g h i j k l m </code></pre> <p>into</p> <pre class="prettyprint"><code> a b c d e f g h i j k l m </code></pre> <p>A few command line options allow some amount of customisation. </p> Plot database table dependecies for a mySQL database (Python) 2010-07-10T08:14:09-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577298-plot-database-table-dependecies-for-a-mysql-databa/ <p style="color: grey"> Python recipe 577298 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/dot/">dot</a>, <a href="/recipes/tags/graphs/">graphs</a>, <a href="/recipes/tags/graphviz/">graphviz</a>, <a href="/recipes/tags/mysql/">mysql</a>). </p> <p>The following snippet will output a spec suitable for the graphviz dot program. It will go through the database specified and for all the tables that start with any of the names in <code>table_prefixes</code>, it will create a dependency graph. A dependency in this context is when a field of one table has a foreign key reference to another. The edges are labelled with the actual field names. </p> <p>It can be used like this</p> <pre class="prettyprint"><code>python deps.py | dot -Tpng | display </code></pre> <p>This requires the InnoDB engine (i.e. something that honours foreign keys. MyISAM doesn't do so).</p> Open a python module given it's name in Emacs (Bash) 2010-07-19T10:25:06-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577317-open-a-python-module-given-its-name-in-emacs/ <p style="color: grey"> Bash recipe 577317 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/emacs/">emacs</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python_developer_tools/">python_developer_tools</a>, <a href="/recipes/tags/zsh/">zsh</a>). </p> <p>A tiny little <code>zsh</code> function to open a python module in <code>Emacs</code>. Assumes that an <code>Emacs</code> server process is running. </p> Create module dependency graph (Python) 2010-05-07T11:29:03-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577222-create-module-dependency-graph/ <p style="color: grey"> Python recipe 577222 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/dependecies/">dependecies</a>, <a href="/recipes/tags/graphs/">graphs</a>, <a href="/recipes/tags/utilities/">utilities</a>). </p> <p>The following snippet will dump the module dependencies in a format that can be interpreted by the dot program distributed along with graphviz. You can use it like below to see the dependency graph for the asynchat module for example. (the program is saved as grapher.py)</p> <pre class="prettyprint"><code>python grapher.py asynchat | dot -Tpng | display </code></pre> <p>A screenshot is available here <a href="http://twitpic.com/1lqnmh" rel="nofollow">http://twitpic.com/1lqnmh</a></p>