<?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>Matt Jones' Blog &#187; Code Fragment</title>
	<atom:link href="http://www.mattjones.workhorsy.org/category/code-fragment/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattjones.workhorsy.org</link>
	<description>Blah You, Blah Me, Blah We</description>
	<lastBuildDate>Fri, 09 Jul 2010 02:50:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Porting Tornado to D</title>
		<link>http://www.mattjones.workhorsy.org/2010/03/12/porting-tornado-to-d/</link>
		<comments>http://www.mattjones.workhorsy.org/2010/03/12/porting-tornado-to-d/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 03:03:53 +0000</pubDate>
		<dc:creator>mattjones</dc:creator>
				<category><![CDATA[Code Fragment]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.mattjones.workhorsy.org/?p=353</guid>
		<description><![CDATA[The other day I started porting the Tornado web server to D. I just got the IO Loop part ported. I&#8217;m planning on using this in my web framework Rootin Tootin.
You can check out the code on Launchpad: http://launchpad.net/dornado. Next I will add proper Epoll and the HTTP part. But in the meantime, you can [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I started porting the <a href="http://tornadoweb.org">Tornado web server</a> to <a href="http://digitalmars.com/d/index.html">D</a>. I just got the IO Loop part ported. I&#8217;m planning on using this in my web framework <a href="http://rootin.toot.in">Rootin Tootin</a>.</p>
<p>You can check out the code on Launchpad: <a href="http://launchpad.net/dornado">http://launchpad.net/dornado</a>. Next I will add proper Epoll and the HTTP part. But in the meantime, you can try it out with this demo code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="d" style="font-family:monospace;"><span style="color: #993333;">private</span> <span style="color: #000000; font-weight: bold;">import</span> tango.<span style="color: #006600;">net</span>.<span style="color: #006600;">device</span>.<span style="color: #006600;">Socket</span><span style="color: #66cc66;">;</span>
<span style="color: #993333;">private</span> <span style="color: #000000; font-weight: bold;">import</span> tango.<span style="color: #006600;">io</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">IConduit</span><span style="color: #66cc66;">;</span>
<span style="color: #993333;">private</span> <span style="color: #000000; font-weight: bold;">import</span> tango.<span style="color: #006600;">net</span>.<span style="color: #006600;">InternetAddress</span><span style="color: #66cc66;">;</span>
<span style="color: #993333;">private</span> <span style="color: #000000; font-weight: bold;">import</span> tango.<span style="color: #006600;">io</span>.<span style="color: #006600;">Stdout</span><span style="color: #66cc66;">;</span>
<span style="color: #993333;">public</span> <span style="color: #000000; font-weight: bold;">import</span> ioloop<span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #993333;">class</span> HelloServer <span style="color: #66cc66;">&#123;</span>
    <span style="color: #993333;">private</span> ServerSocket sock<span style="color: #66cc66;">;</span>
    <span style="color: #993333;">private</span> <span style="color: #993333;">char</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000dd;">1024</span><span style="color: #66cc66;">&#93;</span> buffer<span style="color: #66cc66;">;</span>
&nbsp;
    <span style="color: #993333;">public</span> <span style="color: #993333;">void</span> handle_connection<span style="color: #66cc66;">&#40;</span>Socket connection<span style="color: #66cc66;">,</span> <span style="color: #993333;">char</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> address<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        connection.<span style="color: #006600;">read</span><span style="color: #66cc66;">&#40;</span>buffer<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
        connection.<span style="color: #006600;">write</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;hello world!&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        connection.<span style="color: #006600;">shutdown</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        connection.<span style="color: #006600;">detach</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #993333;">public</span> <span style="color: #993333;">void</span> connection_ready<span style="color: #66cc66;">&#40;</span>ServerSocket sock<span style="color: #66cc66;">,</span> ISelectable.<span style="color: #006600;">Handle</span> fd<span style="color: #66cc66;">,</span> <span style="color: #993333;">uint</span> events<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            Socket connection <span style="color: #66cc66;">=</span> sock.<span style="color: #006600;">accept</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
            connection.<span style="color: #006600;">socket</span>.<span style="color: #006600;">blocking</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
            handle_connection<span style="color: #66cc66;">&#40;</span>connection<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #993333;">public</span> <span style="color: #993333;">void</span> call_connection_ready<span style="color: #66cc66;">&#40;</span>ISelectable.<span style="color: #006600;">Handle</span> fd<span style="color: #66cc66;">,</span> <span style="color: #993333;">uint</span> events<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        connection_ready<span style="color: #66cc66;">&#40;</span>sock<span style="color: #66cc66;">,</span> fd<span style="color: #66cc66;">,</span> events<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #993333;">public</span> <span style="color: #993333;">void</span> start<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #993333;">int</span> port <span style="color: #66cc66;">=</span> <span style="color: #0000dd;">3000</span><span style="color: #66cc66;">;</span>
        <span style="color: #993333;">int</span> max_waiting_clients <span style="color: #66cc66;">=</span> <span style="color: #0000dd;">128</span><span style="color: #66cc66;">;</span>
        <span style="color: #993333;">bool</span> reuse_address <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">sock</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ServerSocket<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> InternetAddress<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;0.0.0.0&quot;</span><span style="color: #66cc66;">,</span> port<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> max_waiting_clients<span style="color: #66cc66;">,</span> reuse_address<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">sock</span>.<span style="color: #006600;">socket</span>.<span style="color: #006600;">blocking</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
        <span style="color: #993333;">auto</span> io_loop <span style="color: #66cc66;">=</span> IOLoop.<span style="color: #006600;">instance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #993333;">auto</span> callback <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&amp;</span>this.<span style="color: #006600;">call_connection_ready</span><span style="color: #66cc66;">;</span>
        io_loop.<span style="color: #006600;">add_handler</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">sock</span>.<span style="color: #006600;">fileHandle</span><span style="color: #66cc66;">,</span> callback<span style="color: #66cc66;">,</span> io_loop.<span style="color: #006600;">READ</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        Stdout<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://localhost:3000&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">newline</span>.<span style="color: #006600;">flush</span><span style="color: #66cc66;">;</span>
        io_loop.<span style="color: #006600;">start</span><span style="color: #66cc66;">&#40;</span>sock<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">public</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    IOLoop.<span style="color: #006600;">use_epoll</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">;</span>
    <span style="color: #993333;">auto</span> server <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HelloServer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
    server.<span style="color: #006600;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>
You can compile this with:<br />
<code><br />
ldc helloworld.d ../ioloop.d ../language_helper.d<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattjones.workhorsy.org/2010/03/12/porting-tornado-to-d/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python: Find objects of a certain type in memory</title>
		<link>http://www.mattjones.workhorsy.org/2009/08/23/python-find-objects-of-a-certain-type-in-memory/</link>
		<comments>http://www.mattjones.workhorsy.org/2009/08/23/python-find-objects-of-a-certain-type-in-memory/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 04:33:43 +0000</pubDate>
		<dc:creator>mattjones</dc:creator>
				<category><![CDATA[Code Fragment]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.mattjones.workhorsy.org/?p=279</guid>
		<description><![CDATA[This code snippet will allow you to look for objects of a certain type in memory. This is very useful for plugins:

&#34;&#34;&#34;
    This looks through all the objects in memory, to find ones
    of the designated type.
&#34;&#34;&#34;
&#160;
import gc
&#160;
class Animal&#40;object&#41;:
    def make_noise&#40;self&#41;:
      [...]]]></description>
			<content:encoded><![CDATA[<p>This code snippet will allow you to look for objects of a certain type in memory. This is very useful for plugins:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #483d8b;">&quot;&quot;&quot;
    This looks through all the objects in memory, to find ones
    of the designated type.
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">gc</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Animal<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> make_noise<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;snort&quot;</span>
&nbsp;
animal = Animal<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> obj <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">gc</span>.<span style="color: black;">get_objects</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">type</span><span style="color: black;">&#40;</span>obj<span style="color: black;">&#41;</span> == Animal:
        obj.<span style="color: black;">make_noise</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mattjones.workhorsy.org/2009/08/23/python-find-objects-of-a-certain-type-in-memory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Fragment: How to programatically get MySQL table relationships</title>
		<link>http://www.mattjones.workhorsy.org/2009/02/27/code-fragment-how-to-programatically-get-mysql-table-relationships/</link>
		<comments>http://www.mattjones.workhorsy.org/2009/02/27/code-fragment-how-to-programatically-get-mysql-table-relationships/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 19:43:47 +0000</pubDate>
		<dc:creator>mattjones</dc:creator>
				<category><![CDATA[Code Fragment]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.mattjones.workhorsy.org/?p=195</guid>
		<description><![CDATA[This magical chunk of goodness will allow you to query a mysql database to determine what table fields are foreign keys, and what they reference. Just replace &#8216;database_name&#8217; and &#8216;table_name&#8217; with the respective names you want:

1
2
3
4
5
6
7
SELECT column_name, referenced_table_name,
referenced_column_name
FROM information_schema.key_column_usage
WHERE table_schema='database_name'
AND table_name='table_name'
AND referenced_table_name IS NOT NULL
AND referenced_column_name IS NOT NULL;

]]></description>
			<content:encoded><![CDATA[<p>This magical chunk of goodness will allow you to query a mysql database to determine what table fields are foreign keys, and what they reference. Just replace &#8216;database_name&#8217; and &#8216;table_name&#8217; with the respective names you want:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> column_name<span style="color: #66cc66;">,</span> referenced_table_name<span style="color: #66cc66;">,</span>
referenced_column_name
<span style="color: #993333; font-weight: bold;">FROM</span> information_schema<span style="color: #66cc66;">.</span>key_column_usage
<span style="color: #993333; font-weight: bold;">WHERE</span> table_schema<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'database_name'</span>
<span style="color: #993333; font-weight: bold;">AND</span> table_name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'table_name'</span>
<span style="color: #993333; font-weight: bold;">AND</span> referenced_table_name <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #993333; font-weight: bold;">AND</span> referenced_column_name <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mattjones.workhorsy.org/2009/02/27/code-fragment-how-to-programatically-get-mysql-table-relationships/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
