<?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; Uncategorized</title>
	<atom:link href="http://ominian.com/category/uncategorized/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>Canvas tag: Collision detection &amp; pixel decay</title>
		<link>http://ominian.com/2010/03/02/canvas-tag-collision-detection-pixel-decay/</link>
		<comments>http://ominian.com/2010/03/02/canvas-tag-collision-detection-pixel-decay/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 22:49:55 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=13</guid>
		<description><![CDATA[Continuing my tests/experiments with the Canvas tag has led to the Ping prototype.  I had 3 minimal things I wanted to accomplish:  Detecting the intersection of a 360 degree arc of ray/line segments to previously defined in map shapes; a visual decay/fade out of intersection points on the canvas, and lastly a test [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing my tests/experiments with the Canvas tag has led to the <a href="http://ominian.com/examples/js/canvastag/ping">Ping prototype</a>.  I had 3 minimal things I wanted to accomplish:  Detecting the intersection of a 360 degree arc of ray/line segments to previously defined in map shapes; a visual decay/fade out of intersection points on the canvas, and lastly a test of performance.  In addition I decided to experiment with another approach to Javascript object construction in the hopes of getting a performance gain.<br />
<span id="more-13"></span><br />
<strong> performance</strong><br />
None of the code involved is optimized or really geared towards performance [ I am using JQuery.each(array|object, function() ) ] and a fairly inefficient pattern for determining intersection ( leveraging CPU with little or no caching ) but was mostly happy with the results when using Google Chrome on Ubuntu 9.10 and utterly surprised with Firefox 3.5 &amp; 3.6 on the same system.  It was literally a night and day difference with Chrome purring along and Firefox struggling to keep up.</p>
<p><strong>JS Objects</strong></p>
<p>Besides the canvas tag related stuff, I was experimenting with another approach to class construction that for the moment seems to goofy to be viable.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">appLib.<span style="color: #660066;">Point</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> y<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
app.<span style="color: #660066;">w</span><span style="color: #009900;">&#40;</span>appLib.<span style="color: #660066;">Point</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>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dist</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> tX <span style="color: #339933;">=</span> Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> o.<span style="color: #660066;">x</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> tY <span style="color: #339933;">=</span> Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> o.<span style="color: #660066;">y</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">sqrt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>tX<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>tY<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     *Bad design choice
     *@deprecated */</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">slope</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> o.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> o.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>app.w( scope, anonymous) basically makes this in context of the anonymous function == scope.prototype.  Therefore making it easier to add prototypical methods to the final product.  My thought was to avoid closure based creation and rely on Function.prototype.method = function to make the objects leaner/faster.  I figured that Javascript engines have already been optimized to a degree to build an object from it&#8217;s prototype.   From my perspective, there didn&#8217;t seem to be a noticeable difference.</p>
<p><strong>Final thoughts</strong><br />
Ping functions as expected on Chrome but otherwise if not for my quad-core environment, I imagine it would be a rather abysmal user experience.  According to top and Chrome&#8217;s built in task manager, its devouring near 100% cpu time and has a semi-stable memory leak ( drifting up and down around 1,500 KB ever 30 seconds ) when in a resting state.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/03/02/canvas-tag-collision-detection-pixel-decay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing with canvas tag</title>
		<link>http://ominian.com/2010/02/22/playing-with-canvas-tag/</link>
		<comments>http://ominian.com/2010/02/22/playing-with-canvas-tag/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 08:05:49 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=12</guid>
		<description><![CDATA[   I am taking a break from the server code to give me sometime to think about how I want to resolve some of the issues that Rob N. @ Bivio software pointed out to me.  In the interim, I&#8217;ve moved back to the making games theme.

LunarLander &#8211; Rough draft Project page
 [...]]]></description>
			<content:encoded><![CDATA[<p>   I am taking a break from the server code to give me sometime to think about how I want to resolve some of the issues that Rob N. @ Bivio software pointed out to me.  In the interim, I&#8217;ve moved back to the making games theme.<br />
<span id="more-12"></span><br />
LunarLander &#8211; Rough draft <a href="http://code.google.com/p/devdave/wiki/LunarLander">Project page</a></p>
<p>    This will be the third time I&#8217;ve implemented a Lunar lander simulation game; the first was in C++ using inline ASM and mode 13H as my graphics interface.  Fun stuff.  The second was in Java in the late 90&#8217;s and not so fun ( My last line of Java was 2000 for a reason).   Now comes the third iteration, implemeneted in Javascript using the Canvas tag.  Overall the experience wasn&#8217;t so bad, I was initially <del datetime="2010-02-22T05:06:22+00:00">frustrated</del> annoyed at the lack of a simple putPixel like mechanism, but canvasContext2d.arc or rect with a size/width of 1 pixel is a relatively good substitute.</p>
<p>    I decided to go with a run loop pattern instead of a tickless/event driven mechanism.  Sure, a tickless system is more efficient ( avoiding unecessary redraws ) but it&#8217;s also a tad more complicated and prone to error.  Also, I am relying HEAVILY on JIT javascript interpreters to make the MainLoop class efficient.  Normally you want to minimize as much as possible unnecessary function calls but MainLoop&#8217;s logic handler has a stack and list mechanism that it iterates over, every tick.<br />
    The list is a constant actions function, every tick the logic handler calls each element which is an anonymous function.  In Lunar lander I used this to split off the status board in two,  key state&#8217;s being handled by an anonymous function, while the other stats are handled by the Game logic class itself.<br />
    The stack on the other hand will be used for staggered events, one anonymous function being popped off and executed per tick.  Some in-efficient idea&#8217;s for using it would be for animation effects.  Push 10 actions onto the stack, each action drawing say an explosion image frame in progressing fashion.</p>
<p>    LunarLander&#8217;s logic add&#8217;s a hook onto MainLoop&#8217;s constant action list and from there its pretty straight forward.  Every tick, add a gravity value amount to the Y delta velocity, then add this to the current Y position.  If Y is > then the height of the screen, then the lander has crashed/landed.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/02/22/playing-with-canvas-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
