<?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>Ultra High &#187; Code</title>
	<atom:link href="http://ultrahigh.org/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://ultrahigh.org</link>
	<description>Cosmic Rays, Code and Life in New York</description>
	<lastBuildDate>Wed, 16 Sep 2009 21:05:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Picflick 1.2</title>
		<link>http://ultrahigh.org/2009/06/15/picflick-1-2/</link>
		<comments>http://ultrahigh.org/2009/06/15/picflick-1-2/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 10:08:27 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://ultrahigh.org/?p=92</guid>
		<description><![CDATA[Quick update to picflick, fixing a $PATH bug in picflick_starter and using &#8216;nice&#8217; when resizing the images.
]]></description>
			<content:encoded><![CDATA[<p>Quick update to <a href="/picflick">picflick</a>, fixing a $PATH bug in picflick_starter and using &#8216;nice&#8217; when resizing the images.</p>
]]></content:encoded>
			<wfw:commentRss>http://ultrahigh.org/2009/06/15/picflick-1-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>picflick: Picasa To Flickr Export on Linux</title>
		<link>http://ultrahigh.org/2008/12/09/picflick-picasa-to-flickr-export-on-linux/</link>
		<comments>http://ultrahigh.org/2008/12/09/picflick-picasa-to-flickr-export-on-linux/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 19:40:45 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[picasa]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://ultrahigh.org/?p=75</guid>
		<description><![CDATA[I&#8217;ve adapted the pragmatic-looking picasa2flickr Picasa plugin to work in Picasa 3 on Linux. Instead of feeding the Picasa files to a graphical Flickr uploader, it uploads them automatically using a perl utility called &#8216;flickr_upload&#8217;. Hopefully one or two people will find this useful.
Find it at picflick.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve adapted the pragmatic-looking <a href="http://picasa2flickr.sourceforge.net/install_v2.html">picasa2flickr</a> Picasa plugin to work in Picasa 3 on Linux. Instead of feeding the Picasa files to a graphical Flickr uploader, it uploads them automatically using a perl utility called &#8216;flickr_upload&#8217;. Hopefully one or two people will find this useful.</p>
<p>Find it at <a href="http://ultrahigh.org/picflick/">picflick</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ultrahigh.org/2008/12/09/picflick-picasa-to-flickr-export-on-linux/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Command-line face detection</title>
		<link>http://ultrahigh.org/2008/10/14/command-line-face-detection/</link>
		<comments>http://ultrahigh.org/2008/10/14/command-line-face-detection/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 09:13:10 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://ultrahigh.org/?p=42</guid>
		<description><![CDATA[This post explains how to:

Take a facial portrait and detect the position of the face
Cut a facial portrait down the center and remove half of the picture so that kids can fill it in themselves.
Print a massive amount of JPEGs at once by putting them in a PDF.

I&#8217;m in the Eastern Cape, South Africa now, [...]]]></description>
			<content:encoded><![CDATA[<p>This post explains how to:</p>
<ol>
<li>Take a facial portrait and detect the position of the face</li>
<li>Cut a facial portrait down the center and remove half of the picture so that kids can fill it in themselves.</li>
<li>Print a massive amount of JPEGs at once by putting them in a PDF.</li>
</ol>
<p><a href="http://africa.potatoriot.com">I&#8217;m in the Eastern Cape, South Africa now</a>, working with orphans and vulnerable children. Alex and I are spending some of our time on art projects in remote rural areas, and one of the projects is an idea we stole from an orphanage in Cape Town: take a digital portrait of a child&#8217;s face, crop it down the center, print it and let them draw the other side of the face. Like this one Alex did:</p>
<div id="attachment_45" class="wp-caption aligncenter" style="width: 510px"><a href="http://ultrahigh.org/wp-content/uploads/2008/10/img_6238_500.jpg"><img class="size-full wp-image-45" title="Half-face portrait" src="http://ultrahigh.org/wp-content/uploads/2008/10/img_6238_500.jpg" alt="Alex's half-face portrait" width="500" height="375" /></a><p class="wp-caption-text">Half-face portrait</p></div>
<p>The first time we did this, we went out to the rural area, took pictures of about 16 kids and then spent an hour or two processing the pictures and printing. The processing involved:</p>
<ol>
<li> Importing the pictures to Picassa, straightening some of them and cropping others. (Yes, I know Picassa is not Free/Libre, but F-spot (in Ubuntu Hardy) is dog slow to display pictures and doesn&#8217;t have the straighten function).</li>
<li>Exporting to a directory, then opening each file in GIMP and cropping the right-or-left hand side of the face away.</li>
<li>Combine all the JPEG images into a PDF so they&#8217;re easy to print.</li>
</ol>
<p>The second time, we did the project at a school, for 60+ pupils. The straightening/cropping in Picassa took about ten minutes (since most of the pictures didn&#8217;t need much work). The open-crop-save-close process in GIMP took about thirty seconds per picture and was both repetitive and highly mouse intensive so that we both got hand cramps after a while.</p>
<p>So, after watching Alex do the process for a second class at the school, I decided there must be a better way: automatic face detection. Lo-and-behold, five minutes of Googling got me to <a href="http://torch3vision.idiap.ch/">Torch3Vision</a>, an image recognition toolkit with built-in face detection. It definitely works, but it takes quite a little setting up, so here&#8217;s a guide.</p>
<ol>
<li><a href="http://torch3vision.idiap.ch/downloads.php">Download Torch3Vision</a> and un-tar it: <span class="monospace">tar -zxf Torch3vision2.1.tgz</span></li>
<li>Build Torch3vision: <span class="monospace">cp Linux_i686.cfg.vision2.1 Linux_i686.cfg</span> <span class="monospace">./torch3make</span></li>
<li>Build the vison examples for face detection:<span class="monospace">cd vision2.1/examples/facedetect/</span><br />
<span class="monospace">../../../torch3make *.cc</span></li>
</ol>
<p>So now we have a working set of face-detection programmes. The command line interface isn&#8217;t too friendly, so they take a little playing around. For starters, the binaries on my Ubuntu system don&#8217;t read JPEG images (although the code seems to be there, the build system is non-standard and didn&#8217;t automatically pick up my jpeg libraries. So, I needed to convert my images to PPM format, which is one of those image formats that no-one uses but somehow is the lowest common denominator for image processing command line apps. I use the program &#8216;jpegtopnm&#8217; from package &#8216;netpbm&#8217;.</p>
<span class="monospace">jpegtopnm andy.jpg &gt; andy.ppm</span>
<p>Of the three facial detection programs available, I found &#8216;mlpcascadescan&#8217; to be the most effective and quickest, although they all have similar interfaces so this will basically be the same for all of them. We need to pass the source image and the model file, and we tell it to write the face position and to save a drawing with the face detected:</p>
<span class="monospace">mlpcascadescan andy.ppm -savepos -draw \<br />
-model ~/temp/models/mlp-cascade19&#215;19-20-2-110</span>
<p>This command takes about 20s to run on my creaky old laptop, and creates two files. One is a greyscale visualization of the face detected (the original image was colour):</p>
<div id="attachment_49" class="wp-caption aligncenter" style="width: 510px"><a href="http://ultrahigh.org/wp-content/uploads/2008/10/andy_500-detect.jpg"><img class="size-full wp-image-49" title="andy_500-detect" src="http://ultrahigh.org/wp-content/uploads/2008/10/andy_500-detect.jpg" alt="Face detected, more or less" width="500" height="375" /></a><p class="wp-caption-text">Face detected, more or less</p></div>
<p>The other file &#8216;andy.pos&#8217; contains the results of face detection. Line one is the number of detections, then each line has format <span class="monospace">x y w h</span>, very easy to parse.</p>
<span class="monospace">    FACE_POS=`head -n 2 &#8220;andy.pos | tail -n 1`<br />
FACE_X=`echo $FACE_POS | awk &#8216;{print $1}&#8217;`<br />
FACE_W=`echo $FACE_POS | awk &#8216;{print $3}&#8217;`<br />
FACE_CENTER=`echo $FACE_X + $FACE_W/2 | bc`</span>
<p>I played around with the step-factors in the x and y directions to shave a second or so off the face detection routine, the values I chose were 0.1 and 0.2 respectively (I don&#8217;t need any accuracy in the y direction really, since my use is to cut the face down the middle).</p>
<p>Then, since these are portrait photographs, I can speed up face detection by setting a minimum size for the face. I experimented and one sixth of the total image width gave good results &#8211; any larger and the face detection would fail with a crash. Adding this constraint provides better than 10X speed up, since the algorithm doesn&#8217;t waste time searching for small faces.</p>
<span class="monospace">WIDTH=`identify -format &#8220;%w&#8221; &#8220;andy.jpg&#8221;`<br />
MIN_FACE_WIDTH=`echo $WIDTH / 6 | bc`</span>
<p>So now here&#8217;s the final face detection command</p>
<span class="monospace">mlpcascadescan &#8220;$ppm&#8221; -dir /tmp/ -savepos -model $MODEL \<br />
-minWsize $MIN_FACE_WIDTH -stepxfactor $STEPX -stepyfactor $STEPY</span>
<p>And finally, as promised, I&#8217;ll tell you how to blank-out one side of the face: of course, using <a href="http://www.imagemagick.org/">Image Magick</a>. Using the &#8216;chop&#8217; or &#8216;crop&#8217; commands didn&#8217;t work for this purpose, where I wanted the image to keep it&#8217;s dimensions but have one half just be white. So I decided to draw a white rectangle over half of the picture.  I apply the image manipulation to the original JPEG file, not the temporary PPM file that I used to detect the face position.</p>
<span class="monospace">convert -fill white \<br />
-draw &#8220;rectangle $FACE_CENTER,0 $WIDTH,$HEIGHT&#8221; \<br />
&#8220;andy.jpg&#8221; &#8220;andy_half.jpg&#8221;</span>
<p>And here&#8217;s the final result:<a href="http://ultrahigh.org/wp-content/uploads/2008/10/andy_half.jpg"><img class="aligncenter size-full wp-image-53" title="andy_half" src="http://ultrahigh.org/wp-content/uploads/2008/10/andy_half.jpg" alt="" width="500" height="375" /></a></p>
<p><a href="http://code.ultrahigh.org/crop_center_face.sh">The script I am using</a> to tie this all together.</p>
<p>After processing all the portraits, I run a quick script to convert the jpegs to PDF and then join them into one master PDF file that I can easily print. The JPEG-PDF conversion uses Image Magick again (<span class="monospace">convert -rotate 90 file.jpg file.pdf</span>). Joining together many PDFs into one document is easy with &#8216;pdfjoin&#8217; from package &#8216;pdfjam&#8217; (<span class="monospace">pdfjoin $tempfiles &#8211;outfile jpg2pdf.pdf</span>). <a href="http://code.ultrahigh.org/jpg2pdf.sh">See the final jpg2pdf script.</a></p>
<p>But perhaps more enjoyable is to see the result after letting my limited creative talents loose:</p>
<div id="attachment_57" class="wp-caption aligncenter" style="width: 510px"><a href="http://ultrahigh.org/wp-content/uploads/2008/10/andy_finished_500.jpg"><img class="size-full wp-image-57" title="andy_finished_500" src="http://ultrahigh.org/wp-content/uploads/2008/10/andy_finished_500.jpg" alt="A work of staggering complexity." width="500" height="375" /></a><p class="wp-caption-text">A work of staggering complexity.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://ultrahigh.org/2008/10/14/command-line-face-detection/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Undistract v0.2</title>
		<link>http://ultrahigh.org/2007/12/17/undistract-v02/</link>
		<comments>http://ultrahigh.org/2007/12/17/undistract-v02/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 01:25:44 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://ultrahigh.org/2007/12/17/undistract-v02/</guid>
		<description><![CDATA[I have posted a version 0.2 of my attention monitoring software &#8220;Undistract&#8221;. This release features the following changes:

Uses libnotify instead of xosd, which looks a lot better in GNOME
at least and should work fine cross-desktop.
The most drastic action is now to minimize the distracting window
rather than change virtual desktops, which was quite specific to my
desktop [...]]]></description>
			<content:encoded><![CDATA[<p>I have posted a version 0.2 of my <a href="http://ultrahigh.org/undistract" target="_parent">attention monitoring software &#8220;Undistract&#8221;.</a> This release features the following changes:</p>
<p><UL><br />
<LI>Uses libnotify instead of xosd, which looks a lot better in GNOME<br />
at least and should work fine cross-desktop.</LI><br />
<LI>The most drastic action is now to minimize the distracting window<br />
rather than change virtual desktops, which was quite specific to my<br />
desktop usage. I have tried to manage the focus with this change too,<br />
so that the user doesn&#8217;t inadvertently send key presses to a different<br />
window.</LI><br />
<LI>Uses GTK event loop which makes monitoring a lot more efficient.</LI><br />
<LI>More sophisticated usage of libwnck to determine which windows are<br />
active at whether they belong to a distracting application.</LI><br />
<LI>Simplified some of the code and tried to de-jargonize the config file.</LI><br />
</UL></p>
<p>You can download it at <a href="http://code.ultrahigh.org/undistract">http://code.ultrahigh.org/undistract</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ultrahigh.org/2007/12/17/undistract-v02/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Define Template Functions In .cpp Files</title>
		<link>http://ultrahigh.org/2007/05/17/dont-define-template-functions-in-cpp-files/</link>
		<comments>http://ultrahigh.org/2007/05/17/dont-define-template-functions-in-cpp-files/#comments</comments>
		<pubDate>Thu, 17 May 2007 16:50:25 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://ultrahigh.org/2007/05/17/dont-define-template-functions-in-cpp-files/</guid>
		<description><![CDATA[This is another gotcha from my recent C++ work. When I learned C++ I was taught to put the interface (function declarations) in a header file and the implentation (function definitions) in a .cpp module source file. Some small functions could be written inline in the class declarations, usually just get/set member functions for private [...]]]></description>
			<content:encoded><![CDATA[<p>This is another gotcha from my recent C++ work. When I learned C++ I was taught to put the interface (function declarations) in a header file and the implentation (function definitions) in a .cpp module source file. Some small functions could be written inline in the class declarations, usually just get/set member functions for private data. At one point (or possibly just in C) having if/else statements in a header was not allowed, the compiler complained about branching. I recently realized (about 10 years after everyone else, it seems) that there is actually a very good reason to put implementation of templated functions in the header file.<br />
<span id="more-9"></span></p>
<p>Recently I was working on my interpolation classes, which are templates, like</p>
<pre>
template <class T>
class Interpolation1D : public Interpolation
{
public:
    ...
    T GetValue(const T&#038; x)
    {
        // vectors hold interpolation points and values near 'x'
        vector<T> xa(_order), ya(_order);
        ...    // set up the points to interpolate
        return Neville<T> (_order, xa, ya, x);
    }
protected:
    ...
};
</pre>
<p>The function GetValue(x) retrieved the interpolated value of the function position x. The Interpolation2D class has a similar GetValue(x,y) member. Both of these GetValue functions use <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">Neville&#8217;s algorithm</a> to determine the value at the interpolation point, which is a pretty fast polynomial approximation technique. In fact, they basically do exactly the same thing, except the 2-D version builds an intermediate 1-D set of values (using Neville&#8217;s algorithm) and then interpolates that in the same manner as the 1-D version. </p>
<p>Naturally I wrote a function to perform the Neville interpolation, and that too had to be templated, in order to be used inside the templated interpolation classes.</p>
<pre>
template <class T>
T Neville(const size_t&#038; order, const vector<T>&#038; xa,
         const vector<T>&#038; ya, const T&#038; x)
{ ... }
</pre>
<p>I put the declaration for the Neville function in the header file interpolation.h, and the implentation in interpolation.cpp. Everything compiled just fine (I compiled this into a library) but when I came to link the main program, which used a Interpolation1D<double> instance, the compiler started complaining that it couldn&#8217;t find the double version of Neville:</p>
<pre>double Neville(const size_t&#038;, const vector<double>&#038;,
       const vector<double>&#038;, const double)</pre>
<p>I spent a good while double checking the function declaration was the same as the definition (since the main program <em>did compile</em>, only the linking failed. Using <code>nm</code> to examine the object code in interpolation.o showed that in fact NO version of Neville() was present.</p>
<p>Anyway, to cut a long story short, the answer is one of those C++ things that is obvious after you figure it out: The compiler, when it compiles interpolation.cpp into interpolation.o, only builds creates implentations of templated functions that it sees are being used, in this case, none, since no code within interpolation.cpp calls Neville<double> (or Neville<anything>).</p>
<p>The solution was to move the definition of Neville<T> into interpolation.h, which is <code>#include</code>d in the interpolation1d.h file. When the compiler builds an object file relying on the Interpolation1D class (ie code which <code>#include</code>s interpolation1d.h and hence interpolation.h) it sees that it needs to create the object code for Neville<double> and does so.</p>
]]></content:encoded>
			<wfw:commentRss>http://ultrahigh.org/2007/05/17/dont-define-template-functions-in-cpp-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mixing Inheritance and Templates in C++</title>
		<link>http://ultrahigh.org/2007/05/05/mixing-inheritance-and-templates/</link>
		<comments>http://ultrahigh.org/2007/05/05/mixing-inheritance-and-templates/#comments</comments>
		<pubDate>Sat, 05 May 2007 16:36:01 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://ultrahigh.org/2007/05/05/mixing-inheritance-and-templates/</guid>
		<description><![CDATA[I came across a gotcha today with some C++ code I&#8217;m working on. I have an abstract base class for doing  interpolation, and when I tried converting it to a template class it stopped working &#8211; specifically the derived class could no longer access certain members of the base class.

Here&#8217;s my abstract base class [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a gotcha today with some C++ code I&#8217;m working on. I have an abstract base class for doing  interpolation, and when I tried converting it to a template class it stopped working &#8211; specifically the derived class could no longer access certain members of the base class.<br />
<span id="more-8"></span><br />
Here&#8217;s my abstract base class (simplified for this example):</p>
<pre>
class Interpolation
{
public:
	Interpolation(const string&#038; name, const double&#038; accuracy)
	{
		_name = name;
		_accuracy = accuracy;
		_isBuilt = false;
	}
	virtual void Init(void) = 0;
	virtual void LoadFromFile(const string&#038; filename) = 0;
	virtual void SaveToFile(const string&#038; filename) = 0;
protected:
	string _name;
	double _accuracy;
	bool _isBuilt;
};
</pre>
<p>I then have a layer of inheritance on top of that, defining the interface for interpolation in two variables</p>
<pre>
class Interpolation2D : public Interpolation
{
public:
	Interpolation2D(const string&#038; name, const double&#038; accuracy,
		const long&#038; Nx, const long&#038; Ny,
		const double&#038; xmin, const double&#038; xmax,
		const double&#038; ymin, const double&#038; ymax)
		: Interpolation (name, accuracy)
	{

		_grid = new Data2D&lt;double&gt;(Nx, Ny);
		...
	}
	~Interpolation(void)
	{
		cout &lt;&lt; "deleting data grid for " &lt;&lt; _name &lt;&lt; "\n";
		delete _grid;
	}
	// these are implemented here for two-D interpolations
	virtual void SaveToFile(const string&#038; filename);
	virtual void LoadFromFile(const string&#038; filename);
protected:
	Data2D&lt;double&gt;* _grid;
};
</pre>
<p>This code was working fine. I have the templated 2D data array class Data2D and chose to use doubles for my interpolation data. The inherited _name and _isBuilt variables work fine, as in the debug output line in the destructor.NB: I do implement the SaveToFile and LoadFromFile functions here, which basically just dump the _grid variable to a binary file.</p>
<p>Then I discovered the rather obvious fact that if I want to make a very fine-grained interpolation, that can take a lot of memory. For example, a 5000&#215;5000 grid of doubles is 5000&#215;5000x8 bytes, i.e. 190MB. Too rich for my laptop at least, although not absurd for most of the machines I use for simulation.</p>
<p>One obvious choice would be to use float instead of double as the data type. Of course, this leads to wanting to template the Interpolation class, which I duly did:</p>
<pre>
template &lt;class T&gt;
class Interpolation
{
public:
	Interpolation(const string&#038; name, const T&#038; accuracy)
	{
		_name = name;
		_isBuilt = false;
		_accuracy = accuracy
	}
	virtual void Init(void) = 0;
	virtual void LoadFromFile(const string&#038; filename) = 0;
	virtual void SaveToFile(const string&#038; filename) = 0;
protected:
	string _name;
	bool _isBuilt;
	T _accuracy;
};

template &lt;class T&gt;
class Interpolation2D : public Interpolation&lt;T&gt;
{
public:
	Interpolation2D(const string&#038; name, const T&#038; accuracy,
		const long&#038; Nx, const long&#038; Ny,
		const T&#038; xmin, const T&#038; xmax,
		const T&#038; ymin, const T&#038; ymax)
		: Interpolation&lt;T&gt; (name)
	{

		_grid = new Data2D&lt;T&gt;(Nx, Ny);
		...
	}
	~Interpolation(void)
	{
		cout &lt;&lt; "deleting data grid for " &lt;&lt; _name &lt;&lt; "\n";
		delete _grid;
	}
	virtual void SaveToFile(const string&#038; filename);
	virtual void LoadFromFile(const string&#038; filename);
protected:
	Data2D&lt;T&gt;* _grid;
};
</pre>
<p>So, imagine my surprise and confusion when this code no longer works. Specifically, gcc complains about the debugging output in the derived class&#8217; destructor.</p>
<pre>
./include/aon_interpolation.h:179: error: "_name" was not declared in this scope
</pre>
<p>The problem, according to <a href="http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18">the C++ FAQ</a>, is that the variable _name is not dependent on the template, and the compile will not look in the base template class to resolve non-dependent names.</p>
<p>Luckily there&#8217;s a really easy fix: change the call to use
<pre>this-&gt;_name</pre>
<p> instead: i.e.</p>
<pre>cout &lt;&lt; data grid for " &lt;&lt; this-&gt;_name &lt;&lt; "\n";</pre>
<p>C++ Is just one of those things that constantly surprises me with weird little things like this, even after 7 years of using it. But it&#8217;s still so powerful it&#8217;s mostly a pleasure to use.</p>
]]></content:encoded>
			<wfw:commentRss>http://ultrahigh.org/2007/05/05/mixing-inheritance-and-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Undistract: An Attention Watchdog</title>
		<link>http://ultrahigh.org/2007/03/09/undistract-an-attention-watchdog/</link>
		<comments>http://ultrahigh.org/2007/03/09/undistract-an-attention-watchdog/#comments</comments>
		<pubDate>Sat, 10 Mar 2007 00:23:04 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://ultrahigh.org/2007/03/09/undistract-an-attention-watchdog/</guid>
		<description><![CDATA[I&#8217;m posting my distraction defeating program undistract today and wanted to explain how it came about and why I find it useful.

I have problems with attention. I&#8217;ve not been diagnosed with A.D.D. or anything but anyone who spent fifteen minutes in my office would realize that I am either utterly distracted or hyper-focused. These are [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m posting my distraction defeating program <a href="/undistract/">undistract</a> today and wanted to explain how it came about and why I find it useful.</p>
<p><span id="more-5"></span></p>
<p>I have problems with attention. I&#8217;ve not been diagnosed with A.D.D. or anything but anyone who spent fifteen minutes in my office would realize that I am either utterly distracted or hyper-focused. These are pretty common traits amongst scientists and programmers &#8211; indeed, the tendency to hyper-focus is probably the same thing that programmers call &#8220;being in the zone&#8221;.</p>
<p>I have designed it to solve a particular problem &#8211; I tend to focus on my work once I get started, but I also focus equally well on non-work activities, in particular web browsing. It&#8217;s easy for me to let an hour (or eight!!) pass whilst, say, checking Slashdot repeatedly, without realizing that so much time has gone by. I designed undistract to gently pull me out of this focus-on-distraction to give me a chance to focus on my work.</p>
<p>The program works by monitoring what windows are open on my desktop. I use GNOME on Ubuntu Linux (I also test the program in KDE and XFCE) with multiple workspaces (also called virtual desktops). I tend to have them arranged like</p>
<ul>
<li>Workspace 1: Browser, Email, IM windows, music player</li>
<li>Workspace 2: Couple of xterms on local machine</li>
<li>Workspace 3: SSH &amp; VNC sessions to machines on the cluster at work</li>
<li>Workspace 4: gvim editing analysis code or LaTeX files.</li>
</ul>
<p>Clearly, if I am doing useful work, I ought to be spending most (but not all) of my time on Workspaces 3 &amp; 4. Workspace 2 tends to involve distractions but not entirely useless ones, as I do things like update the operating system, tweak configuration, backup my data etc. If, however, I am spending a lot of time on Workspace 1, it is safe to assume that I have become absorbed in some distraction, whether it be Slashdot, MySpace, eBay&#8230; whatever it is, I have a thesis to write so it&#8217;s probably not helpful.</p>
<p>I do want to allow for those times when I&#8217;m in the flow, working on something, and I have to look up some documentation online. What I&#8217;m really trying to catch with Undistract are those times when you sit down to work, but just want to check your email, only to find someone emailed you a funny link, which led you to your browser, which led you to hover next to that open tab to Google News&#8230; if you have found this page, you know the story!</p>
<p>Undistract maintains a &#8216;nag level&#8217; which is raised or lowered at intervals depending on whether the user has a browser open on the current workspace or not. The intervals for checking are not uniform, and when the nag level is low the checking occurs slowly, like every 10 minutes. If the user is still using a browser after that interval, then a message appears in front of all the open windows (using xosd) telling them to get to work, and the nag level is raised.</p>
<p>As the nag level increases, the interval between nags becomes shorter, up to a limit, by default 60 seconds. After the nag level passes a certain value, 6 by default, then the user is reminded to work by the xosd message but current workspace is changed. The user is free to change back to the browser and finish what they are doing, but after 60 seconds they will be bounced to a different desktop again.</p>
<p>If you think this could be helpful in helping with your own distractions, <a href="/undistract/">try undistract</a> for a bit.</p>
]]></content:encoded>
			<wfw:commentRss>http://ultrahigh.org/2007/03/09/undistract-an-attention-watchdog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
