<?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>Psychic Origami</title>
	<atom:link href="http://www.psychicorigami.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.psychicorigami.com</link>
	<description>folding with my brain</description>
	<lastBuildDate>Wed, 24 Feb 2010 12:27:23 +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>Chumby Podcast Client Source Code</title>
		<link>http://www.psychicorigami.com/2010/01/09/chumby-podcast-client-source-code/</link>
		<comments>http://www.psychicorigami.com/2010/01/09/chumby-podcast-client-source-code/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 18:46:54 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Application]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[chumby]]></category>

		<guid isPermaLink="false">http://www.psychicorigami.com/?p=250</guid>
		<description><![CDATA[Ok so I blogged about a podcatcher/podcast client for the Chumby quite a while ago (August 2008 to be precise).  At the time I said I&#8217;d tidy things up and release the source code etc.  Well that didn&#8217;t quite happen, but I figured I might as well release the source code.  So [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so I blogged about a <a href="http://www.psychicorigami.com/2008/08/23/chumby-podcatcher/">podcatcher/podcast client for the Chumby</a> quite a while ago (August 2008 to be precise).  At the time I said I&#8217;d tidy things up and release the source code etc.  Well that didn&#8217;t quite happen, but I figured I might as well release the source code.  So seeing as I&#8217;ve been using <a href="http://git-scm.com/">git</a> a lot lately and <a href="https://github.com/">github</a> is easy to use I thought that&#8217;d I&#8217;d best just put online what I had.</p>
<p>So you can now find the hybrid Python, Javascript and Flash <a href="http://www.chumby.com/">Chumby</a> postcast client I dubbed <a href="http://github.com/lilspikey/chumbycast">chumbycast, on github</a>.  I&#8217;m providing the code just for the curious &#8211; I&#8217;ve had at least one request for it, but I&#8217;m not really going to detail too much of how it works. Though some of this is outlined in the original post where I mentioned the project.</p>
<p>I am tempted to revive this project a bit, but probably by trying a different approach.  I mostly gave up on this as I was creating a UI on the Chumby in Flash and my Flash skills aren&#8217;t exactly great, plus I was trying to use <a href="http://www.mtasc.org/">mtasc</a> which hampered things further.  Which is not to belittle mtasc &#8211; it&#8217;s just with limited time and no previous Flash experience I wasn&#8217;t exactly helping myself by not using some nice friendly Flash IDE.</p>
<p>I&#8217;ve since realised that if I ditched the Flash UI I could probably get quite a bit done.  The Python httpserver side of things was pretty easy.  So if I focussed on that I would then have a few of ways of providing a UI by hijacking existing functionality on the Chumby.</p>
<ul>
<li>The Chumby runs a <a href="http://wiki.chumby.com/mediawiki/index.php/Chumby_as_an_iPod_server">httpserver on port 8080 when an ipod is plugged in</a>, which the UI uses to access playlists etc.  I could mimic this approach and effectively make the podcast client look like an iPod as far as the Chumby&#8217;s UI was concerned.  By plugging in a USB stick loaded up with the podcast client everything would behave the same as if you had plugged in an iPod.</li>
<li>It&#8217;s possible to <a href="http://wiki.chumby.com/mediawiki/index.php/Chumby_and_music">create playlist files and edit the &#8220;My Streams&#8221;</a> section programmatically.  Each podcast subscribed to would create a matching pls or m3u file and be added to the &#8220;My Streams&#8221; section.</li>
<li>Create a javascript/web UI for controlling the playback and subscriptions to podcasts and other podcast management tasks (like removing old files, manually downloading older episodes etc) from another computer.  Possibly adding bonjour/zero-conf support so the Chumby can be browsed to easily</li>
</ul>
<p>I would need to see whether those first two could be made to work for my purpose, but it would make sense to just use the existing UI on the Chumby &#8211; rather than creating a new one.  The existing chumbycast code already provides a javascript/web UI for controlling the playback on the Chumby.  This was originally done so I could remote control the chumby, but also so that I could easily create and debug an API for the Flash UI to use.</p>
<p>The other major missing feature is allowing the podcasts to be paused part way through.  The current client does not support this, as the audio files are streamed and not downloaded.  So that would be the first change to make.  Now that I&#8217;ve dug out the code maybe I&#8217;ll be inspired to play around some more.  I&#8217;ve also been listening to a lot more podcasts (thanks to <a href="http://huffduffer.com/">Huffduffer</a>) so it might happen yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.psychicorigami.com/2010/01/09/chumby-podcast-client-source-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to sew a felt horse</title>
		<link>http://www.psychicorigami.com/2010/01/02/how-to-sew-a-felt-horse/</link>
		<comments>http://www.psychicorigami.com/2010/01/02/how-to-sew-a-felt-horse/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 12:03:21 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Craft]]></category>

		<guid isPermaLink="false">http://www.psychicorigami.com/?p=239</guid>
		<description><![CDATA[I&#8217;ve clearly picked up the making felt toys bug.  For Christmas this year I ended up making a pair of felt horses for two of my cousin&#8217;s children:

I thought I&#8217;d have a go at writing up the instructions for how I did this &#8211; complete with template for making your own:


How to sew a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve clearly picked up the <a href="http://www.psychicorigami.com/2009/10/12/two-months-of-felt-creations/">making felt toys bug</a>.  For Christmas this year I ended up making a pair of felt horses for two of my cousin&#8217;s children:</p>
<p><center><a title="A pair of felt horses by lilspikey, on Flickr" href="http://www.flickr.com/photos/lilspikey/4203959561/"><img src="http://farm5.static.flickr.com/4008/4203959561_18e63783b6.jpg" alt="A pair of felt horses" width="500" height="375" /></a></center></p>
<p>I thought I&#8217;d have a go at writing up the instructions for how I did this &#8211; complete with template for making your own:</p>
<p><center><br />
<a href="http://www.psychicorigami.com/craft/horsies/"><img src="http://www.psychicorigami.com/wp-content/uploads/2010/01/how-to-sew-a-felt-horse.png" alt="" title="how-to-sew-a-felt-horse" width="400" height="344" /></p>
<p>How to sew a felt horse</a><br />
</center></p>
<p>It&#8217;s pretty easy really.  As long as you can sew some backstitch you should be able to make this easily.  If not then it might not be the worst first project to try either!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.psychicorigami.com/2010/01/02/how-to-sew-a-felt-horse/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django Batch Select</title>
		<link>http://www.psychicorigami.com/2009/11/23/django-batch-select/</link>
		<comments>http://www.psychicorigami.com/2009/11/23/django-batch-select/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 10:00:00 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.psychicorigami.com/?p=228</guid>
		<description><![CDATA[So quite a while ago I wrote about avoiding the n+1 query problem with SQLObject.  I&#8217;ve since been using Django a lot more.  In particular at my day job I&#8217;ve been improving a Django site we&#8217;ve inherited.  This particular site suffered from a few too many SQL queries and needed speeding up. [...]]]></description>
			<content:encoded><![CDATA[<p>So quite a while ago I wrote about <a href="http://www.psychicorigami.com/2007/12/16/using-raw-sql-with-sqlobject-and-keeping-the-object-y-goodness/">avoiding the n+1 query problem with SQLObject</a>.  I&#8217;ve since been using <a href="http://www.djangoproject.com/">Django</a> a lot more.  In particular at <a href="http://www.sensibledevelopment.com/">my day job</a> I&#8217;ve been improving a Django site we&#8217;ve inherited.  This particular site suffered from a few too many SQL queries and needed speeding up.  Some of the issues related to the classic n+1 problem.  i.e. one initial query triggering a further n queries (where n is the number of results in the first query).</p>
<p>A liberal dose of <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4">select_related</a> helped.  However that was only useful in the cases where a ForeignKey needed to be pre-fetched.</p>
<p>In the case however there was a page that was selecting a set of objects that had tags.  The tags for each object were being displayed along side a link to the main object.  Given that the initial query returned over three hundred objects, this meant the page was performing another three hundred (plus) queries to fetch the individual tags for each object!  Now we could cache the page and that&#8217;s was indeed what was being done.  The trouble however was when the cache expired.  It also made things painful when developing &#8211; as I&#8217;d typically want to disable caching whilst I&#8217;m making changes to pages frequently.</p>
<p>I came up with a specific solution for this project &#8211; to perform the initial query, then a second query to fetch *all* of the other tags in one go.  The results of the second query could then be stitched into the original results, to make them available in a handy manor within the page&#8217;s template.</p>
<p>I took the original idea and made it re-usable and am now releasing that code as <a href="http://github.com/lilspikey/django-batch-select">Django Batch Select</a>.  There are examples of how to use it over at <a href="http://github.com/lilspikey/django-batch-select">github</a>, but it works a bit like this:</p>
<pre><code>
&gt;&gt;&gt; entries = Entry.objects.batch_select('tags').all()
&gt;&gt;&gt; entry = entries[0]
&gt;&gt;&gt; print entry.tags_all
[&lt;Tag: Tag object&gt;]
</code></pre>
<p>It&#8217;s a very early release &#8211; after the result of only a few hours coding, so use with care.  It does have 100% test code coverage at the moment and I&#8217;m reasonable confident about it working.  Please try it out and let me know whether it works for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.psychicorigami.com/2009/11/23/django-batch-select/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Two Months of Felt Creations</title>
		<link>http://www.psychicorigami.com/2009/10/12/two-months-of-felt-creations/</link>
		<comments>http://www.psychicorigami.com/2009/10/12/two-months-of-felt-creations/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 09:00:00 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Craft]]></category>

		<guid isPermaLink="false">http://www.psychicorigami.com/?p=212</guid>
		<description><![CDATA[It&#8217;s been a busy two months for me.  I&#8217;ll soon be getting married and there&#8217;s been quite a lot to do.  A while back I finished the invites for the wedding (which involved hand-stamped wrapping paper):



From there I moved on to creating a pair of robins to sit on top of the wedding [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a busy two months for me.  I&#8217;ll soon be <a href="http://montgomery-williams.com/">getting married</a> and there&#8217;s been quite a lot to do.  A while back I finished the invites for the wedding (which involved hand-stamped wrapping paper):</p>
<p><center><br />
<a href="http://www.flickr.com/photos/lilspikey/3754837888/" title="Wedding Invites by lilspikey, on Flickr"><img src="http://farm3.static.flickr.com/2577/3754837888_e3245312e2_m.jpg" width="240" height="180" alt="Wedding Invites" /></a><br />
</center></p>
<p>From there I moved on to creating a pair of robins to sit on top of the wedding cake:</p>
<p><center><br />
<a href="http://www.flickr.com/photos/lilspikey/3781536205/" title="Finished Robin Cake Toppers by lilspikey, on Flickr"><img src="http://farm3.static.flickr.com/2429/3781536205_89441e7a0f_m.jpg" width="240" height="180" alt="Finished Robin Cake Toppers" /></a> <a href="http://www.flickr.com/photos/lilspikey/3782330222/" title="Robins by lilspikey, on Flickr"><img src="http://farm3.static.flickr.com/2644/3782330222_697b088f0d_m.jpg" width="240" height="180" alt="Robins" /></a> <a href="http://www.flickr.com/photos/lilspikey/3782342972/" title="One finished, one robin nearly finished by lilspikey, on Flickr"><img src="http://farm3.static.flickr.com/2494/3782342972_eb49106d79_m.jpg" width="240" height="180" alt="One finished, one robin nearly finished" /></a><br />
</center></p>
<p>The robins are made out of felt and stuffed using bits of cut-up cotton sheet (as that was all I had to hand at the time &#8211; hence also the green cotton).  The legs are simply silver wire stitched into place inside, with the red-breast covering up the extra stitches needed.  The eyes are just small black beads (from <a href="http://www.beadsunlimited.co.uk/">Beads Unlimited</a> in Brighton, as was the silver wire).</p>
<p>I felt they turned out really well, so seeing as they didn&#8217;t take too long (a couple of hours each) we decided it&#8217;d be nice to make more felt creatures (following an autumn theme) for table centrepieces.  Initially we planned on one creature per table, then two and so with some extra help from my bride-to-be we ended up with twenty eight felt hedgehogs:</p>
<p><center><br />
<a href="http://www.flickr.com/photos/lilspikey/3950486371/" title="Hedgehogs with conkers by lilspikey, on Flickr"><img src="http://farm3.static.flickr.com/2640/3950486371_f956c2bf9a_m.jpg" width="240" height="180" alt="Hedgehogs with conkers" /></a> <a href="http://www.flickr.com/photos/lilspikey/3950487655/" title="Hedgehogs boxed and waiting by lilspikey, on Flickr"><img src="http://farm3.static.flickr.com/2582/3950487655_b59bb95070_m.jpg" width="240" height="180" alt="Hedgehogs boxed and waiting" /></a> <a href="http://www.flickr.com/photos/lilspikey/3840579140/" title="Hedgehogs in production by lilspikey, on Flickr"><img src="http://farm3.static.flickr.com/2582/3840579140_0b933cc017_m.jpg" width="240" height="180" alt="Hedgehogs in production" /></a> <a href="http://www.flickr.com/photos/lilspikey/3803697896/" title="Felt Hedgehog in progress by lilspikey, on Flickr"><img src="http://farm3.static.flickr.com/2509/3803697896_bf30055971_m.jpg" width="240" height="180" alt="Felt Hedgehog in progress" /></a><br />
</center></p>
<p>Again the hedgehogs were made of felt.  This time they were stuffed with wadding which made things easier.  The spines were glued on as &#8220;fringed&#8221; bits of felt, with a special widows-peak shaped piece for the head.  This time the eyes and nose were just small bits of black felt, glued in place &#8211; so as to be marginally more child-friendly.  Each hedgehog body consists of three pieces of felt &#8211; two sides and a smaller bottom piece.  The bottom piece makes them stand fairly levelly and also gives them a more rounded look.</p>
<p>Somewhere during this time I&#8217;ve also had several friends children&#8217;s first birthdays to contend with.  So seeing as I was in a felt creature production mood I turned my hand to three felt toys:</p>
<p><center><br />
<a href="http://www.flickr.com/photos/lilspikey/3975343592/" title="Finished Felt Max (from Where the wild things are) by lilspikey, on Flickr"><img src="http://farm3.static.flickr.com/2589/3975343592_81df443787_m.jpg" width="240" height="180" alt="Finished Felt Max (from Where the wild things are)" /></a> <a href="http://www.flickr.com/photos/lilspikey/3974465999/" title="Felt Spaceman by lilspikey, on Flickr"><img src="http://farm3.static.flickr.com/2454/3974465999_957cfca2df_m.jpg" width="180" height="240" alt="Felt Spaceman" /></a> <a href="http://www.flickr.com/photos/lilspikey/3853034451/" title="Purple Felt Monster by lilspikey, on Flickr"><img src="http://farm4.static.flickr.com/3509/3853034451_a75193f2a2_m.jpg" width="240" height="180" alt="Purple Felt Monster" /></a><br />
</center></p>
<p>I realised the other day that all thirty three of these were made during a roughly two month period &#8211; meaning one felt creation every two days!  Not a bad rate of productivity I guess.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.psychicorigami.com/2009/10/12/two-months-of-felt-creations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Kite Physics Demo</title>
		<link>http://www.psychicorigami.com/2009/10/03/kite-physics-demo/</link>
		<comments>http://www.psychicorigami.com/2009/10/03/kite-physics-demo/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 10:20:33 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.psychicorigami.com/?p=207</guid>
		<description><![CDATA[I&#8217;ve been working on a little kite physics demo app:



After chatting with Allistar at the £5app about how he did physics simulations I was pointed at &#8220;Gauss-Seidel&#8221; as an easy way to handle constraints.  This led me to Advanced Character Physics by Thomas Jakobsen, which explained it all very nicely.  That coupled with [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a little kite physics demo app:</p>
<p><center><br />
<object type="application/x-shockwave-flash" width="480" height="480" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&#038;photo_secret=548e27c980&#038;photo_id=3976817556&#038;flickr_show_info_box=true"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&#038;photo_secret=548e27c980&#038;photo_id=3976817556&#038;flickr_show_info_box=true" height="480" width="480"></embed></object><br />
</center></p>
<p>After chatting with Allistar at the <a href="http://fivepoundapp.com/meetup/18/">£5app</a> about how he did physics simulations I was pointed at &#8220;Gauss-Seidel&#8221; as an easy way to handle constraints.  This led me to <a href="http://www.teknikus.dk/tj/gdc2001.htm">Advanced Character Physics by Thomas Jakobsen</a>, which explained it all very nicely.  That coupled with some info from NASA on <a href="http://www.grc.nasa.gov/WWW/K-12/airplane/kitefor.html">forces on a kite</a> helped me create this simple 2D &#8220;simulation&#8221;.</p>
<p>It&#8217;s not yet finished, but I thought I&#8217;d share some of my progress.  I want to turn it into a slightly more rounded demo or perhaps even a simple game of some sort, with some scenery etc.  I&#8217;m quite happy with how it&#8217;s turned out so far &#8211; even though I did waste a fair bit of time getting drop-shadows working&#8230;</p>
<p>It&#8217;s all written in Java, so it&#8217;ll be nice and easy to put online later.  I think I&#8217;ll probably release the source too, as the physics and constraints code is fairly generalized.  In fact through the use of generics and a few other tricks the code is setup to allow (potential) re-use for 3D physics too. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.psychicorigami.com/2009/10/03/kite-physics-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moleskin upload</title>
		<link>http://www.psychicorigami.com/2009/07/13/moleskin-upload-2/</link>
		<comments>http://www.psychicorigami.com/2009/07/13/moleskin-upload-2/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 17:17:11 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Artwork]]></category>

		<guid isPermaLink="false">http://www.psychicorigami.com/?p=194</guid>
		<description><![CDATA[A few more pictures from my moleskin.
Mixture of pencil, micron ink and tria markers.
]]></description>
			<content:encoded><![CDATA[<p>A few more pictures from my <a href="http://www.moleskine.com/">moleskin</a>.</p>

<a href='http://www.psychicorigami.com/2009/07/13/moleskin-upload-2/gorilla/' title='gorilla'><img width="150" height="150" src="http://www.psychicorigami.com/wp-content/uploads/2009/07/gorilla-150x150.jpg" class="attachment-thumbnail" alt="" title="gorilla" /></a>
<a href='http://www.psychicorigami.com/2009/07/13/moleskin-upload-2/house-roofs/' title='house-roofs'><img width="150" height="150" src="http://www.psychicorigami.com/wp-content/uploads/2009/07/house-roofs-150x150.jpg" class="attachment-thumbnail" alt="" title="house-roofs" /></a>
<a href='http://www.psychicorigami.com/2009/07/13/moleskin-upload-2/monkey-and-red-panda/' title='monkey-and-red-panda'><img width="150" height="150" src="http://www.psychicorigami.com/wp-content/uploads/2009/07/monkey-and-red-panda-150x150.jpg" class="attachment-thumbnail" alt="" title="monkey-and-red-panda" /></a>
<a href='http://www.psychicorigami.com/2009/07/13/moleskin-upload-2/rosy/' title='rosy'><img width="150" height="150" src="http://www.psychicorigami.com/wp-content/uploads/2009/07/rosy-150x150.jpg" class="attachment-thumbnail" alt="" title="rosy" /></a>
<a href='http://www.psychicorigami.com/2009/07/13/moleskin-upload-2/tapir/' title='tapir'><img width="150" height="150" src="http://www.psychicorigami.com/wp-content/uploads/2009/07/tapir-150x150.jpg" class="attachment-thumbnail" alt="" title="tapir" /></a>
<a href='http://www.psychicorigami.com/2009/07/13/moleskin-upload-2/wilson/' title='wilson'><img width="150" height="150" src="http://www.psychicorigami.com/wp-content/uploads/2009/07/wilson-150x150.jpg" class="attachment-thumbnail" alt="" title="wilson" /></a>

<p>Mixture of pencil, <a href="http://www.sakuraofamerica.com/Pen-Archival">micron ink</a> and <a href="http://www.letraset.com/manga/shopdisplaycategories.asp?id=55&#038;cat=Tria+Markers">tria markers</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.psychicorigami.com/2009/07/13/moleskin-upload-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An iPhone friendly, local storage backed, offline TODO list webapp</title>
		<link>http://www.psychicorigami.com/2009/07/10/an-iphone-friendly-local-storage-backed-offline-todo-list-webapp/</link>
		<comments>http://www.psychicorigami.com/2009/07/10/an-iphone-friendly-local-storage-backed-offline-todo-list-webapp/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 11:21:13 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Application]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.psychicorigami.com/?p=176</guid>
		<description><![CDATA[A while back I had a go at using the local storage features being added to javascript to create a simple TODO list app.  The main focus of the app was getting it all to fit under 5K (5120 bytes), but it was a good test of using a client-side sql database in javascript.
As [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I had a go at using the local storage features being added to javascript to create a <a href="http://www.psychicorigami.com/2008/12/24/a-5k-javascript-local-storage-backed-todo-list-app/">simple TODO list app</a>.  The main focus of the app was getting it all to fit under 5K (5120 bytes), but it was a good test of using a <a href="http://www.psychicorigami.com/2009/01/13/client-side-sql-databases-in-javascript/">client-side sql database</a> in javascript.</p>
<p>As the app was written for size it didn&#8217;t have many frills.  It did however work on the <a href="http://www.apple.com/iphone/">iPhone</a>, as it&#8217;s version of <a href="http://www.apple.com/safari/">Safari</a> had support for the <code>openDatabase</code> call needed.  However it didn&#8217;t look so good and although the TODO list items were stored locally the phone still had to be online to access the host webpage &#8211; which kind of undermined some of it&#8217;s utility.</p>
<p>With my recent acquisition of an iPhone I thought I&#8217;d revisit this TODO app and make it play nicely on the iPhone.  In addition to using a client-side SQL database this new version features:</p>
<ul>
<li>Better looks (thanks to <a href="http://code.google.com/p/iui/">iui</a>)</li>
<li>Ability to run offline (thanks to <a href="http://developer.apple.com/safari/library/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/OfflineApplicationCache/OfflineApplicationCache.html">html5&#8217;s offline application cache</a>)</li>
<li>Drag and drop item sorting (thanks to <a href="http://jqueryui.com/">jquery UI</a> + <a href="http://jasonkuhn.net/mobile/jqui/js/jquery.iphoneui.js">a bit of touch event hacking</a>)</li>
</ul>
<p>These features mean that if you have add a bookmark to your homescreen for this app, you might as well be running a native app.  It looks pretty native, stores data locally, doesn&#8217;t require a net connection and even features standard app UI mechanisms.  The main giveaway is of course the chrome associated with the Safari browser.  Still not bad for some html, css and javascript.  Not a total replacement for native <a href="http://developer.apple.com/cocoa/">Cocoa</a> apps, but it does put the creation of client-side apps for the iPhone into the hands of even more people.</p>
<p>If you are on an iPhone or are running Safari 4.0 you can <a href="http://www.psychicorigami.com/jTODO/">try out jTODO</a> yourself or watch the video of it in action below:</p>
<p><center><br />
<object type="application/x-shockwave-flash" width="320" height="479" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&#038;photo_secret=0b052f7e03&#038;photo_id=3706217955&#038;flickr_show_info_box=true"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&#038;photo_secret=0b052f7e03&#038;photo_id=3706217955&#038;flickr_show_info_box=true" height="479" width="320"></embed></object><br />
</center></p>
<p>I won&#8217;t rehash the sql-side of things in this post &#8211; instead I&#8217;d refer you to  <a href="http://www.psychicorigami.com/2009/01/13/client-side-sql-databases-in-javascript/">my original post</a> on the matter.</p>
<p>The use of iui was also fairly straightforward &#8211; I&#8217;m only using the style-sheets and images.  This means that there are no animations involved, but at this stage it seemed excessive to add them in.  Perhaps I&#8217;ll add some in a future version.</p>
<p>This leaves the offline application cache and getting drag and drop to work.</p>
<h3>Offline application cache</h3>
<p>The offline application cache is really simple to implement.  It&#8217;s currently supported by Safari on the iPhone, Safari 4.0 and Firefox 3+.</p>
<p>In my case I want <em>all</em> files to be cached, so I simple specify them in a &#8220;manifest&#8221; file:</p>
<pre>
<code>
CACHE MANIFEST

# version 1.0.2.37

iui/backButton.png
iui/blueButton.png
iui/cancel.png
iui/grayButton.png
iui/iui-logo-touch-icon.png
iui/iui.css
iui/iui.js
iui/iuix.css
iui/iuix.js
iui/listArrow.png
iui/listArrowSel.png
iui/listGroup.png
iui/loading.gif
iui/pinstripes.png
iui/selection.png
iui/thumb.png
iui/toggle.png
iui/toggleOn.png
iui/toolButton.png
iui/toolbar.png
iui/whiteButton.png

css/todo.css

js/jquery-1.3.2.min.js
js/jquery-ui-1.7.2.custom.min.js
js/todo.js

img/delete.png
img/deleting.png
img/redButton.png
img/handle.png
img/todo-touch-icon.png
</code>
</pre>
<p>This manifest file is then linked to the main html file thus:</p>
<pre>
<code>
&lt;html manifest="todo.manifest"&gt;
</code>
</pre>
<p>That&#8217;s it.  We now have an offline capable web-app.  The main issue I had when doing this, was that Safari was very strict about the manifest &#8211; any file not mentioned in the manifest would not be loaded (even if it was normally accessible).  The other issue of course is that we&#8217;ve now introduced another level of caching, so developing can be a bit annoying &#8211; as you think you&#8217;ve made a change, but then nothing shows up.  I often ended up disabling the manifest for a while when debugging and then re-enabled it after things were working again.  There&#8217;s also a version number in the manifest file, so that it well register as changed &#8211; to help refresh the caches after we&#8217;ve made a change.</p>
<p>With all this in place the app can be used when no net connection is available (e.g. in Airplane mode).</p>
<h3>Drag and drop</h3>
<p>The last job when developing this app was to enable drag and drop for re-ordering items.  My first go at this worked pretty easily using jQuery UI&#8217;s <a href="http://jqueryui.com/demos/sortable/">sortable</a> plugin &#8211; when running on my mac in Safari:</p>
<pre>
<code>
            page.sortable({
                axis: 'y',
                handle: '.handle',
                update: function(){
                    db.transaction(function(tx) {
                        $('.todo_item').each(function(i,item) {
                            var id = $(item).find(':input[type=checkbox]').attr('id');
                            id = Number(id.substring('todo_checkbox_'.length));
                            tx.executeSql('UPDATE todo SET todo_order=? WHERE id=?', [i, id]);
                        });
                    });
                }
            });
</code>
</pre>
<p>Essentially this is just setup to enabling drag and drop sorting only along the y axis (up and down), using the element with class <code>handle</code> to start the drag.  Once the dragging has finished <code>update</code> gets called and I inspect the DOM to work out the current order of the <code>todo_item</code>s and update the database accordingly.</p>
<p>That was pretty easy and working really well on the mac.  Then of course I thought I&#8217;d test it on the iPhone.  At that point I realised I&#8217;d forgotten that drag and drop doesn&#8217;t normally work in Safari in the iPhone.  Holding and dragging normally scrolls the entire page &#8211; so drag and drop was a bit useless here.</p>
<p>However after a little digging I found <a href="http://jasonkuhn.net/mobile/jqui/">someone</a> had figured out how to get drag and drop working on the iPhone, by hijacking the various &#8220;touch&#8221; events that the phone generates.  These work a little differently to the normal mouse events, but with some work can made to do our bidding:</p>
<pre>
<code>
    function handleTouchEvent(event) {
        /* from http://jasonkuhn.net/mobile/jqui/js/jquery.iphoneui.js
         but changed a bit*/

        var touches = event.changedTouches;
        var first = touches[0];
        var type = '';

        // only want to do this for the drag handles
        if ( !first.target || !first.target.className || first.target.className.indexOf("handle") == -1 ) {
            return;
        }

        switch(event.type) {
            case 'touchstart':
                type = 'mousedown';
                break;

            case 'touchmove':
                type = 'mousemove';
                break;        

            case 'touchend':
                type = 'mouseup';
                break;

            default:
                return;
        }

        var simulatedEvent = document.createEvent('MouseEvent');
        simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0/*left*/, null);

        first.target.dispatchEvent(simulatedEvent);

        if ( event.type == 'touchmove' ) {
            event.preventDefault();
        }
    }
    document.addEventListener("touchstart", handleTouchEvent, false);
    document.addEventListener("touchmove", handleTouchEvent, false);
    document.addEventListener("touchend", handleTouchEvent, false);
</code>
</pre>
<p>This registers listeners for the touch events, but only does any extra work if the target of the event has the class &#8220;handle&#8221;.  If that&#8217;s the case a simulated mouse event is sent for the first touched item.  To stop the page from scrolling when we want to drag instead <code>event.preventDefault()</code> is called just for the <code>touchmove</code> event.  This is sufficient to let jquery UI do it&#8217;s job and enable drag and drop sorting of the TODO items.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.psychicorigami.com/2009/07/10/an-iphone-friendly-local-storage-backed-offline-todo-list-webapp/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Django simple admin ImageField thumbnail</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/</link>
		<comments>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 11:11:00 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168</guid>
		<description><![CDATA[The Django admin site is one of the best features of Django.  It really lets you just get on with building your app, without having to worry too much about how you&#8217;ll administer your site.
The defaults are generally pretty good, but it&#8217;s often the case that you&#8217;ll want to tweak and change it (particularly [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.djangoproject.com/">Django</a> admin site is one of the best features of Django.  It really lets you just get on with building your app, without having to worry too much about how you&#8217;ll administer your site.</p>
<p>The defaults are generally pretty good, but it&#8217;s often the case that you&#8217;ll want to tweak and change it (particularly when you have clients involved).  Luckily it&#8217;s pretty easy to customize.</p>
<p>One common change that many people will want to do is to display a thumbnail of an uploaded image in the admin.  The default image field (when an image has been uploaded) in the admin looks like:</p>
<p><img class="alignnone size-full wp-image-169" title="image_field1" src="http://www.psychicorigami.com/wp-content/uploads/2009/06/image_field1.jpg" alt="image_field1" width="331" height="44" /></p>
<p>and we want to change it to look like this:</p>
<p><img class="alignnone size-full wp-image-170" title="image_field2" src="http://www.psychicorigami.com/wp-content/uploads/2009/06/image_field2.jpg" alt="image_field2" width="257" height="77" /></p>
<p>In my case I had images that I knew would be fairly small so I didn&#8217;t need to use any auto-resizing or anything like that.  I found <a href="http://www.djangosnippets.org/snippets/934/">this snippet</a> for doing the same task, but decided to simplify it a fair bit and ended up with:</p>
<pre><code>
from django.contrib.admin.widgets import AdminFileWidget
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe

class AdminImageWidget(AdminFileWidget):
    def render(self, name, value, attrs=None):
        output = []
        if value and getattr(value, "url", None):
            image_url = value.url
            file_name=str(value)
            output.append(u' &lt;a href="%s" target="_blank"&gt;&lt;img src="%s" alt="%s" /&gt;&lt;/a&gt; %s ' % \
                (image_url, image_url, file_name, _('Change:')))
        output.append(super(AdminFileWidget, self).render(name, value, attrs))
        return mark_safe(u''.join(output))
</code></pre>
<p>Then to use it I simply override <code>formfield_for_dbfield</code> to return a field that uses that widget for the field I&#8217;m interested in:</p>
<pre><code>
class MyAdmin(admin.ModelAdmin):
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name == 'profile_image':
            request = kwargs.pop("request", None)
            kwargs['widget'] = AdminImageWidget
            return db_field.formfield(**kwargs)
        return super(MyAdmin,self).formfield_for_dbfield(db_field, **kwargs)
</code></pre>
<p>It&#8217;s a fairly straightforward alteration to how the <code>ImageField</code> widget renders in the admin, but it is often a big help to be able to actually see the image in question.</p>
<p>UPDATED: Feb 24th, 2010.  Based on Jeremy&#8217;s comment below and having upgraded to Django 1.1 I&#8217;ve modified this example to remove the &#8220;request&#8221; param from kwargs before passing it db_field.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing NoteComb</title>
		<link>http://www.psychicorigami.com/2009/05/18/introducing-notecomb/</link>
		<comments>http://www.psychicorigami.com/2009/05/18/introducing-notecomb/#comments</comments>
		<pubDate>Mon, 18 May 2009 21:25:50 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Application]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.psychicorigami.com/?p=167</guid>
		<description><![CDATA[I&#8217;ve been writing an application for my other half in recent months to help her organise observations of the children in her class.  I&#8217;ve actually written two versions of the app.  The first was dubbed &#8220;Observertron&#8221; and in retrospect was overly complex.  After a bit of thought I was able to vastly [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing an application for my other half in recent months to help her organise observations of the children in her class.  I&#8217;ve actually written two versions of the app.  The first was dubbed &#8220;Observertron&#8221; and in retrospect was overly complex.  After a bit of thought I was able to vastly simplify the app, whilst also making it more useful for other purposes beyond making observations.</p>
<p>The app is called <a href="http://www.psychicorigami.com/notecomb/">NoteComb</a> and is written in <a href="http://python.org/">Python</a> using <a href="http://www.wxpython.org/">wxPython</a>.  It&#8217;s essentially a specialised text-editor.  The core feature is a <a href="http://www.gnu.org/software/grep/">grep</a>-like search functionality coupled with the ability to edit text in-place during a search.  Lines that don&#8217;t contain the search terms get hidden, leaving you free to edit the remaining lines as you want:</p>
<p><center><br />
<a href="http://www.psychicorigami.com/notecomb/#demo"><img src="http://www.psychicorigami.com/notecomb/images/screenshot1.jpg" /></a><br />
</center></p>
<p>I&#8217;ve decided to take the time and try to package it up &#8220;properly&#8221;.  So NoteComb is available as Mac and Windows apps, complete with icons etc.  In fact to &#8220;regular&#8221; users it should appear that NoteComb is an app like any other &#8211; the fact it&#8217;s written using Python is largely incidental.</p>
<p>This packaging works pretty well overall and is pretty seamless once the app is downloaded, but it does tend to make for rather large apps.  The Windows version when packaged as an installer runs in at about 4Mb, which isn&#8217;t too crazy, but the OS X app packed into a compressed DMG file weighs in at 15Mb!  At the end of the day the app does include Python + wxPython + various libraries, so it&#8217;s not a surprise really, but I guess I was kind of hoping that I might develop in Python and get everything for free&#8230;</p>
<p>This is an early version of NoteComb (version 0.2.1), but it&#8217;s core functionality is there.  Most of the extra work I&#8217;ve done has been on adding those little extra bits that aren&#8217;t core to the app, but are generally just expected (e.g. remembering previous window positions, copy/paste, undo/redo etc).</p>
<p>So feel free to download <a href="http://www.psychicorigami.com/notecomb/#download">NoteComb</a> and give it a go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.psychicorigami.com/2009/05/18/introducing-notecomb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easily setting frame icon from exe file in wxPython</title>
		<link>http://www.psychicorigami.com/2009/05/01/easily-setting-frame-icon-from-exe-file-in-wxpython/</link>
		<comments>http://www.psychicorigami.com/2009/05/01/easily-setting-frame-icon-from-exe-file-in-wxpython/#comments</comments>
		<pubDate>Fri, 01 May 2009 14:25:24 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.psychicorigami.com/?p=166</guid>
		<description><![CDATA[I&#8217;ve updated the relevant wxPython wiki page with this info, but thought i&#8217;d record it here for posterity too.
I&#8217;m currently playing around with writing a wxPython app.  It&#8217;s at the point where I&#8217;m starting to package it into executables to be run without needing Python installed.
Py2exe is the tool I&#8217;m using for creating a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve updated the relevant <a href="http://wiki.wxpython.org/LoadIconFromWin32Resources">wxPython wiki page</a> with this info, but thought i&#8217;d record it here for posterity too.</p>
<p>I&#8217;m currently playing around with writing a <a href="http://www.wxpython.org/">wxPython</a> app.  It&#8217;s at the point where I&#8217;m starting to package it into executables to be run without needing <a href="http://python.org/">Python</a> installed.</p>
<p><a href="http://www.py2exe.org/">Py2exe</a> is the tool I&#8217;m using for creating a windows app (and <a href="http://undefined.org/python/py2app.html">py2app</a> for the mac).  It&#8217;s possible to specify an icon for the executable you create with py2exe.  However it&#8217;d be nice if this same icon would be used as the icon for frames created by that app.  One could include an extra icon as a resource and load that up, but this seems counter to the whole <a href="http://c2.com/cgi/wiki?DontRepeatYourself">DRY</a> principle.  Instead it&#8217;d be better to load the same icon from the executable we have created already.</p>
<p>Consulting the wxPython wiki showed that some enterprising souls had already had a go at doing this, but the solutions there relied on the <code>win32api</code> modules amongst others.  My Windows machine didn&#8217;t have this module installed (as it was running Python 2.5) and looking at the 2nd solution proposed I saw a way to remove this dependency (and thus decrease the size of the final exe as it would not need to include the extra dll&#8217;s etc).</p>
<p>So here&#8217;s the sample code, from the wiki, I posted:</p>
<pre>
<code>
import wx, sys

class MyFrame(wx.Frame):
    def __init__(self, parent=None):
        wx.Frame.__init__(self, parent, wx.ID_ANY)
            # set window icon
            if sys.platform == 'win32':
                # only do this on windows, so we don't
                # cause an error dialog on other platforms
                exeName = sys.executable
                icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
                self.SetIcon(icon)

if __name__ == '__main__':
    app = wx.App(redirect=False)
    frame = MyFrame()
    frame.Show(True)
    app.MainLoop()
</code>
</pre>
<p>Basically it uses <code>sys.executable</code> to find the exe we are running in and then gets wxPython to load the first icon it finds from it (which should be the icon of the executable itself).  So when you run this directly from python (not packaged), you end up with the icon from the python executable, but when you run the packaged version you get the icon from the exe instead.</p>
<p>It includes the platform check, as otherwise the app throws up an error dialog on the mac and obviously I want this to work on both platforms (and Linux too in the future).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.psychicorigami.com/2009/05/01/easily-setting-frame-icon-from-exe-file-in-wxpython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
