
<rss version="0.91">
  <channel>
  <copyright>Copyright 1997-2005 eden</copyright>
  <pubDate>Thu, 01 Jan 1970 01:33:28 +0100</pubDate>
  <description>Why bother? I mean, really, why?</description>
  <link>http://teethgrinder.co.uk/</link>
  <title>teethgrinder</title>

  <webMaster>rss&#064;teethgrinder.co.uk</webMaster>
  <managingEditor>rss&#064;teethgrinder.co.uk</managingEditor>
  <language>en-us</language>

<item><title>Zend Framework Menus Navigation :: Programming</title><link>http://teethgrinder.co.uk/perm.php?id=349</link><description>&lt;p style=&quot;border: 1px solid grey; padding: 5px;&quot;&gt;&lt;b&gt;Tags&lt;/b&gt;: Zend Framework, &lt;i&gt;menus&lt;/i&gt;, controller, &lt;i&gt;action&lt;/i&gt;, navigation, &lt;i&gt;template&lt;/i&gt;, menu.phtml, &lt;code&gt;actionStack, &lt;/code&gt;&lt;code&gt;setResponseSegment, &lt;/code&gt;&lt;code&gt;renderScript&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This is how to put menu logic in your web page.&lt;/p&gt;
&lt;p&gt;OK, from the get go, this is hard. You may need to read it a couple of times or do more research.&lt;/p&gt;
&lt;p&gt;What we want is a web page with a menu system (a list of items) on the left of the page. The menu will be different for each controller and action.&lt;/p&gt;
&lt;p&gt;What usually happens in ZF is the &lt;span style=&quot;font-family: Courier New;&quot;&gt;ApplicationController &lt;/span&gt;class is created and the method &lt;span style=&quot;font-family: Courier New;&quot;&gt;indexAction &lt;/span&gt;is called. &lt;span style=&quot;font-family: Courier New;&quot;&gt;indexAction &lt;/span&gt;then uses the model to get data and passes info to the view (for example using &lt;span style=&quot;font-family: Courier New;&quot;&gt;$this-&amp;gt;view-&amp;gt;data = 99;&lt;/span&gt; ). The view is then rendered as a string, which is appended to the Layout content.&lt;/p&gt;
&lt;p&gt;It took me a while to figure that out.&lt;/p&gt;
&lt;p&gt;To make the menu we need a seperate controller, the MenuController will decide what to show on the menu. The the menu view will render it and we capture the output of the view into a layout variable. The menu HTML is used later in the layout.phtml template.&lt;/p&gt;
&lt;p&gt;In our application controller we push the &amp;quot;menu&amp;quot; onto the &lt;span style=&quot;font-family: Courier New;&quot;&gt;actionStack &lt;/span&gt;which makes ZF run MenuController::applicationAction next.&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: rgb(51, 102, 255);&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;ApplicationController.php&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;br /&gt;
class ApplicationController extends Zend_Controller_Action&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function __construct(...)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // this tells the framework to run the MenuController after this&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;_helper-&amp;gt;actionStack(&#039;application&#039;, &#039;menu&#039;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
}&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;color: rgb(51, 102, 255);&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;MenuController.php&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;br /&gt;
class MenuController extends Zend_Controller_Action&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function applicationAction&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // we don&#039;t want to append the menu to the end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // of the layout content, so:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;_helper-&amp;gt;viewRenderer-&amp;gt;setResponseSegment(&#039;menu&#039;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;view-&amp;gt;menu = array(&#039;x&#039;, &#039;y&#039;, &#039;z&#039;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function anotherAction&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;_helper-&amp;gt;viewRenderer-&amp;gt;setResponseSegment(&#039;menu&#039;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;view-&amp;gt;menu = array(&#039;a&#039;, &#039;b&#039;, &#039;b&#039;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: rgb(51, 102, 255);&quot;&gt;&lt;b&gt;layout.phtml (/layouts/)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?= $this-&amp;gt;layout()-&amp;gt;menu; ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?= $this-&amp;gt;layout()-&amp;gt;content; ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: rgb(51, 102, 255);&quot;&gt;&lt;b&gt;application.phtml (in /views/scripts/menu/)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;?php foreach( $this-&amp;gt;menu as $m ): ?&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;li&amp;gt;&amp;lt;?= $m ?&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;?php endforeach; ?&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;span style=&quot;color: rgb(51, 102, 255);&quot;&gt;&lt;b&gt;another.phtml (in /views/scripts/menu/)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;?php foreach( $this-&amp;gt;menu as $m ): ?&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;li&amp;gt;&amp;lt;?= $m ?&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;?php endforeach; ?&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The MenuController changes the layout response segment to &#039;menu&#039;, all the HTML in the menu view is saved to this variable.&lt;/p&gt;
&lt;p&gt;This HTML to make the menu is then merged into the web page in layout.phtml.&lt;/p&gt;
&lt;p&gt;More notes on &lt;a href=&quot;http://teethgrinder.co.uk/perm.php?a=Zend-Framework-actionStack&quot;&gt;Zend Framework Menu Navigation&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Zend Framework actionStack :: Programming</title><link>http://teethgrinder.co.uk/perm.php?id=350</link><description>&lt;p&gt;Further notes on &lt;a href=&quot;http://teethgrinder.co.uk/perm.php?a=Zend-Framework-Menus-Navigation&quot;&gt;Zend Framework Menu Navigation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is how you pass variables to another action on the &lt;span style=&quot;font-family: Courier New;&quot;&gt;actionStack&lt;/span&gt;:&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;$this-&amp;gt;_helper-&amp;gt;actionStack(&#039;application&#039;, &#039;menu&#039;, &#039;default&#039;, array(&#039;show_menu&#039;=&amp;gt;$this-&amp;gt;getRequest()-&amp;gt;action));&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Then in your menu controller, &lt;span style=&quot;font-family: Courier New;&quot;&gt;ApplicationController::menuAction&lt;/span&gt; you can:&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;$show_menu = $this-&amp;gt;_getParam( &#039;show_menu&#039; );&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Then you can use this variable to highlight the correct menu item, e.g:&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;li&amp;gt;menu 1&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;li id=&amp;quot;selected&amp;quot;&amp;gt;menu 2&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;li&amp;gt;menu 3&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>youtube :: Programming</title><link>http://teethgrinder.co.uk/perm.php?id=348</link><description>&lt;p&gt;best youtube comment so far:&lt;/p&gt;
&lt;p&gt;JESUS IM COMING&lt;br /&gt;
Right all over your mom&lt;/p&gt;</description></item><item><title>AS3 sprintf :: Programming</title><link>http://teethgrinder.co.uk/perm.php?id=347</link><description>&lt;p&gt;Tags: &lt;i&gt;Actionscript &lt;/i&gt;flash AS3 &lt;i&gt;flex &lt;/i&gt;adobe print &lt;b&gt;format number&lt;/b&gt; &lt;u&gt;format date&lt;/u&gt; string &lt;i&gt;format float&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://code.google.com/p/printf-as3/&quot;&gt;sprinf&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Zend Framework MySQL Out Of Memory Error :: Programming</title><link>http://teethgrinder.co.uk/perm.php?id=346</link><description>&lt;p&gt;Tags:&lt;span style=&quot;color: rgb(51, 102, 255);&quot;&gt; Zend framework, ZF, PHP, MySQL, MySQLi, PDO, SQL, FORMAT, LONGTEXT, FLOAT, floating point, out of memory error&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;There is a bug in the MySQLi (Note the &lt;b&gt;i&lt;/b&gt;) adapter that causes FORMAT() to fail.&lt;/p&gt;
&lt;p&gt;For more info see the &lt;a href=&quot;http://www.nabble.com/Out-of-memory-error-td19108319.html#a19185386&quot;&gt;Zend DB email list&lt;/a&gt;. Here is the &lt;a href=&quot;http://framework.zend.com/issues/browse/ZF-1498&quot;&gt;ZF DB MySQLi bug report&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Hope that helps someone out :-) it&#039;s one of the obscure little bugs that are hard to pin down.&lt;/p&gt;</description></item><item><title>shotgun blast of functions :: Programming</title><link>http://teethgrinder.co.uk/perm.php?id=345</link><description>&lt;p&gt;Start a side project. &amp;lt;-- This is quite amusing and informative. There is a classic quote:&lt;/p&gt;
&lt;pre&gt;&lt;div id=&quot;LC225&quot; class=&quot;line&quot; style=&quot;margin-left: 40px;&quot;&gt;Naturally, the first thing I did was institutionalize Subversion.&lt;/div&gt;&lt;div id=&quot;LC226&quot; class=&quot;line&quot; style=&quot;margin-left: 40px;&quot;&gt;(I&#039;ve apparently always been a champion of source control, though I&lt;/div&gt;&lt;div id=&quot;LC227&quot; class=&quot;line&quot; style=&quot;margin-left: 40px;&quot;&gt;didn&#039;t realize it until setting this story to paper.)&lt;/div&gt;&lt;div id=&quot;LC228&quot; class=&quot;line&quot; style=&quot;margin-left: 40px;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div id=&quot;LC229&quot; class=&quot;line&quot; style=&quot;margin-left: 40px;&quot;&gt;The second thing I did was start extracting the magic numbers into&lt;/div&gt;&lt;div id=&quot;LC230&quot; class=&quot;line&quot; style=&quot;margin-left: 40px;&quot;&gt;configuration files.  At the time, it was a pretty common PHP idiom to&lt;/div&gt;&lt;div id=&quot;LC231&quot; class=&quot;line&quot; style=&quot;margin-left: 40px;&quot;&gt;use .ini files for configuration.  Most of what you&#039;d need was&lt;/div&gt;&lt;div id=&quot;LC232&quot; class=&quot;line&quot; style=&quot;margin-left: 40px;&quot;&gt;supported, and I&#039;m pretty sure PHP came with a library (&lt;i&gt;aka a shotgun&lt;/i&gt;&lt;/div&gt;&lt;div id=&quot;LC233&quot; class=&quot;line&quot; style=&quot;margin-left: 40px;&quot;&gt;&lt;i&gt;blast of functions in the global namespace&lt;/i&gt;) that could understand .ini&lt;/div&gt;&lt;div id=&quot;LC234&quot; class=&quot;line&quot; style=&quot;margin-left: 40px;&quot;&gt;files.&lt;/div&gt;&lt;/pre&gt;
&lt;p&gt;Haha! Man-o-man. So true. It is impossible to find any related functions. Anyway, we&#039;re getting namespaces in PHP6, wow, welcome to the 90s, man.&lt;/p&gt;</description></item><item><title>Python memory leak detector :: Programming</title><link>http://teethgrinder.co.uk/perm.php?id=344</link><description>&lt;p&gt;&lt;span style=&quot;color: rgb(51, 102, 255);&quot;&gt;&lt;b&gt;Tags:&lt;/b&gt;&lt;/span&gt; Python, &lt;b&gt;memory leak&lt;/b&gt;, leek, object, &lt;b&gt;garbage collection&lt;/b&gt;, garbage collector, __del__, inspect, gc, &lt;b&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;DEBUG_LEAK&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;I have a nasty memory leak in my Python script which I can&#039;t find. For some random projects my script gobbles up 2gig of memory then quietly dies.&lt;/p&gt;
&lt;p&gt;Here is my first attempt at cobbling together a leak detector:&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;import gc&lt;br /&gt;
import inspect&lt;br /&gt;
&lt;br /&gt;
def dump_garbage():&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # force collection&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;\nCollecting GARBAGE:&amp;quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; gc.collect()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # prove they have been collected&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;\nCollecting GARBAGE:&amp;quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; gc.collect()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;\nGARBAGE OBJECTS:&amp;quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for x in gc.garbage:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s = str(x)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(s) &amp;gt; 80: s = &amp;quot;%s...&amp;quot; % s[:80]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;::&amp;quot;, s&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type:&amp;quot;, type(x)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;&amp;nbsp;&amp;nbsp; referrers:&amp;quot;, len(gc.get_referrers(x))&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;&amp;nbsp;&amp;nbsp;&amp;nbsp; is class:&amp;quot;, inspect.isclass(type(x))&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; module:&amp;quot;, inspect.getmodule(x)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lines, line_num = inspect.getsourcelines(type(x))&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;&amp;nbsp;&amp;nbsp;&amp;nbsp; line num:&amp;quot;, line_num&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for l in lines:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;quot;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line:&amp;quot;, l.rstrip(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print&lt;br /&gt;
&lt;br /&gt;
class tmp(object):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = 0&lt;br /&gt;
&lt;br /&gt;
if __name__==&amp;quot;__main__&amp;quot;:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; import gc&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; gc.enable()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; gc.set_debug(gc.DEBUG_LEAK)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # make a leak&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; l = [tmp()]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; l.append(l)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; del l&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; dump_garbage()&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;When run it outputs:&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;Collecting GARBAGE:&lt;br /&gt;
gc: collectable &amp;lt;tmp 00BE1730&amp;gt;&lt;br /&gt;
gc: collectable &amp;lt;list 00BED788&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Collecting GARBAGE:&lt;br /&gt;
&lt;br /&gt;
GARBAGE OBJECTS:&lt;br /&gt;
:: &amp;lt;__main__.tmp object at 0x00BE1730&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type: &amp;lt;class &#039;__main__.tmp&#039;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; referrers: 4&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; is class: True&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; module: &amp;lt;module &#039;__main__&#039; from &#039;C:\XXXXXX.py&#039;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; line num: 33&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line: class tmp(object):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = 0&lt;br /&gt;
&lt;br /&gt;
:: [&amp;lt;__main__.tmp object at 0x00BE1730&amp;gt;, [...]]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type: &amp;lt;type &#039;list&#039;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; referrers: 4&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; is class: True&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; module: None&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;As you can see it tries to figure out where the object is defined in your code. This should give you some clues as to where the leak is happening. If you are still having problems try adding some debug comments to the classes as you create them, print the debug info in the dump_garbage() function.&lt;/p&gt;
&lt;p&gt;This is based on this &lt;a href=&quot;http://code.activestate.com/recipes/65333/&quot;&gt;python memory leak detector&lt;/a&gt; at active state. I am learning all this as I go. I guess outputing this as a .csv would help. If you have any comments or improvements drop me a line in the comments below and I&#039;ll update the code.&lt;/p&gt;
&lt;p&gt;These are some links and stuff to help you get started hunting down your memory leak:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Zope.org has a class called TrackRefs (google for it) but to use it you need a debug version of Python.&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://sourceforge.net/projects/guppy-pe&quot;&gt;Guppy PE&lt;/a&gt;, also called heapy. See this post for &lt;a href=&quot;http://blog.redinnovation.com/2008/03/07/debugging-django-memory-leak-with-trackrefs-and-guppy/&quot;&gt;an example of how to use guppy&lt;/a&gt; (the example is near the end of the post)&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://pysizer.8325.org/&quot;&gt;PySizer&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://mg.pov.lt/blog/hunting-python-memleaks.html&quot;&gt;Hunting memory leaks in Python&lt;/a&gt;, and a followup &lt;a href=&quot;http://mg.pov.lt/blog/python-object-graphs.html&quot;&gt;post&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Update&lt;/b&gt;:&lt;/p&gt;
&lt;p&gt;A simple &lt;a href=&quot;http://mail.python.org/pipermail/python-bugs-list/2005-October/030763.html&quot;&gt;urllib2 memory leak test&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python chain methods :: Programming</title><link>http://teethgrinder.co.uk/perm.php?id=343</link><description>&lt;p&gt;I don&#039;t know why I didn&#039;t know this, but you can chain methods in Python. I use this quite a bit in PHP and Zend Framework uses it a little. But here it is in Python:&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;class table_model:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; pass&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def connect(self):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &#039;connect to DB&#039;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return self&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def run_query(self):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &#039;run query&#039;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return self&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def get_last_result(self):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return &#039;Hello&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
table = table_model()&lt;br /&gt;
res = table.connect().run_query().get_last_result()&lt;br /&gt;
print res&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: rgb(128, 0, 0);&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;br /&gt;
connect to DB&lt;br /&gt;
run query&lt;br /&gt;
Hello&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That&#039;s it. Job done.&lt;/p&gt;</description></item><item><title>MySQL max of two columns :: Programming</title><link>http://teethgrinder.co.uk/perm.php?id=342</link><description>&lt;p&gt;How to get the &lt;span style=&quot;font-family: Courier New;&quot;&gt;MAX &lt;/span&gt;or &lt;span style=&quot;font-family: Courier New;&quot;&gt;MIN &lt;/span&gt;value of two columns: &lt;span style=&quot;font-family: Courier New;&quot;&gt;GREATEST( col_1, col_2 )&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Or a more interesting example. I have a client who may have some reports. I need to list the clients in &lt;b&gt;&#039;most recently active&#039;&lt;/b&gt; order. So if they have had a recent action they should be near the top of the list, or if they have recently had a report they should be near the top of the list:&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;SELECT clients.id, clients.name, clients.date, MAX(r.date), GREATEST(clients.date, IFNULL(MAX(r.date), clients.date)) AS date&lt;br /&gt;
FROM clients&lt;br /&gt;
LEFT JOIN reports r on r.clients_id=clients.id&lt;br /&gt;
GROUP BY clients.id&lt;br /&gt;
ORDER BY date DESC&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;So this uses &lt;span style=&quot;font-family: Courier New;&quot;&gt;MAX &lt;/span&gt;to get the most recent report (this may return &lt;span style=&quot;font-family: Courier New;&quot;&gt;NULL &lt;/span&gt;if they have no reports) then I use &lt;span style=&quot;font-family: Courier New;&quot;&gt;GREATEST &lt;/span&gt;to choose the most recent of the two dates (two columns). Job done.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>since I put :: Programming</title><link>http://teethgrinder.co.uk/perm.php?id=341</link><description>&lt;p&gt;Google analytics, &lt;b&gt;page views&lt;/b&gt; from Feb 2007 to July 31 2008:&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;primary_value&quot;&gt;&lt;span style=&quot;font-size: xx-large;&quot;&gt;2,405,706&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item>
</channel>
</rss>

