<?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>Trouble With Dreams &#187; code</title>
	<atom:link href="http://troublewithdreams.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://troublewithdreams.com</link>
	<description></description>
	<lastBuildDate>Thu, 05 Jan 2012 10:02:31 +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>Last.fm Explorer</title>
		<link>http://troublewithdreams.com/2011/01/30/last-fm-explorer/</link>
		<comments>http://troublewithdreams.com/2011/01/30/last-fm-explorer/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 21:54:45 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[scrobbler]]></category>
		<category><![CDATA[twd]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=432</guid>
		<description><![CDATA[A note to say that a successor to Historical Charts is available at twothreefall.co.uk/lastfmexplorer.  Redesign and restructure aside, new features alongside the charts that went before include:

Interactive charts and plots of weekly playcounts
Charts for only new artists
Information about extreme weeks

For an example see what it does with my data.
I&#8217;m pleased with how it&#8217;s turned [...]]]></description>
			<content:encoded><![CDATA[<p>A note to say that a successor to <a href="/scrobbler">Historical Charts</a> is available at <a href="http://twothreefall.co.uk/lastfmexplorer">twothreefall.co.uk/lastfmexplorer</a>.  Redesign and restructure aside, new features alongside the charts that went before include:</p>
<ul>
<li>Interactive charts and plots of weekly playcounts</li>
<li>Charts for only new artists</li>
<li>Information about extreme weeks</li>
</ul>
<p>For an example see what it does with <a href="http://twothreefall.co.uk/lastfmexplorer/user/aradnuk">my data</a>.</p>
<p>I&#8217;m pleased with how it&#8217;s turned out.</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2011/01/30/last-fm-explorer/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Django experiments</title>
		<link>http://troublewithdreams.com/2010/04/05/django-experiments/</link>
		<comments>http://troublewithdreams.com/2010/04/05/django-experiments/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 22:44:53 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scrobbler]]></category>
		<category><![CDATA[twd]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=337</guid>
		<description><![CDATA[I&#8217;ve been playing about with Django and Last.fm data, intended as an eventual upgrade to historical charts.  It&#8217;s fun .. I now know I play most music in March and November (university deadline time!), that my top three artists of 2010 so far are Animal Collective, Grizzly Bear and The Delgados, and that my [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing about with Django and Last.fm data, intended as an eventual upgrade to <a href="/scrobbler"/>historical charts</a>.  It&#8217;s fun .. I now know I play most music in March and November (university deadline time!), that my top three artists of 2010 so far are <a href="http://www.last.fm/music/Animal Collective">Animal Collective</a>, <a href="http://www.last.fm/music/Grizzly Bear">Grizzly Bear</a> and <a href="http://www.last.fm/music/The Delgados">The Delgados</a>, and that my favourite three discoveries are <a href="http://www.last.fm/music/Starless &#038; Bible Black">Starless &amp; Bible Black</a>, <a href="http://www.last.fm/music/RM Hubbert">RM Hubbert</a> and <a href="http://www.last.fm/music/Soweto Kinch">Soweto Kinch</a>.</p>
<p>I also discovered that using a foreign key of an object returned by a Django QuerySet as a dictionary key prompts Django to look the actual data up.  I had something like the following:</p>
<blockquote><p><code>class WeekData(models.Model):<br />
&nbsp;&nbsp;&nbsp;&nbsp;artist = models.ForeignKey(Artist)<br />
&nbsp;&nbsp;&nbsp;&nbsp;plays  = models.PositiveIntegerField()<br />
&nbsp;&nbsp;&nbsp;&nbsp;..</code><br />
<code><br />
tracking = defaultdict(int)<br />
for week in WeekData.objects.all():<br />
&nbsp;&nbsp;&nbsp;&nbsp;tracking[week.artist] += week.plays<br />
</code>
</p></blockquote>
<p>The dictionary update was taking <em>ages</em>.  Confused, I enabled Mysql&#8217;s logging and discovered 25,000 lines of the following..</p>
<blockquote><p>
<code>SELECT `id`, `name` FROM `muncher_artist` WHERE `id` = 22<br />
SELECT `id`, `name` FROM `muncher_artist` WHERE `id` = 23<br />
SELECT `id`, `name` FROM `muncher_artist` WHERE `id` = 24<br />
SELECT `id`, `name` FROM `muncher_artist` WHERE `id` = 25</code>
</p></blockquote>
<p>At which point I realised that using <code>week.artist</code> as the key here looks up the artist <em>every</em> time, meaning 25,000 useless database queries and a really, really slow function.  Perhaps I was being too hopeful in my expectation that Django would be clever.</p>
<p>Changing the last line to:</p>
<blockquote><p>
<code>tracking[week.artist_id] += week.plays</code></p></blockquote>
<p>sped the function up by a factor of ten and lets me produce images like this in reasonable time:</p>
<p><img src="http://troublewithdreams.com/sometimesiwrite/wp-content/uploads/2010/04/tophist-snippet.png" alt="" title="tophist-snippet" class="aligncenter size-full wp-image-345" /></p>
<p>It&#8217;s showing which artists occupy which chart positions as the weeks go by.  The dark black line is for Fleet Foxes .. seems I went pretty mad for them :o</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2010/04/05/django-experiments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sunburn</title>
		<link>http://troublewithdreams.com/2009/06/11/sunburn/</link>
		<comments>http://troublewithdreams.com/2009/06/11/sunburn/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 22:05:35 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scrobbler]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=271</guid>
		<description><![CDATA[Exams are over, the sun came and went, I got a first (hurrah!), a job for a couple of months and now it&#8217;s just .. working out what now? Completing Chrono Trigger is my first priority :D
Spent some time moving the last.fm charts thing to Python, because Python is tasty, PHP is clumsy, and matplotlib [...]]]></description>
			<content:encoded><![CDATA[<p>Exams are over, the sun came and went, I got a first (hurrah!), a job for a couple of months and now it&#8217;s just .. working out what now? Completing Chrono Trigger is my first priority :D</p>
<p>Spent some time moving the <a href="/scrobbler">last.fm charts</a> thing to Python, because Python is tasty, PHP is clumsy, and <a href="http://matplotlib.sourceforge.net/">matplotlib</a> is a superb piece of kit.</p>
<p>Here&#8217;s a histogram of the number of tracks I&#8217;ve listened to each week for the last few years:</p>
<p><img src="http://troublewithdreams.com/sometimesiwrite/wp-content/uploads/2009/06/last-fm-histogrampng.png" alt="last-fm-histogrampng" title="last-fm-histogrampng" width="516" height="394" class="aligncenter size-full wp-image-285" /></p>
<p>(<em>x</em> is the number of tracks in a week.)  I looked at a few friends&#8217; and there seemed quite a split between those roughly following a Gaussian distribution and those following something rather more exponential.  I should experiment with different features of matplotlib, maybe narrow those bins a little.  I&#8217;ve lots of little plans for other graphs and combinations.</p>
<hr />
<p>Finally, there&#8217;s a great little piece about a quirk of the number 1/89 <a href="http://www.geom.uiuc.edu/~rminer/1over89/">here</a>.  Sum the numbers of the Fibonacci Sequence in the following manner:</p>
<blockquote>
<pre>  .01
  .001
  .0002
  .00003
  .000005
  .0000008
  .00000013
  .000000021
  .0000000034
  .00000000055
  .000000000089
  .0000000000144
        .
    +   .
        .
----------------
  .01123595505...    = 1/89</pre>
</blockquote>
<p>The link has an outline proof about why it&#8217;s true.</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2009/06/11/sunburn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Charts update</title>
		<link>http://troublewithdreams.com/2009/03/24/charts-update/</link>
		<comments>http://troublewithdreams.com/2009/03/24/charts-update/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 13:15:09 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scrobbler]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=256</guid>
		<description><![CDATA[Just a note to say I updated Historical Charts to take advantage of Last.fm automatically correcting misspelled info.
]]></description>
			<content:encoded><![CDATA[<p>Just a note to say I updated <a href="/scrobbler">Historical Charts</a> to take advantage of Last.fm automatically correcting misspelled info.</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2009/03/24/charts-update/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Recursive chmod</title>
		<link>http://troublewithdreams.com/2009/01/22/recursive-chmod/</link>
		<comments>http://troublewithdreams.com/2009/01/22/recursive-chmod/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 16:44:43 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=214</guid>
		<description><![CDATA[Just so I don&#8217;t forget.
Directories only: find . -type d -exec chmod 755 {} \;
Files only : find . -type f -exec chmod 644 {} \;
]]></description>
			<content:encoded><![CDATA[<p>Just so I don&#8217;t forget.</p>
<p>Directories only: <code>find . -type d -exec chmod 755 {} \;</code><br />
Files only : <code>find . -type f -exec chmod 644 {} \;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2009/01/22/recursive-chmod/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extremely Slow Track Chart Updating</title>
		<link>http://troublewithdreams.com/2009/01/05/extremely-slow-track-chart-updating/</link>
		<comments>http://troublewithdreams.com/2009/01/05/extremely-slow-track-chart-updating/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 14:04:00 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[scrobbler]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=223</guid>
		<description><![CDATA[Should be alleviated &#8211; an unindexed query called for each track in a chart list was returning close to a million rows = ouch and hurrah for indexes.
]]></description>
			<content:encoded><![CDATA[<p>Should be alleviated &#8211; an unindexed query called for each track in a chart list was returning close to a million rows = ouch and hurrah for indexes.</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2009/01/05/extremely-slow-track-chart-updating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Life in the Stencil Buffer</title>
		<link>http://troublewithdreams.com/2008/11/25/life-in-the-stencil-buffer/</link>
		<comments>http://troublewithdreams.com/2008/11/25/life-in-the-stencil-buffer/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 13:46:29 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[silly]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=215</guid>
		<description><![CDATA[Stumbling through a load of OpenGL documentation I came across a demonstration of Conway&#8217;s Game of Life using the stencil buffer, which is simultaneously awesome and horrible:
Life in the Stencil Buffer
One way to create this game using OpenGL is to use a multipass algorithm. Keep the data in the color buffer, one pixel for each [...]]]></description>
			<content:encoded><![CDATA[<p>Stumbling through a load of OpenGL documentation I came across a demonstration of Conway&#8217;s <a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life">Game of Life</a> using the stencil buffer, which is simultaneously awesome and horrible:</p>
<blockquote><h3>Life in the Stencil Buffer</h3>
<p>One way to create this game using OpenGL is to use a multipass algorithm. Keep the data in the color buffer, one pixel for each grid point. Assume that black (all zeros) is the background color, and the color of a live pixel is nonzero. Initialize by clearing the depth and stencil buffers to zero, set the depth-buffer writemask to zero, and set the depth comparison function so that it passes on not-equal. To iterate, read the image off the screen, enable drawing into the depth buffer, and set the stencil function so that it increments whenever a depth comparison succeeds but leaves the stencil buffer unchanged otherwise. Disable drawing into the color buffer.</p>
<p>Next, draw the image eight times, offset one pixel in each vertical, horizontal, and diagonal direction. When you&#8217;re done, the stencil buffer contains a count of the number of live neighbors for each pixel. Enable drawing to the color buffer, set the color to the color for live cells, and set the stencil function to draw only if the value in the stencil buffer is 3 (three live neighbors). In addition, if this drawing occurs, decrement the value in the stencil buffer. Then draw a rectangle covering the image; this paints each cell that has exactly three live neighbors with the “alive” color.</p>
<p>At this point, the stencil buffers contain 0, 1, 2, 4, 5, 6, 7, 8, and the values under the 2&#8217;s are correct. The values under 0, 1, 4, 5, 6, 7, and 8 must be cleared to the “dead” color. Set the stencil function to draw whenever the value is not 2, and to zero the stencil values in all cases. Then draw a large polygon of the “dead” color across the entire image. You&#8217;re done.</p>
</blockquote>
<p><a href="http://www710.univ-lyon1.fr/~jciehl/Public/OpenGL_PG/ch15.html#id5553768">http://www710.univ-lyon1.fr/~jciehl/Public/OpenGL_PG/ch15.html#id5553768</a></p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2008/11/25/life-in-the-stencil-buffer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last.fm Historical Charts v2</title>
		<link>http://troublewithdreams.com/2008/08/21/lastfm-historical-charts-v2/</link>
		<comments>http://troublewithdreams.com/2008/08/21/lastfm-historical-charts-v2/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 23:21:34 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scrobbler]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=200</guid>
		<description><![CDATA[I updated my historical charts program to allow album and track charts, make it utf8 compatible and give it a graphical overhaul too, hurrahs all round.
Same process as before &#8211; when you first create each kind of chart it&#8217;ll take a while to fetch your data, subsequent charts will be created a whole lot faster. [...]]]></description>
			<content:encoded><![CDATA[<p>I updated my historical charts program to allow album and track charts, make it utf8 compatible and give it a graphical overhaul too, hurrahs all round.</p>
<p>Same process as before &#8211; when you first create each kind of chart it&#8217;ll take a while to fetch your data, subsequent charts will be created a whole lot faster.  Eventually I&#8217;ll make a script to purge the data stored for anybody who hasn&#8217;t used the program in a couple of months so keep popping back if you get fed up with the waits.</p>
<p>As always comments are welcome.  Oh and suggestions for a better name too..</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2008/08/21/lastfm-historical-charts-v2/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>LastFM Charts</title>
		<link>http://troublewithdreams.com/2008/03/18/lastfm-charts/</link>
		<comments>http://troublewithdreams.com/2008/03/18/lastfm-charts/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 03:05:34 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scrobbler]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/2008/03/18/lastfm-charts/</guid>
		<description><![CDATA[I made my program to generate charts for any date range from LastFM data available to anybody a few weeks ago and it&#8217;s had a positive response, being included on build.last.fm as an interesting extra kindofthing.  Though still nobody has feedback or suggestions.  Maybe in itself it&#8217;s relatively complete and I should think [...]]]></description>
			<content:encoded><![CDATA[<p>I made my <a href="/scrobbler/">program to generate charts for any date range</a> from LastFM data <a href="http://www.last.fm/user/aradnuk/journal/2008/02/23/656429/">available to anybody</a> a few weeks ago and it&#8217;s had a positive response, being included on <a href="http://build.last.fm">build.last.fm</a> as an interesting extra kindofthing.  Though still nobody has feedback or suggestions.  Maybe in itself it&#8217;s relatively complete and I should think of other, related bits and pieces.  Anybody?</p>
<p>I&#8217;ve made it automatically updating, so you only need to add your data once the very first time you visit, and after that it&#8217;ll check whether there should be new charts available.  Maybe it should only happen a few days into the week &#8211; LastFM never get the charts out on time after all..</p>
<p>That and I added a few extra quick links, to 3/6/12/24 months previous.  No more &#8216;wait a month for charts to refresh&#8217; ;-).  I should totally see if I can make this into a greasemonkey script..</p>
<p>PHP&#8217;s <code>strtotime</code> function is no end of brilliance &#8211; <code>strtotime("-6 months")</code> and <code>strtotime("last sunday")</code> are genius conceptions.</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2008/03/18/lastfm-charts/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Hit F5</title>
		<link>http://troublewithdreams.com/2007/02/23/32/</link>
		<comments>http://troublewithdreams.com/2007/02/23/32/#comments</comments>
		<pubDate>Fri, 23 Feb 2007 17:48:02 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[music]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=32</guid>
		<description><![CDATA[
Cool, huh?
]]></description>
			<content:encoded><![CDATA[<p><?php include('http://www.troublewithdreams.com/includes/lastfm/show.php'); ?></p>
<p>Cool, huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2007/02/23/32/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

