<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Our Craft</title>
	<atom:link href="http://ourcraft.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ourcraft.wordpress.com</link>
	<description>Making it better</description>
	<lastBuildDate>Fri, 06 Nov 2009 16:26:16 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='ourcraft.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/41c395194d5d2fc1201d2039ed250d15?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Our Craft</title>
		<link>http://ourcraft.wordpress.com</link>
	</image>
			<item>
		<title>replace_all for C++</title>
		<link>http://ourcraft.wordpress.com/2009/11/06/replace_all-for-c/</link>
		<comments>http://ourcraft.wordpress.com/2009/11/06/replace_all-for-c/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 16:26:16 +0000</pubDate>
		<dc:creator>danielmeyer</dc:creator>
				<category><![CDATA[Technical Stuff]]></category>
		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://ourcraft.wordpress.com/?p=2123</guid>
		<description><![CDATA[I&#8217;m always surprised by some of the basic functionality C++&#8217;s standard library lacks.    This week&#8217;s: a function to replace all occurrences within string x of string a with string b.  Of course it can be done, it&#8217;s just unwieldy given only the standard library facilities.
That&#8217;s why I&#8217;m so thankful for the Boost libraries.  Looks like [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2123&subd=ourcraft&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m always surprised by some of the basic functionality C++&#8217;s standard library lacks.    This week&#8217;s: a function to replace all occurrences within string <em>x</em> of string <em>a</em> with string <em>b</em>.  Of course it can be done, it&#8217;s just unwieldy given only the standard library facilities.</p>
<p>That&#8217;s why I&#8217;m so thankful for the <a href="http://boost.org">Boost</a> libraries.  Looks like &lt;<a title="Header &lt;boost/algorithm/string/replace.hpp&gt;" href="http://www.boost.org/doc/libs/1_40_0/doc/html/string_algo/reference.html#header.boost.algorithm.string.replace_hpp">boost/algorithm/string/replace.hpp</a>&gt;&#8217;s <a href="http://www.boost.org/doc/libs/1_40_0/doc/html/boost/algorithm/replace_all.html">replace_all()</a> or <a href="http://www.boost.org/doc/libs/1_40_0/doc/html/boost/algorithm/replace_all_copy.html">replace_all_copy()</a> would do the trick!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ourcraft.wordpress.com/2123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ourcraft.wordpress.com/2123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ourcraft.wordpress.com/2123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ourcraft.wordpress.com/2123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ourcraft.wordpress.com/2123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ourcraft.wordpress.com/2123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ourcraft.wordpress.com/2123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ourcraft.wordpress.com/2123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ourcraft.wordpress.com/2123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ourcraft.wordpress.com/2123/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2123&subd=ourcraft&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ourcraft.wordpress.com/2009/11/06/replace_all-for-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">danielmeyer</media:title>
		</media:content>
	</item>
		<item>
		<title>Is it an assigment or a copy construct?</title>
		<link>http://ourcraft.wordpress.com/2009/10/27/is-it-an-assigment-or-a-copy-construct/</link>
		<comments>http://ourcraft.wordpress.com/2009/10/27/is-it-an-assigment-or-a-copy-construct/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 14:17:53 +0000</pubDate>
		<dc:creator>danielmeyer</dc:creator>
				<category><![CDATA[Technical Stuff]]></category>
		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://ourcraft.wordpress.com/?p=2112</guid>
		<description><![CDATA[Suppose we have the following code:
myclass a;
myclass b = a;

Does the  second line invoke b&#8217;s default constructor and then the assignment operator?  Wouldn&#8217;t it be more efficient to rewrite it like this:
myclass b(a);
Actually, though, the first and second versions are equivalent: both result in a single copy constructor call; neither one uses the assignment operator.
Let&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2112&subd=ourcraft&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Suppose we have the following code:</p>
<pre style="padding-left:30px;">myclass a;
myclass b = a;
</pre>
<p>Does the  second line invoke b&#8217;s default constructor and then the assignment operator?  Wouldn&#8217;t it be more efficient to rewrite it like this:</p>
<pre style="padding-left:30px;">myclass b(a);</pre>
<p>Actually, though, the first and second versions are equivalent: both result in a single copy constructor call; neither one uses the assignment operator.</p>
<p>Let&#8217;s try an example to demonstrate this.</p>
<pre class="brush: cpp;">
#include &lt;iostream&gt;

class myclass
{
private:
    std::string innards;
public:
    myclass&amp; operator=(const myclass&amp; c);
    myclass(const myclass&amp; c);
    myclass();
    ~myclass();
};

myclass&amp; myclass::operator=(const myclass&amp; c)
{
    std::cout &lt;&lt; &quot;myclass::operator=\n&quot;;
    if(&amp;c != this)
    {
        innards = c.innards;
    }
    return *this;
}

myclass::myclass(const myclass&amp; c)
 : innards(c.innards)
{
    std::cout &lt;&lt; &quot;myclass::myclass(const myclass&amp; c)\n&quot;;
}

myclass::myclass()
{
    std::cout &lt;&lt; &quot;myclass::myclass()\n&quot;;
}

myclass::~myclass()
{
    std::cout &lt;&lt; &quot;myclass::~myclass()\n&quot;;
}

int main(void)
{
    myclass a;
    myclass b = a;
    return 0;
}
</pre>
<p>The output  is:</p>
<pre style="padding-left:30px;">myclass::myclass()
myclass::myclass(const myclass&amp; c)
myclass::~myclass()
myclass::~myclass()
</pre>
<p>A default construct, a copy construct, and two destructs.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ourcraft.wordpress.com/2112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ourcraft.wordpress.com/2112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ourcraft.wordpress.com/2112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ourcraft.wordpress.com/2112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ourcraft.wordpress.com/2112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ourcraft.wordpress.com/2112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ourcraft.wordpress.com/2112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ourcraft.wordpress.com/2112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ourcraft.wordpress.com/2112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ourcraft.wordpress.com/2112/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2112&subd=ourcraft&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ourcraft.wordpress.com/2009/10/27/is-it-an-assigment-or-a-copy-construct/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">danielmeyer</media:title>
		</media:content>
	</item>
		<item>
		<title>4040404</title>
		<link>http://ourcraft.wordpress.com/2009/10/24/4040404/</link>
		<comments>http://ourcraft.wordpress.com/2009/10/24/4040404/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 17:53:02 +0000</pubDate>
		<dc:creator>danielmeyer</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Technical Stuff]]></category>

		<guid isPermaLink="false">http://ourcraft.wordpress.com/?p=2058</guid>
		<description><![CDATA[
I thought this was funny: the other day I browsed to a nonexistent URL at a website, and because that page was not found it redirected me to 404.html &#8230;which also was not found.  So I ended up getting a 404 Not Found error on 404.html.  Cool!
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2058&subd=ourcraft&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://ourcraft.files.wordpress.com/2009/10/40404.png"><img class="alignnone size-full wp-image-2059" title="40404" src="http://ourcraft.files.wordpress.com/2009/10/40404.png?w=404&#038;h=295" alt="40404" width="404" height="295" /></a></p>
<p>I thought this was funny: the other day I browsed to a nonexistent URL at a website, and because that page was not found it redirected me to 404.html &#8230;which also was not found.  So I ended up getting a 404 Not Found error on 404.html.  Cool!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ourcraft.wordpress.com/2058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ourcraft.wordpress.com/2058/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ourcraft.wordpress.com/2058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ourcraft.wordpress.com/2058/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ourcraft.wordpress.com/2058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ourcraft.wordpress.com/2058/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ourcraft.wordpress.com/2058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ourcraft.wordpress.com/2058/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ourcraft.wordpress.com/2058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ourcraft.wordpress.com/2058/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2058&subd=ourcraft&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ourcraft.wordpress.com/2009/10/24/4040404/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">danielmeyer</media:title>
		</media:content>

		<media:content url="http://ourcraft.files.wordpress.com/2009/10/40404.png" medium="image">
			<media:title type="html">40404</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple GUI with Python and TKinter</title>
		<link>http://ourcraft.wordpress.com/2009/10/22/simple-gui-with-python-and-tkinter/</link>
		<comments>http://ourcraft.wordpress.com/2009/10/22/simple-gui-with-python-and-tkinter/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 12:39:14 +0000</pubDate>
		<dc:creator>danielmeyer</dc:creator>
				<category><![CDATA[Technical Stuff]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[TKinter]]></category>

		<guid isPermaLink="false">http://ourcraft.wordpress.com/?p=2105</guid>
		<description><![CDATA[It would be nice to have a way to build quick-n-dirty GUIs so I can GUI-enable tools when that makes sense&#8230; but I&#8217;ve always just had a mental block about &#8220;going to that length&#8221;.
Yesterday though, I was flipping through Python in a Nutshell and I saw a GUI example there (p. 329) that was so [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2105&subd=ourcraft&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>It would be nice to have a way to build quick-n-dirty GUIs so I can GUI-enable tools when that makes sense&#8230; but I&#8217;ve always just had a mental block about &#8220;going to that length&#8221;.</p>
<p>Yesterday though, I was flipping through <em>Python in a Nutshell</em> and I saw a GUI example there (p. 329) that was so simple I typed it in and tried it out :</p>
<pre class="brush: python;">
import sys, Tkinter
Tkinter.Label(text=&quot;Welcome!&quot;).pack()
Tkinter.Button(text=&quot;Exit&quot;, command=sys.exit).pack()
Tkinter.mainloop()
</pre>
<p>That yields a simple little dialog:</p>
<p><a href="http://ourcraft.files.wordpress.com/2009/10/hellotk-1.png"><img class="alignnone size-full wp-image-2106" title="hellotk-1" src="http://ourcraft.files.wordpress.com/2009/10/hellotk-1.png?w=123&#038;h=76" alt="hellotk-1" width="123" height="76" /></a></p>
<p>&#8230;that can be resized:</p>
<p><a href="http://ourcraft.files.wordpress.com/2009/10/hellotk-2.png"><img class="alignnone size-full wp-image-2107" title="hellotk-2" src="http://ourcraft.files.wordpress.com/2009/10/hellotk-2.png?w=391&#038;h=214" alt="hellotk-2" width="391" height="214" /></a></p>
<p>I need to try some more of this!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ourcraft.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ourcraft.wordpress.com/2105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ourcraft.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ourcraft.wordpress.com/2105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ourcraft.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ourcraft.wordpress.com/2105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ourcraft.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ourcraft.wordpress.com/2105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ourcraft.wordpress.com/2105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ourcraft.wordpress.com/2105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2105&subd=ourcraft&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ourcraft.wordpress.com/2009/10/22/simple-gui-with-python-and-tkinter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">danielmeyer</media:title>
		</media:content>

		<media:content url="http://ourcraft.files.wordpress.com/2009/10/hellotk-1.png" medium="image">
			<media:title type="html">hellotk-1</media:title>
		</media:content>

		<media:content url="http://ourcraft.files.wordpress.com/2009/10/hellotk-2.png" medium="image">
			<media:title type="html">hellotk-2</media:title>
		</media:content>
	</item>
		<item>
		<title>Defining your C++ template in a .cpp file</title>
		<link>http://ourcraft.wordpress.com/2009/10/21/defining-your-c-template-in-a-cpp-file/</link>
		<comments>http://ourcraft.wordpress.com/2009/10/21/defining-your-c-template-in-a-cpp-file/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 21:01:24 +0000</pubDate>
		<dc:creator>danielmeyer</dc:creator>
				<category><![CDATA[Technical Stuff]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://ourcraft.wordpress.com/?p=2103</guid>
		<description><![CDATA[Normally all your C++ template classes are implemented in their header files, and when we  tried to move the definition of a template class out to a .cpp file, the compiler complained.  I thought I remembered reading in Stroustrup&#8217;s The C++ Programming Language of  a keyword   that could help with this very issue, last [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2103&subd=ourcraft&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Normally all your C++ template classes are implemented in their header files, and when we  tried to move the definition of a template class out to a .cpp file, the compiler complained.  I thought I remembered reading in Stroustrup&#8217;s <em>The C++ Programming Language</em> of  a keyword   that could help with this very issue, last time I was doing C++ programming.  A little digging turned up the name of the keyword: <code>export</code> (TC++PL §9.2.3).  However, it&#8217;s <a href="http://www.parashift.com/c++-faq-lite/templates.html#faq-35.14">currently not a good option</a> (also see <a href="http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12">the beginning of the discussion</a>).</p>
<p>So, back into the header it goes.  :)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ourcraft.wordpress.com/2103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ourcraft.wordpress.com/2103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ourcraft.wordpress.com/2103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ourcraft.wordpress.com/2103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ourcraft.wordpress.com/2103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ourcraft.wordpress.com/2103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ourcraft.wordpress.com/2103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ourcraft.wordpress.com/2103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ourcraft.wordpress.com/2103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ourcraft.wordpress.com/2103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2103&subd=ourcraft&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ourcraft.wordpress.com/2009/10/21/defining-your-c-template-in-a-cpp-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">danielmeyer</media:title>
		</media:content>
	</item>
		<item>
		<title>playcd</title>
		<link>http://ourcraft.wordpress.com/2009/10/21/playcd/</link>
		<comments>http://ourcraft.wordpress.com/2009/10/21/playcd/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 14:18:01 +0000</pubDate>
		<dc:creator>danielmeyer</dc:creator>
				<category><![CDATA[Technical Stuff]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ourcraft.wordpress.com/?p=2088</guid>
		<description><![CDATA[Here is a simple CD player/pauser written in Python:

# Playcd.py - Play or pause an audio CD
# Author: Daniel S. Meyer
# Version 0.1
#
# Usage: python playcd.py
# (On Windows you can create a shortcut whose target is for example
# C:\installs\python\python.exe c:\bin\playcd.py , and place it on
# your Windows desktop.  Then you can assign a shortcut [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2088&subd=ourcraft&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Here is a simple CD player/pauser written in Python:</p>
<pre class="brush: python;">
# Playcd.py - Play or pause an audio CD
# Author: Daniel S. Meyer
# Version 0.1
#
# Usage: python playcd.py
# (On Windows you can create a shortcut whose target is for example
# C:\installs\python\python.exe c:\bin\playcd.py , and place it on
# your Windows desktop.  Then you can assign a shortcut key (say,
# Ctrl+Alt+P) to that shortcut.  Now you can play and pause your
# CD by pressing the key combination.)
#
# TODOs:
# - When saving the state, also save the list
#   of tracks (or at least the number of tracks) so
#   we can detect if the CD is changed and not &quot;resume&quot;
#   in the middle of a different CD.
# - Add options for next/previous tracks
# - Detect if a track is an audio track before attempting to play it
# - Support playing a device other than the first one
# 

import pygame,os

def get_state_file_name():
    return os.environ['TEMP']+'/playcd-state.tmp'

pygame.cdrom.init()
cd0 = pygame.cdrom.CD(0)
cd0.init()
if cd0.get_busy():
    # Currently playing: pause it
    cd0.pause()

    # Save our state for later resume
    cdstate = open(get_state_file_name(),'w')
    cdstate.write(str(cd0.get_current()[0]) + '\n') # current track
    cdstate.write(str(cd0.get_current()[1])) # position within track
    cdstate.close()
else:
    # Not currently playing: try to resume from saved state
    try:
      cdstate = open(get_state_file_name(), 'r')
      curtrack = int(cdstate.readline())
      pos = float(cdstate.readline())
      cdstate.close()
      os.remove(get_state_file_name())
    except:
      # If anything goes wrong restoring our state,
      # just start playing at the beginning
      curtrack = 0
      pos = 0

    cd0.play(curtrack,pos,None)

    # Work around bug where only first track plays
    cd0.pause()
    cd0.resume()

cd0.quit()
pygame.cdrom.quit()
</pre>
<p>I set up the shortcut and shortcut key as described in the comments.  Now I can play or pause an audio CD by pressing Ctrl+P.</p>
<p>(&#8216;Course, I could have avoided this whole issue by getting a multimedia keyboard that has play and pause buttons on it&#8230; but then how would I learn Python? ;)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ourcraft.wordpress.com/2088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ourcraft.wordpress.com/2088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ourcraft.wordpress.com/2088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ourcraft.wordpress.com/2088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ourcraft.wordpress.com/2088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ourcraft.wordpress.com/2088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ourcraft.wordpress.com/2088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ourcraft.wordpress.com/2088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ourcraft.wordpress.com/2088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ourcraft.wordpress.com/2088/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2088&subd=ourcraft&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ourcraft.wordpress.com/2009/10/21/playcd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">danielmeyer</media:title>
		</media:content>
	</item>
		<item>
		<title>Codesample CSS style</title>
		<link>http://ourcraft.wordpress.com/2009/10/20/codesample-css-style/</link>
		<comments>http://ourcraft.wordpress.com/2009/10/20/codesample-css-style/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 15:04:48 +0000</pubDate>
		<dc:creator>danielmeyer</dc:creator>
				<category><![CDATA[Technical Stuff]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://ourcraft.wordpress.com/?p=2082</guid>
		<description><![CDATA[When I have source code or want to demonstrate typing at the console, I&#8217;d like to show that highlighted in a certain way.  I know precious little CSS, but here&#8217;s the pinnacle of my current achievement:  the code sample box:
int x = 5;
++x;
To accomplish this, I first define the codesample style*:
&#60;style&#62;
.codesample {border:thin solid [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2082&subd=ourcraft&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>When I have source code or want to demonstrate typing at the console, I&#8217;d like to show that highlighted in a certain way.  I know precious little CSS, but here&#8217;s the pinnacle of my current achievement:  the code sample box:</p>
<pre class="codesample">int x = 5;
++x;</pre>
<p>To accomplish this, I first define the <code>codesample</code> style*:</p>
<pre>&lt;style&gt;
.codesample {border:thin solid gray; padding-left:3em; font-family:Courier,monospace;
             background-color:#eeeeee; color:black;}
&lt;/style&gt;</pre>
<p>When I want to make use of this style, I just use a &lt;pre&gt; tag with a class of <code>codesample</code>:</p>
<pre>&lt;pre class="codesample"&gt;
int x = 5;
++x;
&lt;/pre&gt;</pre>
<p>&#8230;which yields the look featured at the top.</p>
<p>Next step: Right now I  redefine the codesample style in each internal blog post.  As an alternative, there are <a href="http://www.htmlhelp.com/reference/css/style-html.html#external">a couple</a> of <a href="http://www.htmlhelp.com/reference/css/style-html.html#importing">ways</a> to specify an external style sheet&#8230;maybe I&#8217;ll eventually set that up in SharePoint and have each post that needs it just point to that.</p>
<p>*(Here on WordPress I&#8217;ve purchased the custom CSS upgrade and I just put the .codesample part in the custom CSS area of the blog site admin; but for a SharePoint blog post I would do as above, putting the &lt;style&gt; tag in the body of the post**.)</p>
<p>**The &lt;style&gt; element is <a href="http://www.htmlhelp.com/reference/css/style-html.html#embedding">supposed to be in the &lt;head&gt;</a> of an HTML document, not the &lt;body&gt;&#8230; possibly you can get at the &lt;head&gt; and do this more properly &#8211; I just don&#8217;t know how a the moment.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ourcraft.wordpress.com/2082/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ourcraft.wordpress.com/2082/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ourcraft.wordpress.com/2082/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ourcraft.wordpress.com/2082/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ourcraft.wordpress.com/2082/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ourcraft.wordpress.com/2082/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ourcraft.wordpress.com/2082/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ourcraft.wordpress.com/2082/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ourcraft.wordpress.com/2082/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ourcraft.wordpress.com/2082/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2082&subd=ourcraft&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ourcraft.wordpress.com/2009/10/20/codesample-css-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">danielmeyer</media:title>
		</media:content>
	</item>
		<item>
		<title>Link getter</title>
		<link>http://ourcraft.wordpress.com/2009/10/20/link-getter/</link>
		<comments>http://ourcraft.wordpress.com/2009/10/20/link-getter/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 13:12:45 +0000</pubDate>
		<dc:creator>danielmeyer</dc:creator>
				<category><![CDATA[Technical Stuff]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ourcraft.wordpress.com/?p=2067</guid>
		<description><![CDATA[As I learn Python, I&#8217;m writing some little helper scripts.  Here&#8217;s the latest, a script that prints all the .mp3 links referenced by a page (or pages) to standard output:

# mp3s.py
#
# Purpose: display all .mp3 links in the pages
#   pointed to by the given URLs
#
# Usage: python mp3s.py url [url2 [url3...]]
#
# Author: Daniel [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2067&subd=ourcraft&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As I learn Python, I&#8217;m writing some little helper scripts.  Here&#8217;s the latest, a script that prints all the .mp3 links referenced by a page (or pages) to standard output:</p>
<pre class="brush: python;">
# mp3s.py
#
# Purpose: display all .mp3 links in the pages
#   pointed to by the given URLs
#
# Usage: python mp3s.py url [url2 [url3...]]
#
# Author: Daniel Meyer
# Date: Oct 20, 2009
import sys
import urllib2
from HTMLParser import HTMLParser

class LinkFinder(HTMLParser):
  def __init__(self):
    HTMLParser.__init__(self)
    self.links = []

  def handle_starttag(self, tag, attrs):
    if tag == 'a':
      for attr, value in attrs:
        if attr == 'href':
          self.links.append(value)

for url in sys.argv[1:] :
  page = urllib2.urlopen(url)
  linkFinder = LinkFinder()
  linkFinder.feed(page.read())
  linkFinder.close()

  for link in linkFinder.links:
    if link.find('.mp3') != -1:
      print link
</pre>
<p>Notice lines 15-17, which were required to initialize the <code>links</code> data member (since while still calling the base class constructor.</p>
<p>I&#8217;ve found this type of thing helpful when preparing to download conference audio where there are several individual mp3 links &#8211; I can then pipe the output through xargs to wget to download &#8216;em:</p>
<p><code>python mp3s.py http://www.t4g.org/conference/t4g-2006/ | xargs wget</code></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ourcraft.wordpress.com/2067/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ourcraft.wordpress.com/2067/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ourcraft.wordpress.com/2067/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ourcraft.wordpress.com/2067/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ourcraft.wordpress.com/2067/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ourcraft.wordpress.com/2067/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ourcraft.wordpress.com/2067/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ourcraft.wordpress.com/2067/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ourcraft.wordpress.com/2067/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ourcraft.wordpress.com/2067/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2067&subd=ourcraft&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ourcraft.wordpress.com/2009/10/20/link-getter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">danielmeyer</media:title>
		</media:content>
	</item>
		<item>
		<title>When&#8217;s the payoff?</title>
		<link>http://ourcraft.wordpress.com/2009/10/15/whens-the-payoff/</link>
		<comments>http://ourcraft.wordpress.com/2009/10/15/whens-the-payoff/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 16:42:49 +0000</pubDate>
		<dc:creator>danielmeyer</dc:creator>
				<category><![CDATA[Technical Stuff]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[indirection]]></category>

		<guid isPermaLink="false">http://ourcraft.wordpress.com/?p=2056</guid>
		<description><![CDATA[I put my home mortgage in an Excel spreadsheet so I could run scenarios:  if we pay $200 extra per month, how long is it till payoff?  What if we do $300 extra per month?  No  extra per month?  Each time I changed the pay-extra amount though, I&#8217;d have to scroll down to see what [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2056&subd=ourcraft&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I put my home mortgage in an Excel spreadsheet so I could run scenarios:  if we pay $200 extra per month, how long is it till payoff?  What if we do $300 extra per month?  No  extra per month?  Each time I changed the pay-extra amount though, I&#8217;d have to scroll down to see what month the payoff would be.</p>
<h3>Finding the row</h3>
<p>First I needed to somehow search the &#8220;Balance&#8221; column for the first cell whose value was zero.  This was accomplished with the following function:</p>
<pre style="padding-left:30px;">=MATCH(0,B:B,0)</pre>
<p>Explanation of the parameters:</p>
<ol>
<li><code>0</code> &#8211; the  value we&#8217;re looking for</li>
<li><code>B:B</code> &#8211; the column we&#8217;re searching</li>
<li><code>0</code> &#8211;  the match type (we need match type 0 because the other search types require that the values be in ascending order but our balance values are in <em>de</em>scending order (the same reason we can&#8217;t use LOOKUP or VLOOKUP))</li>
</ol>
<p>This formula gives a value like 117 (the first row where there&#8217;s a zero balance).  Now we need to turn that into a date&#8230;</p>
<h3>Displaying the payoff date</h3>
<p>For this we&#8217;ll use the INDIRECT function, which takes a cell address as a string.  In my spreadsheet, the balance amounts are in column B and the month/year dates are beside them in column A, so if the row were 117, the formula for showing the month would be =INDIRECT(&#8220;A117&#8243;) .  Of course, if we knew it was in cell A117, we&#8217;d just use A117 instead of INDIRECT(&#8220;A117&#8243;), but we can&#8217;t hardcode the row &#8211; we need to get it from the match calculation.  The address of the cell containing our payoff date, then, is:</p>
<pre style="padding-left:30px;">"A"&amp;MATCH(0,B:B,0)</pre>
<h3>Final formula</h3>
<p>Putting it all together, here is the formula we&#8217;ll put near the top of the spreadsheet so that we can quickly see the payoff date as we change the amount of extra paid:</p>
<pre style="padding-left:30px;">=INDIRECT("A"&amp;MATCH(0,B:B,0))</pre>
<p>(Thanks to Aladin for his <a href="http://www.mrexcel.com/forum/showpost.php?s=a65920735164e2bdc487f6b86dfb72a1&amp;p=69962&amp;postcount=2">post to the MrExcel message board</a>, which got me started toward this solution.)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ourcraft.wordpress.com/2056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ourcraft.wordpress.com/2056/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ourcraft.wordpress.com/2056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ourcraft.wordpress.com/2056/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ourcraft.wordpress.com/2056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ourcraft.wordpress.com/2056/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ourcraft.wordpress.com/2056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ourcraft.wordpress.com/2056/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ourcraft.wordpress.com/2056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ourcraft.wordpress.com/2056/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2056&subd=ourcraft&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ourcraft.wordpress.com/2009/10/15/whens-the-payoff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">danielmeyer</media:title>
		</media:content>
	</item>
		<item>
		<title>Gears &amp; sprockets</title>
		<link>http://ourcraft.wordpress.com/2009/10/13/gears-sprockets/</link>
		<comments>http://ourcraft.wordpress.com/2009/10/13/gears-sprockets/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 18:35:29 +0000</pubDate>
		<dc:creator>danielmeyer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bicycles]]></category>

		<guid isPermaLink="false">http://ourcraft.wordpress.com/?p=2027</guid>
		<description><![CDATA[
My beloved three-speed bicycle had three problems, one after the other.
First, the rear tire went flat.
After I fixed that, the chain would  skip gears (or at least it felt that way).
After I fixed that, something was slipping, such that when I pedaled hard, some of the effort was lost to just making the rear gear [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2027&subd=ourcraft&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://ourcraft.files.wordpress.com/2009/10/no-longer-slipping.jpg"><img class="alignnone size-full wp-image-2029" title="no-longer-slipping" src="http://ourcraft.files.wordpress.com/2009/10/no-longer-slipping.jpg?w=315&#038;h=238" alt="no-longer-slipping" width="315" height="238" /></a></p>
<p>My beloved three-speed bicycle had three problems, one after the other.</p>
<p>First, the rear tire went flat.</p>
<p>After I fixed that, the chain would  skip gears (or at least it felt that way).</p>
<p>After I fixed that, something was slipping, such that when I pedaled hard, some of the effort was lost to just making the rear gear spin.  This made for mushy pedaling.</p>
<p>I can hear the clamoring begin to rise: &#8220;Throw the old thing away already!  Get a new one!&#8221;</p>
<p>Now, now&#8230; this is my legacy system and it meets my requirements.  :)  I just want to write down what I did for the latter two fixes, since I think I&#8217;ve experienced these same issues in the past and forgot:</p>
<h3>Skipping Gears Fix</h3>
<p>Why was the chain skipping gears?  I never could see it happening, but I do know that increasing the tension of the chain (by loosening the rear axle and moving it backward) fixed that issue.</p>
<h3>Mushy Pedaling Fix</h3>
<p>Why was the pedaling mushy?  When I fixed the slipping gears problem, I moved the serrated washers (<a href="http://images.google.com/images?hl=en&amp;um=1&amp;sa=1&amp;q=serrated+washers&amp;aq=f&amp;oq=&amp;aqi=&amp;start=0">these</a> might give the idea) on the rear axle from the inner side of the metal frame to the outer side.  I don&#8217;t remember why I did this, but it seems to have enabled the mushy slippage.  I moved the serrated washers back to the inner side of the frame (working to maintain chain tension!) and the mushiness evaporated.</p>
<p>No unit tests&#8230; a lot of moving parts&#8230; you start to get scared to change anything&#8230; hmm!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ourcraft.wordpress.com/2027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ourcraft.wordpress.com/2027/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ourcraft.wordpress.com/2027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ourcraft.wordpress.com/2027/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ourcraft.wordpress.com/2027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ourcraft.wordpress.com/2027/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ourcraft.wordpress.com/2027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ourcraft.wordpress.com/2027/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ourcraft.wordpress.com/2027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ourcraft.wordpress.com/2027/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ourcraft.wordpress.com&blog=2431618&post=2027&subd=ourcraft&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ourcraft.wordpress.com/2009/10/13/gears-sprockets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">danielmeyer</media:title>
		</media:content>

		<media:content url="http://ourcraft.files.wordpress.com/2009/10/no-longer-slipping.jpg" medium="image">
			<media:title type="html">no-longer-slipping</media:title>
		</media:content>
	</item>
	</channel>
</rss>