<?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; development</title>
	<atom:link href="http://ominian.com/tag/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://ominian.com</link>
	<description>PyMethius project notes</description>
	<lastBuildDate>Mon, 06 Feb 2012 17:56:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>metaclass service bus decorator concept</title>
		<link>http://ominian.com/2011/08/25/metaclass-service-bus-decorator-concept/</link>
		<comments>http://ominian.com/2011/08/25/metaclass-service-bus-decorator-concept/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 01:28:57 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[metaclass]]></category>
		<category><![CDATA[oh_snap]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=140</guid>
		<description><![CDATA[While playing around with some idea&#8217;s for making PyProxy completely overridable ( and also potentially undebuggable ) I started playing around with metaclasses. Below is from my toxic directory [ gist url ] from collections import defaultdict from functools import wraps Just some preliminary basic utilities A simple bus implementation, decoratedCalls is a dictionary of <a href='http://ominian.com/2011/08/25/metaclass-service-bus-decorator-concept/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>While playing around with some idea&#8217;s for making PyProxy completely overridable ( and also potentially undebuggable ) I started playing around with metaclasses.</p>
<p>Below is from my toxic directory [ <a href="https://gist.github.com/1172478">gist url</a> ]</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">collections</span> <span style="color: #ff7700;font-weight:bold;">import</span> defaultdict
<span style="color: #ff7700;font-weight:bold;">from</span> functools <span style="color: #ff7700;font-weight:bold;">import</span> wraps</pre></div></div>

<p>Just some preliminary basic utilities</p>
<p>A simple bus implementation, decoratedCalls is a dictionary of service calls, with a list<br />
of callbacks to each service call hook.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">decoratedCalls = defaultdict<span style="color: black;">&#40;</span><span style="color: #008000;">list</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> call<span style="color: black;">&#40;</span>name, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> name, args, kwargs
    <span style="color: #ff7700;font-weight:bold;">if</span> name <span style="color: #ff7700;font-weight:bold;">in</span> decoratedCalls:
        <span style="color: #ff7700;font-weight:bold;">for</span> cb <span style="color: #ff7700;font-weight:bold;">in</span> decoratedCalls<span style="color: black;">&#91;</span>name<span style="color: black;">&#93;</span>:
            cb<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span></pre></div></div>

<p>Syntactic suger to add clarity later as to what functions are being bound to what.  Adding in<br />
debug/logging hooks here could allow for easier tracing of what is called for what methods.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> Subscribe<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">name</span> = name
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__call__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, f<span style="color: black;">&#41;</span>:
        decoratedCalls<span style="color: black;">&#91;</span><span style="color: #008000;">self</span>.<span style="color: black;">name</span><span style="color: black;">&#93;</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> f</pre></div></div>

<p>Here&#8217;s the actual bus decorator, very simple just wraps the decorated function with a pre and post bus calls.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> BusDecorator<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">name</span> = name
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__call__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, f<span style="color: black;">&#41;</span>:
&nbsp;
        @wraps<span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">def</span> decorator<span style="color: black;">&#40;</span>inst, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
            call<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s-pre&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">self</span>.<span style="color: black;">name</span>, inst, args, kwargs<span style="color: black;">&#41;</span>            
            retval = f<span style="color: black;">&#40;</span>inst, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
            call<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s-post&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">self</span>.<span style="color: black;">name</span>, inst, retval<span style="color: black;">&#41;</span>            
            <span style="color: #ff7700;font-weight:bold;">return</span> retval
        <span style="color: #ff7700;font-weight:bold;">return</span> decorator</pre></div></div>

<p>And here&#8217;s my Bus Metaclass that combines most of the above.</p>
<p><em>The ease of wrapping the target class is accomplished by cdict which is a dictionary of<br />
every defined attribute of the target class.  As you can see it&#8217;s trivial to spin<br />
through and decorate every callable with the BusDecorator</em></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> BusWrap<span style="color: black;">&#40;</span><span style="color: #008000;">type</span><span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__new__</span><span style="color: black;">&#40;</span>mcs, clsname, bases, cdict<span style="color: black;">&#41;</span>:
&nbsp;
        modName = cdict.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;__module__&quot;</span>, <span style="color: #483d8b;">&quot;unknownclass&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">for</span> name <span style="color: #ff7700;font-weight:bold;">in</span> cdict.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
            prefix = <span style="color: #483d8b;">&quot;%s.%s.%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span> modName, clsname, name<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">callable</span><span style="color: black;">&#40;</span>cdict<span style="color: black;">&#91;</span>name<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:                
                cdict<span style="color: black;">&#91;</span>name<span style="color: black;">&#93;</span> = BusDecorator<span style="color: black;">&#40;</span>prefix<span style="color: black;">&#41;</span><span style="color: black;">&#40;</span>cdict<span style="color: black;">&#91;</span>name<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">type</span>.<span style="color: #0000cd;">__new__</span><span style="color: black;">&#40;</span>mcs, name, bases, cdict<span style="color: black;">&#41;</span></pre></div></div>

<p>Now give a dirt simple class like</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Foo<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #0000cd;">__metaclass__</span> = BusWrap
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;init'd&quot;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> bar<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;bar&quot;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> blah<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;blah&quot;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> ich<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;ich&quot;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> ego<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;lego&quot;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> say<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">*</span>args<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Saying &quot;</span>, args</pre></div></div>

<p>And two service handlers to pre Foo.bar being called and after Foo.ego is called</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
@Subscribe<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;__main__.Foo.bar-pre&quot;</span><span style="color: black;">&#41;</span>        
<span style="color: #ff7700;font-weight:bold;">def</span> preBar<span style="color: black;">&#40;</span>inst, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">hasattr</span><span style="color: black;">&#40;</span>inst, <span style="color: #483d8b;">&quot;ext_info&quot;</span><span style="color: black;">&#41;</span>:
        inst.<span style="color: black;">ext_info</span> = <span style="color: #483d8b;">&quot;Here&quot;</span>
&nbsp;
@Subscribe<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;__main__.Foo.ego-post&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> postEgo<span style="color: black;">&#40;</span>inst, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">hasattr</span><span style="color: black;">&#40;</span>inst, <span style="color: #483d8b;">&quot;ext_info&quot;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Extended info is &quot;</span>, inst.<span style="color: black;">ext_info</span></pre></div></div>

<p>Our test shows&#8230;.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">x = Foo<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
x.<span style="color: black;">bar</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
x.<span style="color: black;">blah</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
x.<span style="color: black;">ich</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
x.<span style="color: black;">ego</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
x.<span style="color: black;">say</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;abba&quot;</span>, <span style="color: #483d8b;">&quot;dabba&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>this as output</p>
<pre>
__main__.Foo.__init__-pre (<__main__.__init__ object at 0x02637890>, (), {}) {}
init'd
__main__.Foo.__init__-post (<__main__.__init__ object at 0x02637890>, None) {}
__main__.Foo.bar-pre (<__main__.__init__ object at 0x02637890>, (), {}) {}
bar
__main__.Foo.bar-post (<__main__.__init__ object at 0x02637890>, None) {}
__main__.Foo.blah-pre (<__main__.__init__ object at 0x02637890>, (), {}) {}
blah
__main__.Foo.blah-post (<__main__.__init__ object at 0x02637890>, None) {}
__main__.Foo.ich-pre (<__main__.__init__ object at 0x02637890>, (), {}) {}
ich
__main__.Foo.ich-post (<__main__.__init__ object at 0x02637890>, None) {}
__main__.Foo.ego-pre (<__main__.__init__ object at 0x02637890>, (), {}) {}
lego
__main__.Foo.ego-post (<__main__.__init__ object at 0x02637890>, None) {}
Extended info is  Here
__main__.Foo.say-pre (<__main__.__init__ object at 0x02637890>, ('abba', 'dabba'), {}) {}
Saying  ('abba', 'dabba')
__main__.Foo.say-post (<__main__.__init__ object at 0x02637890>, None) {}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/08/25/metaclass-service-bus-decorator-concept/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TxWeb Alpha &#8211; A different spin on twisted.web</title>
		<link>http://ominian.com/2011/07/29/txweb-alpha-a-different-spin-on-twisted-web/</link>
		<comments>http://ominian.com/2011/07/29/txweb-alpha-a-different-spin-on-twisted-web/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 06:50:52 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[twisted]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=137</guid>
		<description><![CDATA[I&#8217;ve spent some more time on my current pet, txweb, and I think it&#8217;s pretty much at the as good as it gets stage. Below is the source for the example.py &#160; #App level from txweb import Site, expose #twisted from twisted.web import server, resource from twisted.internet import reactor from twisted.web.static import File &#160; from <a href='http://ominian.com/2011/07/29/txweb-alpha-a-different-spin-on-twisted-web/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent some more time on my current pet, <a href="https://github.com/devdave/txWeb">txweb</a>, and I think it&#8217;s pretty much at the as good as it gets stage.</p>
<p>Below is the source for the <a href="https://github.com/devdave/txWeb/blob/master/example.py">example.py</a></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">#App level</span>
<span style="color: #ff7700;font-weight:bold;">from</span> txweb <span style="color: #ff7700;font-weight:bold;">import</span> Site, expose
<span style="color: #808080; font-style: italic;">#twisted</span>
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">web</span> <span style="color: #ff7700;font-weight:bold;">import</span> server, <span style="color: #dc143c;">resource</span>
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">internet</span> <span style="color: #ff7700;font-weight:bold;">import</span> reactor
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">web</span>.<span style="color: black;">static</span> <span style="color: #ff7700;font-weight:bold;">import</span> File
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span> <span style="color: #ff7700;font-weight:bold;">import</span> abspath, dirname, join</pre></div></div>

<p>Mostly pretty standard imports for a twisted.web application.</p>
<p>Now here is the &#8220;Controllers&#8221;, they&#8217;re stripped down to bare-bones just to keep it simple</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> PageOne<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
&nbsp;
    @expose
    <span style="color: #ff7700;font-weight:bold;">def</span> foo<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, request<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;Hello From PageOne Foo!&quot;</span>        
&nbsp;
    @expose
    <span style="color: #ff7700;font-weight:bold;">def</span> delayed<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, request<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">def</span> delayedResponse<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
            request.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;I was delayed :( &quot;</span><span style="color: black;">&#41;</span>
            request.<span style="color: black;">finish</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        reactor.<span style="color: black;">callLater</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span>, delayedResponse<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> server.<span style="color: black;">NOT_DONE_YET</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> PageTwo<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
&nbsp;
    @expose
    <span style="color: #ff7700;font-weight:bold;">def</span> index<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, request<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot; /pagetwo/index &quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;Hello From PageTwo index!&quot;</span>
&nbsp;
&nbsp;
rootFile = <span style="color: #ff7700;font-weight:bold;">lambda</span> filename : abspath<span style="color: black;">&#40;</span>join<span style="color: black;">&#40;</span>dirname<span style="color: black;">&#40;</span>__file__<span style="color: black;">&#41;</span>, filename<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Root<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
&nbsp;
    @expose
    <span style="color: #ff7700;font-weight:bold;">def</span> index<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, request<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;
            Will handle both / and /index paths
        &quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;Hello From Index!&quot;</span>
&nbsp;
    @expose
    <span style="color: #ff7700;font-weight:bold;">def</span> __default__<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, request<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;
            Unless overriden further down, this will catch all 404's
        &quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;I Caught %s &quot;</span> <span style="color: #66cc66;">%</span> request.<span style="color: black;">path</span>
&nbsp;
    pageone = PageOne<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    pagetwo = PageTwo<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    readme  = File<span style="color: black;">&#40;</span>rootFile<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;README.md&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    license = File<span style="color: black;">&#40;</span>rootFile<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;txweb/LICENSE.txt&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Basically a txWeb enabled twisted service converts a URL path to an Object path.</p>
<p>So /hello/world  could resolve to root.hello.world() if such a construct was provided.</p>
<p>Much more importantly, with the above example,  /license resolves to the local file txweb/LICENSE and /readme resolves to README.md !  </p>
<p>In summary txweb doesn&#8217;t throw away the epic amount of work the Twisted developers and volunteers have put forth, it just presents it in another way.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/07/29/txweb-alpha-a-different-spin-on-twisted-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyProxy &#8211; Aka the development Helper proxy</title>
		<link>http://ominian.com/2011/07/01/pyproxy-aka-the-development-helper-proxy/</link>
		<comments>http://ominian.com/2011/07/01/pyproxy-aka-the-development-helper-proxy/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 16:57:10 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[utilities]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=125</guid>
		<description><![CDATA[Coming out of nothing and into supah doopa Alpha is finally a working proof of concept of my python web proxy. I don&#8217;t really want to talk about the asinine alternatives I&#8217;ve tried until I finally said &#8220;fuck it, time to go completely twisted!&#8221; Low and behold the actual proxy part is 4 lines of <a href='http://ominian.com/2011/07/01/pyproxy-aka-the-development-helper-proxy/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Coming out of nothing and into <a href="http://www.youtube.com/watch?v=m6rqXHX3O48">supah doopa</a> Alpha is finally a working proof of concept of my python web proxy.  I don&#8217;t really want to talk about the asinine alternatives I&#8217;ve tried until I finally said &#8220;fuck it, time to go completely twisted!&#8221;   Low and behold the actual proxy part is 4 lines of code, which is then expanded to maybe 20-30 to allow for overloading some lower level classes.</p>
<p>Originally a public announcement for this project would have been in August at the earliest, give me time to clean things up and go from proof of concept to working concept but apparently a lot of other people have similar thoughts and I figured it&#8217;s better to collaborate then compete.</p>
<p>So some quick notes:<br />
The ultimate goal for PyProxy ( or whatever it ends up being named ) is to sit between a developer and a development server.  The first and immediate idea for this was to automagically parse out Python mechanize scripts to replicate the traffic.  These mechanize scripts could then be collected into a suite, marking other scripts as requirements ( example login  process ).  That alone would make it pretty easy to create full system under test unit-tests.   The next idea was to add in regex or pattern based hooks that could allow a developer to dial in to a specific domain, or even a specific set of webpages.</p>
<p>After that, the idea was to just continually tack on support plugins and scripts, maybe tell PyProxy the name of the target application&#8217;s database, and if it&#8217;s MySQL, switch on the general log.  This could allow for combining both mechanize scripts AND a SQLObject or SQLAlchemy powered unit-test suite to assert that the correct data was changed.</p>
<p>The final future idea was to make a Firefox/Chrome extension that would allow a developer to control some parts of the proxy from their browser and also see additional information.  For Python and PHP web apps, imagine have a finalization plugin that appended a response header listing all File&#8217;s used to perform a request&#8230;. then imagine having a &#8220;click to edit&#8221; button that, if the dev. instance is workstation local, would have your favorite IDE open the specified file for editing.</p>
<p>All in all, I think these are really subtle idea&#8217;s that if combined together, would cut down some mudane parts of developing a web app.</p>
<p>GitHub repo (https://github.com/devdave/PyProxy) <a href="https://github.com/devdave/PyProxy">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/07/01/pyproxy-aka-the-development-helper-proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Komodo IDE auto-generating setters/getters for PHP</title>
		<link>http://ominian.com/2011/06/01/komodo-ide-auto-generating-settersgetters-for-php/</link>
		<comments>http://ominian.com/2011/06/01/komodo-ide-auto-generating-settersgetters-for-php/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 22:29:57 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[oh_snap]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=113</guid>
		<description><![CDATA[I&#8217;ve got about thirty auto-generated PHP Doctrine models that are missing their required Java style setters/getters. At class number three of typing in these accessory methods I snapped and said &#8220;There has to be a better way&#8221; and magically the universe smacked me upside the head and reminded me that I&#8217;m using Komodo IDE which <a href='http://ominian.com/2011/06/01/komodo-ide-auto-generating-settersgetters-for-php/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>  I&#8217;ve got about thirty auto-generated PHP Doctrine models that are missing their required Java style setters/getters.   At class number three of typing in these accessory methods I snapped and said &#8220;There has to be a better way&#8221; and magically the universe smacked me upside the head and reminded me that I&#8217;m using Komodo IDE which just so happens to have a disgustingly powerful Python powered macro system.</p>
<p>   Four minutes later, out came the copy &#038; paste hacked together monstrosity below.  It&#8217;s not perfect but it doesn&#8217;t need to be, just has to work well enough to save my sanity and my client&#8217;s time.</p>
<p>To use, follow Komodo&#8217;s help documentation for creating a new python Macro then copy and paste this code into the macro window OR a slightly easier way, make the macro then click the &#8220;edit macro&#8221; context menu property to open the macro source file as a new view in Komodo.</p>
<p>The macro uses some very simple rules.  It&#8217;s only looking for private properties in a format of &#8220;^\s*private \$[a-zA-Z0-9_]$&#8221;, it collects all of these variable names and then appends them through the setter and getter templates to a string buffer.  Finally the buffer is<br />
inserted into the current document at the position of the cursor.   The output is coherent but not whitespace friendly which isn&#8217;t too big of a deal to re-format.   Note, the macro has no concept of PHP syntax, so if there is more then one class in a file, the results will not be desirable.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> xpcom <span style="color: #ff7700;font-weight:bold;">import</span> components
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
&nbsp;
viewSvc = components.<span style="color: black;">classes</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;@activestate.com/koViewService;1&quot;</span><span style="color: black;">&#93;</span>\
    .<span style="color: black;">getService</span><span style="color: black;">&#40;</span>components.<span style="color: black;">interfaces</span>.<span style="color: black;">koIViewService</span><span style="color: black;">&#41;</span>
view = viewSvc.<span style="color: black;">currentView</span>.<span style="color: black;">queryInterface</span><span style="color: black;">&#40;</span>components.<span style="color: black;">interfaces</span>.<span style="color: black;">koIScintillaView</span><span style="color: black;">&#41;</span>
&nbsp;
sm = view.<span style="color: black;">scimoz</span>
sm.<span style="color: black;">currentPos</span>   <span style="color: #808080; font-style: italic;"># current position in the editor</span>
sm.<span style="color: black;">text</span>         <span style="color: #808080; font-style: italic;"># editor text</span>
sm.<span style="color: black;">selText</span>      <span style="color: #808080; font-style: italic;"># the selected text</span>
<span style="color: #808080; font-style: italic;">#sm.text = &quot;Hello World!&quot;</span>
&nbsp;
output = u<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
setterTemplate = <span style="color: #483d8b;">&quot;&quot;&quot;
    function set%s($value){
        $this-&gt;%s = $value;
    }
&quot;&quot;&quot;</span>
&nbsp;
getterTemplate = <span style="color: #483d8b;">&quot;&quot;&quot;
    /**
    *@return string
    */
    function get%s(){
        return $this-&gt;%s;
    }
&quot;&quot;&quot;</span>
&nbsp;
propertyTemplate = <span style="color: #483d8b;">&quot;&quot;&quot;
%s
&nbsp;
%s
&quot;&quot;&quot;</span>
&nbsp;
prefixSize = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;private $&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> formalName<span style="color: black;">&#40;</span>rawName<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> u<span style="color: #483d8b;">&quot;%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>part.<span style="color: black;">title</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> part <span style="color: #ff7700;font-weight:bold;">in</span> rawName.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;_&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">#todo find a better way to split lines, what if its Mac or Windows format?</span>
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> sm.<span style="color: black;">text</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> line.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;private $&quot;</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;">#trim of the private $ and trailing semi-colon</span>
        realName = line.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>prefixSize:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>        
        output += propertyTemplate <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span> setterTemplate <span style="color: #66cc66;">%</span><span style="color: black;">&#40;</span>formalName<span style="color: black;">&#40;</span>realName<span style="color: black;">&#41;</span>, realName<span style="color: black;">&#41;</span>, getterTemplate <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>formalName<span style="color: black;">&#40;</span>realName<span style="color: black;">&#41;</span>, realName<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>        
&nbsp;
&nbsp;
&nbsp;
sm.<span style="color: black;">insertText</span><span style="color: black;">&#40;</span>sm.<span style="color: black;">currentPos</span>, output<span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/06/01/komodo-ide-auto-generating-settersgetters-for-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery dataTable plugin quick notes</title>
		<link>http://ominian.com/2011/03/31/jquery-datatable-plugin-quick-notes/</link>
		<comments>http://ominian.com/2011/03/31/jquery-datatable-plugin-quick-notes/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 16:09:34 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[educational]]></category>
		<category><![CDATA[oh_snap]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=97</guid>
		<description><![CDATA[Server-side processing To return the names of the columns you want, you need to use aoColumndefs and provided individual objects with the property sName. Below is most of the implementation for a jeditable Ajax driven dataTables, this is the Alpha version and still needs a lot of love in places, but the gist of it <a href='http://ominian.com/2011/03/31/jquery-datatable-plugin-quick-notes/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h2>Server-side processing</h2>
<p>
   To return the names of the columns you want, you need to use aoColumndefs and provided individual objects with the property sName.
</p>
<p>  Below is most of the implementation for a jeditable Ajax driven dataTables, this is the Alpha version and still needs a lot of love in places, but the gist of it is here</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> semesterTable <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#semesterViewTable&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dataTable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #3366CC;">&quot;bProcessing&quot;</span>   <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
            <span style="color: #339933;">,</span>   <span style="color: #3366CC;">&quot;bServerSide&quot;</span>   <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
            <span style="color: #339933;">,</span>   <span style="color: #3366CC;">&quot;sAjaxSource&quot;</span>   <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&lt;?php echo url_for(&quot;</span>roster<span style="color: #339933;">/</span>ajax<span style="color: #339933;">/</span><span style="color: #009900;">&#123;</span>$semester_id<span style="color: #009900;">&#125;</span><span style="color: #3366CC;">&quot;); ?&gt;&quot;</span>
            <span style="color: #339933;">,</span>   <span style="color: #3366CC;">&quot;fnRowCallback&quot;</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> nRow<span style="color: #339933;">,</span> aData<span style="color: #339933;">,</span> iDisplayIndex<span style="color: #339933;">,</span> iDisplayIndexFull <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                    <span style="color: #006600; font-style: italic;">//console.log(nRow, aData, iDisplayIndex, iDisplayIndexFull);</span>
                                    <span style="color: #003366; font-weight: bold;">var</span> recordId <span style="color: #339933;">=</span> aData<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;td&quot;</span><span style="color: #339933;">,</span> nRow<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;recordId&quot;</span><span style="color: #339933;">,</span> recordId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                    <span style="color: #000066; font-weight: bold;">return</span> nRow<span style="color: #339933;">;</span>
                                <span style="color: #009900;">&#125;</span>
            <span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;fnDrawCallback&quot;</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: #3366CC;">&quot;td.editableMajor&quot;</span><span style="color: #009900;">&#41;</span>
                                        .<span style="color: #660066;">editable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;?php echo url_for(&quot;</span>roster<span style="color: #339933;">/</span>edit_record<span style="color: #3366CC;">&quot;);?&gt;&quot;</span><span style="color: #339933;">,</span>
                                                    <span style="color: #009900;">&#123;</span>                                                        
                                                          loadurl<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&lt;?php echo url_for(&quot;</span>roster<span style="color: #339933;">/</span>distinct<span style="color: #339933;">/</span>major<span style="color: #339933;">/</span><span style="color: #009900;">&#123;</span>$semester_id<span style="color: #009900;">&#125;</span><span style="color: #3366CC;">&quot;) ?&gt;&quot;</span>
                                                        <span style="color: #339933;">,</span> type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;select&quot;</span>
                                                        <span style="color: #339933;">,</span> submit<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;OK&quot;</span>
                                                        <span style="color: #339933;">,</span> method<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;post&quot;</span>
                                                        <span style="color: #339933;">,</span> submitdata<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>
                                                            console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                                            <span style="color: #003366; font-weight: bold;">var</span> $this <span style="color: #339933;">=</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: #339933;">;</span>
                                                            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
                                                                    recordId<span style="color: #339933;">:</span> $this.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;recordId&quot;</span><span style="color: #009900;">&#41;</span>
                                                                    <span style="color: #339933;">,</span> classes<span style="color: #339933;">:</span> $this.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;class&quot;</span><span style="color: #009900;">&#41;</span>
                                                                <span style="color: #009900;">&#125;</span>
                                                        <span style="color: #009900;">&#125;</span>
                                                    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                                <span style="color: #009900;">&#125;</span>
            <span style="color: #009966; font-style: italic;">/* Seriously a meta-generator for this would be nice */</span>
            <span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;aoColumnDefs&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;record_id&quot;</span><span style="color: #339933;">,</span>          aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>00<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> bSearchable<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> bVisible<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_date&quot;</span><span style="color: #339933;">,</span>         aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>01<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_date&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_name_both&quot;</span><span style="color: #339933;">,</span>    aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>02<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_name_both&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_student_id&quot;</span><span style="color: #339933;">,</span>   aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>03<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_student_id&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major1&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>04<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major1 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major2&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>05<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major2 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major3&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>06<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major3 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major4&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>07<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major4 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_minor1&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>08<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_minor1 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_minor2&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>09<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_minor2 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>  For the tbody, just put something like  </p>
<pre>
        &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Chill the fuck out, it's loading&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;
</pre>
<h3>Server side data contract</h3>
<p>dataTables expects a JSON&#8217;ified construct like this</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$responseBody</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">&quot;sEcho&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$input</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sEcho'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;iTotalRecords&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$count</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;iTotalDisplayRecords&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;aaData&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$data</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<ul>
<li> sEcho is a security variable used by dataTables, basically just send it back and don&#8217;t worry about it</li>
<li>iTotalRecords &#8211; is the MAXIMUM # of records in the data set without any filtering</li>
<li>iTotalDisplayRecords &#8211; is the MAXIMUM # of records in the data set WITH filtering</li>
<li>An array of numerically indexed arrays, dataTables doesn&#8217;t like associative arrays</li>
</ul>
<h1>Total and Display total records</h1>
<p>   If the blink tag still worked reliably, I&#8217;d put a neon sign here.   Basically you need to do 3 queries per Ajax call&#8230; call 1 is to get a</p>
<pre>
   SELECT count(1) FROM sourceTABLE
</pre>
<p>call 2 is</p>
<pre> SELECT count(1) FROM sourceTable WHERE someCriteria </pre>
<p> and finally call 3 is</p>
<pre> SELECT yourColumnList FROM sourceTable WHERE someCriteria</pre>
<p>With memcache or such, I&#8217;d advise caching the total count but no matter what you unfortunately need to make these three SQL calls <img src='http://ominian.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/03/31/jquery-datatable-plugin-quick-notes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced collision detection</title>
		<link>http://ominian.com/2011/03/29/advanced-collision-detection/</link>
		<comments>http://ominian.com/2011/03/29/advanced-collision-detection/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 15:43:52 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Game development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[educational]]></category>
		<category><![CDATA[simpleCodeTricks]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=94</guid>
		<description><![CDATA[Unfortunately I haven&#8217;t gotten the chance to completely read this ( http://www.wildbunny.co.uk/blog/2011/03/25/speculative-contacts-an-continuous-collision-engine-approach-part-1/ ) but what I&#8217;ve read has been very educational and potentially useful for future game development. A quick synopsis is that the linked article provides a very well documented approach for dealing with collisions in time. Say you have an object that should <a href='http://ominian.com/2011/03/29/advanced-collision-detection/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Unfortunately I haven&#8217;t gotten the chance to completely read <a href="http://www.wildbunny.co.uk/blog/2011/03/25/speculative-contacts-an-continuous-collision-engine-approach-part-1/" target="_blank">this ( http://www.wildbunny.co.uk/blog/2011/03/25/speculative-contacts-an-continuous-collision-engine-approach-part-1/ )</a> but what I&#8217;ve read has been very educational and potentially useful for future game development.  </p>
<p>A quick synopsis is that the linked article provides a very well documented approach for dealing with collisions in time.  Say you have an object that should have collided with another, but it&#8217;s velocity or translation across the drawing surface is so high that in the time between frames it completely skips over another entity without colliding.  In physical reality there would be a collision, but in computer terms there isn&#8217;t easy logic to detect and resolve these false-negative near misses.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/03/29/advanced-collision-detection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snake game prototype</title>
		<link>http://ominian.com/2011/03/27/snake-game-prototype/</link>
		<comments>http://ominian.com/2011/03/27/snake-game-prototype/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 21:22:03 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[canvas]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[about]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=87</guid>
		<description><![CDATA[Running live here User input is fed off the left &#038; right cursor keys. Ping additions included a formalized Quad tree library into the ping.Lib namespace but I want to fix up the factory function I wrote to take an instance of the Canvas rendering class instead of manually writing out the root dimensions. Otherwise <a href='http://ominian.com/2011/03/27/snake-game-prototype/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Running live <a href="http://ominian.com/examples/js/pinglib/snakes.html">here</a></p>
<p>User input is fed off the left &#038; right cursor keys.</p>
<p>Ping additions included a formalized Quad tree library into the ping.Lib namespace but I want to fix up the factory function I wrote to take an instance of the Canvas rendering class instead of manually writing out the root dimensions.  Otherwise collision checks are still a tad wonky&#8230; there&#8217;s a high propensity for near misses unfortunately <img src='http://ominian.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/03/27/snake-game-prototype/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 I started teaching myself Python, <a href='http://ominian.com/2010/03/05/hosting-local-the-ghetto-fabulous-way/'>[...]</a>]]></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>
	</channel>
</rss>

