<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Refactored scope &#187; David</title>
	<atom:link href="http://ominian.com/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://ominian.com</link>
	<description>PyMethius project notes</description>
	<lastBuildDate>Thu, 26 Aug 2010 21:25:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Python, sometimes you scare me</title>
		<link>http://ominian.com/2010/08/26/python-sometimes-you-scare-me/</link>
		<comments>http://ominian.com/2010/08/26/python-sometimes-you-scare-me/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 21:25:58 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=37</guid>
		<description><![CDATA[
for i in range&#40;0, len&#40;sys.path&#41;&#41;:    
    if sys.path&#91;i&#93;.find&#40;&#34;~&#34;&#41; &#62; -1:        
        sys.path&#91;i&#93; = path.expanduser&#40;sys.path&#91;i&#93;&#41;
        break
else:    
    sys.path.insert&#40;1,path.expanduser&#40;&#34;~/lib/python&#34;&#41;&#41;

  More duct tape code [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:    
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span><span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;~&quot;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> -<span style="color: #ff4500;">1</span>:        
        <span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span><span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> = path.<span style="color: black;">expanduser</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span><span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">break</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:    
    <span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">insert</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,path.<span style="color: black;">expanduser</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;~/lib/python&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>  More duct tape code to allow me to rely on ~/lib/python to store common code (ex. apache log parsing &#038; analysis ) when PYTHONPATH might not be set or<br />
set incorrectly.</p>
<p>Basically if ~ is found in sys.path, the break statement skips the else.  Alternatively, if not found then else is executed.<br />
<a href="http://docs.python.org/reference/compound_stmts.html#for">Python compound statements: For loops</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/08/26/python-sometimes-you-scare-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unnamed project: PHP doc&#8217;s on steroids</title>
		<link>http://ominian.com/2010/08/20/unnamed-project-php-docs-on-steroids/</link>
		<comments>http://ominian.com/2010/08/20/unnamed-project-php-docs-on-steroids/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 03:38:51 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=35</guid>
		<description><![CDATA[Been playing with a tool released by Facebook called xhprof, http://mirror.facebook.net/facebook/xhprof/doc.html , which is a
very nice tool for figuring out what exactly is going on in your PHP code.
Meanwhile I used Doxygen a lot, its great for finding out how spread out calls are to individual libraries, has great call graphs, and if setup correctly [...]]]></description>
			<content:encoded><![CDATA[<p>Been playing with a tool released by Facebook called xhprof, http://mirror.facebook.net/facebook/xhprof/doc.html , which is a<br />
very nice tool for figuring out what exactly is going on in your PHP code.</p>
<p>Meanwhile I used Doxygen a lot, its great for finding out how spread out calls are to individual libraries, has great call graphs, and if setup correctly can draw out the entire hierarchy of even the most complicated of projects.</p>
<p>What I&#8217;d like to do is create something that uses xhprof with documentation logic similar to doxygen, to make dynamically generated documentation that not only shows you how a class is defined, but how it&#8217;s defined, what depends on it, and what does it depend on.  </p>
<p>UI:<br />
   I was thinking of something that was intelligent in the ways of MVC frameworks, recording a list of all urls called into a framework and then displaying them as a list broken down by URL components.</p>
<p>A simple example might be a MVC project with one controller called user<br />
User has a standard CRUDE outline so the url&#8217;s might be<br />
/user/create<br />
/user/list<br />
/user/edit<br />
/user/save<br />
/user/delete</p>
<p>So the first screen would be:</p>
<p>Entry points:<br />
  User &#8211; 5 sub points </p>
<p>The sub points part would be a anchor leading to a digest page listing # of recorded profiles to /user/ then maybe a digest of slowest call with the subcompontent ( say save ) to fastest ( delete ), highest / lowest memory consumption, a link to files common to this URI, and then links to progress further down the URL chain.</p>
<p>Clicking on list would lead to /usr/list &#8211; again showing the above, but now specific to this URL.  At this point there shouldn&#8217;t be anymore child components in the URL ( GET arguments are automatically stripped OFF )  so an additional feature would be to click a link to show a visual graph similar to what stock xhprof UI provides.</p>
<p>The fun part would be when you clicked on one of the listed files.  Immediately this would bring up a page similar to a doxygen product, but it would have some additional information:<br />
# of dependant URLS that executed this file<br />
# of classes, functions, and methods used in this file by this url path ( /user/list )<br />
fastest and slowest execution speeds plus memory consumption percentage for /user/list.</p>
<p>Clicking on a class, method, or function would cause it to again drill down and show stats JUST for the specified scope.</p>
<p>Considering its taken me 3 months to get PyProxy to stable useful Alpha, this project is probably going to take me a year or more&#8230; but it should be fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/08/20/unnamed-project-php-docs-on-steroids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyProxy hijack logic</title>
		<link>http://ominian.com/2010/08/19/pyproxy-hijack-logic/</link>
		<comments>http://ominian.com/2010/08/19/pyproxy-hijack-logic/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 22:25:24 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=34</guid>
		<description><![CDATA[So PyProxy is a mostly operational death star able to successfully sit between any website and the browser, one of the latest additions I made was the following inject for html payloads:

&#60;script&#62;
    (function(){
        var original = document.write;
        document.write [...]]]></description>
			<content:encoded><![CDATA[<p>So PyProxy is a mostly operational death star able to successfully sit between any website and the browser, one of the latest additions I made was the following inject for html payloads:</p>
<pre language="Javascript">
&lt;script&gt;
    (function(){
        var original = document.write;
        document.write = function(arg1){
                        console.group("document.write");
                        console.log("doc.write: " + arg1);
                        console.groupEnd();
                        original.apply(document, arguments);
        };
    }());

    (function(){
       var truImage = Image;
       window.Image = function(width, height){
        try{

            this.root = new truImage(width, height);
            this.__defineSetter__("src", function(val){
                console.log("New Image @ " + val)
                this.root.src = val;

                });
        }catch(Err){
            console.log("New Image Err");
        }
       }
    }())
&lt;/script&gt;
</pre>
<p>It&#8217;s abomination code yes, but it is also extremely useful for further illuminating what exactly is going on in the time prior to document.onLoad plus exposes image beacons generated using Javascript Image objects&#8230; something that normally doesn&#8217;t show up any where in the DOM, hence I don&#8217;t believe FireBug or Chrome inspector panels can report it.</p>
<p>Normally to get something like this into a website would require adding it into development, which then opens the risk of it slipping into production.</p>
<p>The functional beta of PyProxy should be released this weekend if I don&#8217;t go on a bender.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/08/19/pyproxy-hijack-logic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pardon my widgets</title>
		<link>http://ominian.com/2010/08/13/pardon-my-widgets/</link>
		<comments>http://ominian.com/2010/08/13/pardon-my-widgets/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 19:37:13 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=33</guid>
		<description><![CDATA[Rendering delays are likely.
]]></description>
			<content:encoded><![CDATA[<p>Rendering delays are likely.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/08/13/pardon-my-widgets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>From the dept of questionable ideas: watching make</title>
		<link>http://ominian.com/2010/07/27/from-the-dept-of-questionable-ideas-watching-make/</link>
		<comments>http://ominian.com/2010/07/27/from-the-dept-of-questionable-ideas-watching-make/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 16:19:07 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=30</guid>
		<description><![CDATA[#watch -n 30 &#8216;make&#8217;
Works great when your webstack uses make to automagically compile multiple files then minify the whole mess down&#8230; but your constantly making tweaks and fixes.
]]></description>
			<content:encoded><![CDATA[<p>#watch -n 30 &#8216;make&#8217;</p>
<p>Works great when your webstack uses make to automagically compile multiple files then minify the whole mess down&#8230; but your constantly making tweaks and fixes.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/07/27/from-the-dept-of-questionable-ideas-watching-make/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A simple example of horizontal scaling VS. vertical scaling just with Database&#8217;s</title>
		<link>http://ominian.com/2010/04/15/a-simple-example-of-horizontal-scaling-vs-vertical-scaling-just-with-databases/</link>
		<comments>http://ominian.com/2010/04/15/a-simple-example-of-horizontal-scaling-vs-vertical-scaling-just-with-databases/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 22:26:14 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=26</guid>
		<description><![CDATA[My answer to a question of what is the difference between Horizontal &#38; Vertical scaling
Link

Given an example application like so: Application has many clients, each client has multiple users.
update: No client needs to know about another client, each user belongs exclusively to one client
Vertical scaling:
Client data is stored in a normalized SQL based database. user [...]]]></description>
			<content:encoded><![CDATA[<p>My answer to a question of what is the difference between Horizontal &amp; Vertical scaling<br />
<a href="http://stackoverflow.com/questions/2635847/what-this-phrase-try-to-make-you-architecture-more-horizontal-rather-than-vertic">Link</a><br />
<span id="more-26"></span><br />
Given an example application like so: Application has many clients, each client has multiple users.</p>
<p>update: No client needs to know about another client, each user belongs exclusively to one client</p>
<p><strong>Vertical scaling</strong>:<br />
Client data is stored in a normalized SQL based database. user credentials for all users is stored in client_users table.</p>
<p>Benefits<br />
Shortest path of resistance for development<br />
relatively easy to maintain integrity with<br />
Easy to backup<br />
Problem:<br />
Because all client credentials are stored in this one table along with related data, to maintain or increase performance would require beefing up your database tier with more resources or investing in more slaves to this one master.</p>
<p><strong>Horizontal scaling</strong>:<br />
Each client exists on a prefixed table schema. client_users becomes client01_users</p>
<p>Benefits<br />
Someone with intermediate level skills in DB administration could write a simple script to copy client#_* tables to a new DB server in about 5 minutes ( then another hour to sanity check/test/verify). In this way you can push your low traffic clients onto a overbooked server and profit from the infrastructure savings while charging your higher traffic clients for requiring dedicated hardware.</p>
<p>Problems<br />
Maintenance/development time can extend into oblivion and paralyse development entirely if shared nothing techniques don&#8217;t include automation and schema change management systems.<br />
A simple task like adding/dropping a column will take much longer to peform as you have to do it on multiple tables/machines in lockstep to software changes.<br />
Backup&#8217;s get pretty interesting sometimes<br />
Summary<br />
If in the beginning I can see an opportunity for shared nothing, I will fight tooth and nail to get that implemented. For new client&#8217;s with scaling issues, after contracted my initial proposal will include refactoring to incorporate sharding or shared nothing principals. In my mind, the extra complexity can be managed if approached/handled correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/04/15/a-simple-example-of-horizontal-scaling-vs-vertical-scaling-just-with-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pulling cheap tricks with JQuery</title>
		<link>http://ominian.com/2010/03/29/pulling-cheap-tricks-with-jquery/</link>
		<comments>http://ominian.com/2010/03/29/pulling-cheap-tricks-with-jquery/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 10:55:00 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=25</guid>
		<description><![CDATA[Let&#8217;s say you got some tabular data with input button/anchor tags that ideally will cause previously hidden data to appear.
Attempt 1 went like:

&#160;
//Simulated row
&#60;td&#62;
  &#60;a href=&#34;#&#34; onclick=&#34;$('#my_SubData&#60;?= $currentRecordId ?&#62;').slideToggle(); return false&#34;&#62;Click me to show stuff!&#60;/a&#62;&#60;br&#62;
  &#60;div id=&#34;my_SubData&#60;?= $currentRecordId; ?&#62;&#34; style=&#34;display: none &#34;&#62; Blah blah blah....&#60;/div&#62;
&#60;/td&#62;

  I hate messy code, but unfortunately this [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you got some tabular data with input button/anchor tags that ideally will cause previously hidden data to appear.</p>
<p>Attempt 1 went like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">//Simulated row</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;$('#my_SubData&lt;?= $currentRecordId ?&gt;').slideToggle(); return false&quot;</span><span style="color: #339933;">&gt;</span>Click me to show stuff<span style="color: #339933;">!&lt;/</span>a<span style="color: #339933;">&gt;&lt;</span>br<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;my_SubData&lt;?= $currentRecordId; ?&gt;&quot;</span> style<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;display: none &quot;</span><span style="color: #339933;">&gt;</span> Blah blah blah....<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span></pre></div></div>

<p>  I hate messy code, but unfortunately this is PHP so there&#8217;s only so much one borderline pyschotic developer can accomplish.  Or is there?</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">//prior to my table</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.actionable'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>                
                $<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideToggle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Now </span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#my_SubData&lt;?= $currentRecordId ?&gt;')&quot;</span> <span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;actionable&quot;</span><span style="color: #339933;">&gt;</span>Click me to show stuff<span style="color: #339933;">!&lt;/</span>a<span style="color: #339933;">&gt;&lt;</span>br<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;my_SubData&lt;?= $currentRecordId; ?&gt;&quot;</span> style<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;display: none &quot;</span><span style="color: #339933;">&gt;</span> Blah blah blah....<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span></pre></div></div>

<p>It&#8217;s almost elegant if you ignore the PHP inject.   JQuery&#8217;s .live handler automatically routes all unhandled click events to the closest &#8220;.actionable&#8221; classed element, then inside the live event handler, you grab the anchor&#8217;s href value to get the element Id of what you want to edit. </p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/03/29/pulling-cheap-tricks-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stupid PHP tricks: The Array builder</title>
		<link>http://ominian.com/2010/03/22/stupid-php-tricks-the-array-builder/</link>
		<comments>http://ominian.com/2010/03/22/stupid-php-tricks-the-array-builder/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 05:50:46 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=24</guid>
		<description><![CDATA[
class ArrayBuilder &#123;
    public function __set&#40;$name, $value&#41;&#123;
        return $this-&#62;$name = $value;
    &#125;
&#160;
    public function __call&#40;$name, $value&#41;&#123;
        if&#40;count&#40;$value&#41; == 1&#41;&#123;
            $this-&#62;$name = [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ArrayBuilder <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> toArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">get_object_vars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> FACTORY<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> ArrayBuilder<span style="color: #339933;">::</span><span style="color: #004000;">FACTORY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hello</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;World&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">digits</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">foo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;BaR?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;hello&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;World&quot;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;digits&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
    int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
    int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
    int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
    int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
    int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=&gt;</span>
  string<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&quot;BaR?&quot;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Works great for factory scenarios and confusing the $*&#038;!  out of the unwary.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/03/22/stupid-php-tricks-the-array-builder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hosting local, the ghetto fabulous way</title>
		<link>http://ominian.com/2010/03/05/hosting-local-the-ghetto-fabulous-way/</link>
		<comments>http://ominian.com/2010/03/05/hosting-local-the-ghetto-fabulous-way/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 10:31:47 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[simpleCodeTricks]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=17</guid>
		<description><![CDATA[   One of the first big draws of Ruby on Rails in late 2006 was the ability to host my development environment locally.  Not only did this cut down on the chore work of developing in an environment, but it probably also boosted productivity for me substantially.  A year later when [...]]]></description>
			<content:encoded><![CDATA[<p>   One of the first big draws of Ruby on Rails in late 2006 was the ability to host my development environment locally.  Not only did this cut down on the chore work of developing in an environment, but it probably also boosted productivity for me substantially.  A year later when I started teaching myself Python, another nail was hammered into the coffin that is my opinion of PHP.   That said, I&#8217;ve toyed with a lot of different idea&#8217;s of hosting a PHP environment locally but to a degree stymied in the effort.<br />
<span id="more-17"></span><br />
   Late last year I asked on <a href="http://stackoverflow.com/questions/1679084/lightweight-development-web-server-with-support-for-php-v2">Stack overflow</a> a question of how to accomplish the above for PHP.  Results were somewhat mixed and it looks like everyone who provided an answer was ultimately punished for their effort.  As of March 5, 2010 the only answer with a positive vote is because I up voted it up.</p>
<p>   Now a few months down the road, I&#8217;ve been playing with a much simpler approach using Lighttpd.  It&#8217;s not perfect for a couple reasons I will point out&#8230;but good enough for me, for now.</p>
<pre>
# default document-root
  var.baseDir = var.CWD
  server.document-root = var.baseDir + "/"
   index-file.names   = ( "index.php", "index.html", "index.htm", "default.htm" )

  # TCP port
  server.port = 8000

  # selecting modules
  server.modules = ("mod_rewrite", "mod_accesslog", "mod_fastcgi")

  #logs
  accesslog.filename = var.baseDir + "/access.log"
  server.errorlog = var.baseDir + "/error.log"

    server.dir-listing = "enable"
    mimetype.use-xattr = "enable"
    mimetype.assign = (
  ".html" => "text/html",
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png",
  ".js" => "text/javascript"
  )

  static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
  fastcgi.server = (
  ".php" =>
  (( "host" => "127.0.0.1",
     "port" => 9000,
      "bin-path" => "/usr/bin/php5-cgi"
  )))
</pre>
<p>   What seems like a lifetime ago, I was <em>the</em> database administrator for a very heavily trafficked web SaaS site.  One thing I remembered vividly was that for a poorly configured development instance of MySQL, random logging and utility files would crop up in strange places.  Since I was already spending a good portion of my life at that time with MySQL, I spent some extra time to figure out that these files were showing up because my.cnf was configured with relative file paths.  Taking that memory alongside my habit of relaying on document relative paths in Apache, I wondered if I could do the same for lighttpd.</p>
<p>   Turns out you can actually.  So using the above template, I can host arbitrary locations in my /home directory by simply running &#8220;lighttpd -f lighttpd.conf -D&#8221; which translates out to:  Lighttp&#8217;y run using this specific configuration file ( -F lighttpd.conf ) in the current PWD and stay resident to the console -D so I can shut you down later&#8221;</p>
<h2>Problems</h2>
<p>    Unless you change the local config file to something else, you can&#8217;t run two instances of lighttp&#8217;y concurrently.  First reason is that the second instance would try to listen to the same port for http traffic.  This is pretty easy to fix, just change sever.port to some other port #.   The second problem is that fastcgi.server also has to have it&#8217;s own port to listen for fastcgi traffic.</p>
<p>    Also, it might not be to obvious, but if you ran the above config on a non-firewalled, internet homed box, someone could find your development environment and possibly cause havoc.</p>
<h2>Solutions</h2>
<p>    The first problem is a doozy that won&#8217;t have an easy fix&#8230; and its debatable whether investing time to come up with a fix.</p>
<p>   Second problem is stupid easy by adding:</p>
<pre>
   server.bind = "127.0.0.1"
</pre>
<p>  to tell your instance to home on the loopback address.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/03/05/hosting-local-the-ghetto-fabulous-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bridging the gap:  GIT &amp; SVN, B.F.F.</title>
		<link>http://ominian.com/2010/03/02/bridging-the-gap-git-svn-b-f-f/</link>
		<comments>http://ominian.com/2010/03/02/bridging-the-gap-git-svn-b-f-f/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 05:24:29 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=14</guid>
		<description><![CDATA[Background
  I&#8217;ve been using SVN for several years now, since late 2005 or early 2006, and its done me well since then.  But a new darling has entered my life and its name is Git.  I like git for some very specific reasons:  It&#8217;s stupid easy to work with and as [...]]]></description>
			<content:encoded><![CDATA[<h3>Background</h3>
<p>  I&#8217;ve been using SVN for several years now, since late 2005 or early 2006, and its done me well since then.  But a new darling has entered my life and its name is Git.  I like git for some very specific reasons:  It&#8217;s stupid easy to work with and as good or better then SVN for reliability.  Also it helps that my preferred IDE, Komodo, recognizes and works with Git as well.<br />
   That said, I use google code for hosting my public projects and it only supports SVN and HG.  So one night I read up on git and noticed that it had a plugin/support for bridging to a SVN managed repo.  So began my journey.<br />
<span id="more-14"></span></p>
<p>!Note &#8211; I am using a client side credentials manager, if access to your repo requires authentication credentials you will need to supply them where appropriate.</p>
<h3>Initialization</h3>
<p>Bridging a new Git Repo to a new directory in SVN<br />
Step 1:</p>
<pre>
$svn mkdir https://devdave.googlecode.com/svn/trunk/javascript/canvastag/cnvLib

Committed revision 26.
</pre>
<p>      Now I&#8217;ve got a fresh/empty svn directory</p>
<pre>
   $git svn init https://devdave.googlecode.com/svn/trunk/javascript/canvastag/cnvLib
   Initialized empty Git repository in ~/dev/javascript/cnvLib/.git/
</pre>
<p>      Now I&#8217;ve got a local git repo that has most of the information I need for the bridge, to verify everything is hunky dory so far:</p>
<pre>
    $git svn fetch
    #r26 = a47a908ea96bec2d737f6646c47418778ce6ad32 (git-svn)
</pre>
<p><a href="http://ominian.com/wp-content/uploads/2010/03/cnvLib_initial.jpeg"><img src="http://ominian.com/wp-content/uploads/2010/03/cnvLib_initial-300x130.jpg" alt="Before the graft" title="Before the graft" width="300" height="130" class="alignnone size-medium wp-image-16" /></a></p>
<h3>Final steps, the graft</h3>
<p>Some tutorials out there say you should run git svn rebase or such, but doing so has gone poorly for me with results like </p>
<pre>
$ git svn rebase
      fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
      Use '--' to separate paths from revisions
      log --no-color --first-parent --pretty=medium HEAD: command returned error: 128
</pre>
<p>  I believe the problem relates to lining up your local Git repository with the remote SVN repository.   Unfortunately I was somewhat stuck in trying to figure out how the hell to fix this problem for a long time.  Fortunately Google search is the modern day version of a genie, it can grant you the information you seek, but first you have to know what to ask.  Which led me to finding <a href="http://eikke.com/importing-a-git-tree-into-a-subversion-repository/">this</a> blog post.</p>
<p>  I am not doing things &#8220;exactly&#8221; like the aforementioned blog, but close enough that I can get a similar result.</p>
<pre>
$ git show-ref
2a41e85e0dc264cfdb6c04b59547a3093c02f64f refs/heads/master
a47a908ea96bec2d737f6646c47418778ce6ad32 refs/remotes/git-svn
$ git log --pretty=oneline master
2a41e85e0dc264cfdb6c04b59547a3093c02f64f Initial import, copied from ping project
$ echo "2a41e85e0dc264cfdb6c04b59547a3093c02f64f a47a908ea96bec2d737f6646c47418778ce6ad32" >> .git/info/grafts
</pre>
<p><a href="http://ominian.com/wp-content/uploads/2010/03/cnvLib_aftergraft.jpeg"><img src="http://ominian.com/wp-content/uploads/2010/03/cnvLib_aftergraft-300x130.jpg" alt="After the Graft" title="After the Graft" width="300" height="130" class="alignnone size-medium wp-image-15" /></a>       </p>
<p>Since I am doing things a little odd/differently, there is no &#8220;trunk&#8221; branch available.  But the idea is close enough to duplicate.  I&#8217;ve already made some add/commit&#8217;s to my local Git repo but there isn&#8217;t a logical way to tell git/git-svn that this local commit also belongs to my remote SVN remote.  A more human friendly version of git show-ref is<br />
available via:</p>
<pre>
$ git branch -a
* master
  remotes/git-svn
</pre>
<p>So the concatenation of the two internal reference&#8217;s into .git/info/graft helps git-svn understand that the two separate repositories belong to each other.   Sometimes it&#8217;s nice when a configuration structure does what it&#8217;s called.</p>
<p>That said, on to the next obvious step, actually pushing changes from a local Git repo to SVN.</p>
<pre>
$ git svn dcommit
Committing to https://devdave.googlecode.com/svn/trunk/javascript/canvastag/cnvLib ...
        A       app.canvas.js
        A       app.input.js
        A       app.main.js
        A       app.mainloop.js
        A       app.shapes.js
Committed r27
        A       app.canvas.js
        A       app.mainloop.js
        A       app.input.js
        A       app.shapes.js
        A       app.main.js
r27 = ae1cd1055deffe4209ab89d1316c97336c731c39 (git-svn)
No changes between current HEAD and refs/remotes/git-svn
Resetting to the latest refs/remotes/git-svn
</pre>
<h2>What&#8217;s going on here?</h2>
<p>    As I am still learning the finer points of Git, it was important to me to understand what exactly .git/info/grafts does.  So turning to my favorite resource for arbitrary questions&#8230; I found an answer on Stack overflow: <a href="http://stackoverflow.com/questions/161928/what-are-git-info-grafts-for">What are git info grafts for</a>?   And a more official answer in the Git Wiki <a href="http://git.wiki.kernel.org/index.php/GraftPoint">http://git.wiki.kernel.org/index.php/GraftPoint</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/03/02/bridging-the-gap-git-svn-b-f-f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
