<?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>Note to Self</title>
	<atom:link href="http://notetoself.vrensk.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://notetoself.vrensk.com</link>
	<description>lest I forget</description>
	<lastBuildDate>Tue, 26 Jan 2010 16:38:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SQLite is dynamically typed</title>
		<link>http://notetoself.vrensk.com/2009/08/sqlite-is-dynamically-typed/</link>
		<comments>http://notetoself.vrensk.com/2009/08/sqlite-is-dynamically-typed/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 12:54:08 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=59</guid>
		<description><![CDATA[SQLite3 is truly dynamically typed.  To a fault:
sqlite&#62; select count(*) from posts where external_id = 199252;
0
sqlite&#62; select count(*) from posts where external_id = '199252';
1
sqlite&#62; select count(*) from posts where external_id = 199793;
1
sqlite&#62; select count(*) from posts where external_id = '199793';
0

One day I suppose I will find it useful to store different data types in [...]]]></description>
			<content:encoded><![CDATA[<p>SQLite3 is truly dynamically typed.  To a fault:</p>
<pre><code>sqlite&gt; select count(*) from posts where external_id = 199252;
0
sqlite&gt; select count(*) from posts where external_id = '199252';
1
sqlite&gt; select count(*) from posts where external_id = 199793;
1
sqlite&gt; select count(*) from posts where external_id = '199793';
0
</code></pre>
<p>One day I suppose I will find it useful to store different data types in the same column, and without implicit conversion.  I look forward to that day.  Right now, I will have to spend a few hours cleaning up the mess that this caused.</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2009/08/sqlite-is-dynamically-typed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gueuze Fond Tradition</title>
		<link>http://notetoself.vrensk.com/2009/08/gueuze-fond-tradition/</link>
		<comments>http://notetoself.vrensk.com/2009/08/gueuze-fond-tradition/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 15:34:39 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Life outside work]]></category>
		<category><![CDATA[beer]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=56</guid>
		<description><![CDATA[After last week&#8217;s got.rb meeting we went out to grab a beer and continue our geeky discussions.  I just want to make a note to myself that the wonderful beer I had (after CJ refused it) was a Gueuze Fond Tradition from Belgium.  It&#8217;s not available at Systembolaget, much like this summer&#8217;s first favourite, Gjutarns [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://beeradvocate.com/beer/profile/212/5212" onclick="pageTracker._trackPageview('/outgoing/beeradvocate.com/beer/profile/212/5212?referer=');"><img class="alignleft size-full wp-image-57" title="picture-3" src="http://notetoself.vrensk.com/wp-content/uploads/2009/08/picture-3.png" alt="" width="95" height="277" /></a>After last week&#8217;s <a href="http://gotrb.org/calendar/10914739/" onclick="pageTracker._trackPageview('/outgoing/gotrb.org/calendar/10914739/?referer=');">got.rb meeting</a> we went out to <a href="http://www.restaurangguiden.com/gbg/centrum/delirium/omossRG.aspx" onclick="pageTracker._trackPageview('/outgoing/www.restaurangguiden.com/gbg/centrum/delirium/omossRG.aspx?referer=');">grab a beer</a> and continue our geeky discussions.  I just want to make a note to myself that the wonderful beer I had (after CJ refused it) was a <a href="http://beeradvocate.com/beer/profile/212/5212" onclick="pageTracker._trackPageview('/outgoing/beeradvocate.com/beer/profile/212/5212?referer=');">Gueuze Fond Tradition</a> from Belgium.  It&#8217;s not available at Systembolaget, much like this summer&#8217;s first favourite, <a href="http://skebobruksbryggeri.blogspot.com/search?updated-min=1971-03-14T00%3A00%3A00%2B01%3A00&amp;updated-max=1971-03-18T00%3A00%3A00%2B01%3A00&amp;max-results=1" onclick="pageTracker._trackPageview('/outgoing/skebobruksbryggeri.blogspot.com/search?updated-min=1971-03-14T00_3A00_3A00_2B01_3A00_amp_updated-max=1971-03-18T00_3A00_3A00_2B01_3A00_amp_max-results=1&amp;referer=');">Gjutarns Bästa Bitter</a> (et al.) from Skebo Bruksbryggeri.  Note within note: according to the <a href="http://skebobruksbryggeri.blogspot.com/1971_06_01_archive.html" onclick="pageTracker._trackPageview('/outgoing/skebobruksbryggeri.blogspot.com/1971_06_01_archive.html?referer=');">homepage</a>, Skebo&#8217;s beers should be available at Delirium and <a href="http://www.bishopsarms.com/" onclick="pageTracker._trackPageview('/outgoing/www.bishopsarms.com/?referer=');">three</a> <a href="http://www.hitta.se/ViewDetailsPink.aspx?vkiid=zVaMLGX1RdJeoW63V%20r9gw==&amp;vad=Plain+Kitchen+and+Sports+Bar" onclick="pageTracker._trackPageview('/outgoing/www.hitta.se/ViewDetailsPink.aspx?vkiid=zVaMLGX1RdJeoW63V_20r9gw==_amp_vad=Plain+Kitchen+and+Sports+Bar&amp;referer=');">more</a> <a href="http://www.therover.se/" onclick="pageTracker._trackPageview('/outgoing/www.therover.se/?referer=');">venues</a> in Gothenburg!</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2009/08/gueuze-fond-tradition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping Fedora 6 going after end-of-life</title>
		<link>http://notetoself.vrensk.com/2009/06/keeping-fedora-6-going-after-end-of-life/</link>
		<comments>http://notetoself.vrensk.com/2009/06/keeping-fedora-6-going-after-end-of-life/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 16:38:21 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Server Configuration]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=53</guid>
		<description><![CDATA[All hackers want to live on the edge.  What we rarely reflect on is the fact that most things have more than one edge.  Adaptation curves have two: one where the early adopters build up their reputation for cool and one where I found myself this afternoon.
Apparently I should have let go of [...]]]></description>
			<content:encoded><![CDATA[<p>All hackers want to live on the edge.  What we rarely reflect on is the fact that most things have more than one edge.  Adaptation curves have two: one where the early adopters build up their reputation for cool and one where I found myself this afternoon.</p>
<p>Apparently I should have let go of Fedora 6 some time ago.  I installed this particular server in December 2006 when FC6 was the cool new girl on the block, and it has been running smoothly since then.  But today when I tried to (<code>yum</code>) install a package, there were no servers to be found:</p>
<pre><code># yum search libxslt-devel
Loading "installonlyn" plugin
Setting up repositories
http://archive.kernel.org/fedora-archive/fedora/linux/core/6/i386/os/repodata/repomd.xml:
  [Errno 14] HTTP Error 404: Server: nginx/0.5.0
...
Trying other mirror.
core                      100% |=========================| 1.1 kB    00:00
Error: Cannot find a valid baseurl for repo: extras
</code></pre>
<p>Oops.  I looked in <code>/etc/yum.repos.d/fedora-extras.repo</code> which is provides the base URL:</p>
<pre><code>[extras]
name=Fedora Extras $releasever - $basearch
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/extras/$releasever/$basearch/
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=extras-$releasever&amp;arch=$basearch
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-extras
gpgcheck=1
</code></pre>
<p>In earlier experience, the problem has been that the DNS service for the repo that <code>mirrorlist</code> recommends is down, and this is what some googling suggested too.  So I went to <a href="http://mirrors.fedoraproject.org/mirrorlist?repo=extras-6&amp;arch=i386" onclick="pageTracker._trackPageview('/outgoing/mirrors.fedoraproject.org/mirrorlist?repo=extras-6_amp_arch=i386&amp;referer=');">mirrors.fedoraproject.org</a> to see what it said.  The answer surprised me:</p>
<pre><code># repo = extras-6 arch = i386 error: invalid repo or arch
# following repositories are available:
# repo=core-2, arch=i386
# repo=core-2, arch=x86_64
# ...
# repo=core-6, arch=x86_64
# ...
</code></pre>
<p>So <code>core-6</code> is in the list but <code>extras-6</code> is not.  I tried some different combinations thinking I had got it wrong, but to no avail.  Instead, on a whim, I checked out the <a href="http://mirrors.fedoraproject.org/" onclick="pageTracker._trackPageview('/outgoing/mirrors.fedoraproject.org/?referer=');">site’s root</a> where I could navigate to a human-readable <a href="http://mirrors.fedoraproject.org/publiclist/Fedora/6/i386/" onclick="pageTracker._trackPageview('/outgoing/mirrors.fedoraproject.org/publiclist/Fedora/6/i386/?referer=');">list of mirrors</a> and I started checking them out one by one.  Uni-Bayreuth seemed to have what I wanted, so I edited <code>fedora-extras.repo</code> like this:</p>
<pre><code>[extras]
name=Fedora Extras $releasever - $basearch
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/extras/$releasever/$basearch/
#mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=extras-$releasever&amp;arch=$basearch
baseurl=http://ftp.uni-bayreuth.de/linux/fedora/linux/extras/$releasever/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-extras
gpgcheck=1
</code></pre>
<p>and ran <code>yum search libxslt-devel</code> again.  This time it complained about <code>updates</code> instead (<code>Error: Cannot find a valid baseurl for repo: updates</code>).  Unfortunately Bayreuth didn’t have the updates catalog which sent me searching in a few other places until I finally decided to try to make do without it by setting <code>enabled=0</code> in <code>fedora-updates.repo</code>:</p>
<pre><code>[updates]
name=Fedora Core $releasever - $basearch - Updates
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/core/updates/$releasever/$basearch/
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-fc$releasever&amp;arch=$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
</code></pre>
<p>It worked, and I was able to install the packages I wanted, but I really need to get myself a newer OS.  I’ll combine that with a move to another host; FS-data have let me down once too many, and I’ve never fancied upgrading the OS on a production server anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2009/06/keeping-fedora-6-going-after-end-of-life/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Git bisect saves the day!</title>
		<link>http://notetoself.vrensk.com/2009/04/git-bisect-saves-the-day/</link>
		<comments>http://notetoself.vrensk.com/2009/04/git-bisect-saves-the-day/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 21:01:59 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[git bisect]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=51</guid>
		<description><![CDATA[Git bisect is the hero of the week!  It turned out that some time between now and three weeks ago, the login functionality broke in the Rails app we’re developing.  It didn’t break completely, of course, just in certain environments.  And looking at the logs, I had no idea what the error [...]]]></description>
			<content:encoded><![CDATA[<p>Git bisect is the hero of the week!  It turned out that some time between now and three weeks ago, the login functionality broke in the Rails app we’re developing.  It didn’t break completely, of course, just in certain environments.  And looking at the logs, I had no idea what the error could be, so I just had to work it out from the diff between the last working commit and next.  Well, between three developers, there can be quite a few commits during three weeks and with a lesser version control system I would have had to</p>
<ol>
<li>checkout the previous revision,</li>
<li>restart the server (because plugins, gems and even Rails can change between versions),</li>
<li>try to log in,</li>
<li>see if works and stop if it does,</li>
<li>repeat from 1.</li>
</ol>
<p>With git, I can ask git itself to perform a binary search among all the revisions between now and three weeks ago.  It would go like this:</p>
<ol>
<li><code>git bisect start HEAD 57c3aaa</code>,</li>
<li>restart the server,</li>
<li>try to log in,</li>
<li>see it fail or succeed,</li>
<li>say <code>git bisect bad</code> or <code>git bisect good</code> to make Git checkout the next node in the binary search tree</li>
<li>repeat from 1 until Git says that it found the culprit.</li>
</ol>
<p>It doesn’t look a lot better, but it is if you have 300 commits.  Of course there is nothing to stop you from doing a manual binary search with Subversion, or even to step back one day at a time to narrow it down, and we didn’t actually have 300 commits.  But where Git really shines is in the fact that if I can write a program that can tell if a version is good or bad, all I have to do is</p>
<ol>
<li><code>git bisect start HEAD 57c3aaa</code>,</li>
<li><code>git run ../my-test-probe.rb</code></li>
</ol>
<p>and sit back and wait.  Provided of course that the program also knew how to start and stop the server.  Well, here is that program, for your debugging pleasure, and mine:</p>
<p><script src="http://pastie.org/437749.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2009/04/git-bisect-saves-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pretty-printing PeepCode PDFs</title>
		<link>http://notetoself.vrensk.com/2009/04/pretty-printing-peepcode-pdfs/</link>
		<comments>http://notetoself.vrensk.com/2009/04/pretty-printing-peepcode-pdfs/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 16:23:26 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[The daily grind]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[peepcode]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=47</guid>
		<description><![CDATA[PeepCode publishes wonderful screencasts and pdf books on subjects that should be of interest to any Rails developer.  The pdfs seem to be adapted for screen reading – they are in landscape mode, not in standard paper sizes (as far as I can tell) and they have big print.  So far so good, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://peepcode.com/" onclick="pageTracker._trackPageview('/outgoing/peepcode.com/?referer=');">PeepCode</a> publishes wonderful screencasts and pdf books on subjects that should be of interest to any Rails developer.  The pdfs seem to be adapted for screen reading – they are in landscape mode, not in standard paper sizes (as far as I can tell) and they have big print.  So far so good, but I spend enough time in front of computer screens and like reading paper.  I have tried various pdf rendering options combined with cropping, but the solution that worked best for printing <a href="http://jointheconversation.org/" onclick="pageTracker._trackPageview('/outgoing/jointheconversation.org/?referer=');">Scott Chacon</a>’s <a href="http://peepcode.com/products/git-internals-pdf" onclick="pageTracker._trackPageview('/outgoing/peepcode.com/products/git-internals-pdf?referer=');">Git Internals PDF</a> on A4 paper was as simple as printing it 2up at 118%.</p>
<p><a href="http://notetoself.vrensk.com/wp-content/uploads/2009/04/picture-8.png"><img class="alignnone size-full wp-image-48" title="print settings" src="http://notetoself.vrensk.com/wp-content/uploads/2009/04/picture-8.png" alt="" width="500" height="391" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2009/04/pretty-printing-peepcode-pdfs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Really killing rails processes at FS-data</title>
		<link>http://notetoself.vrensk.com/2009/04/really-killing-rails-processes-at-fs-data/</link>
		<comments>http://notetoself.vrensk.com/2009/04/really-killing-rails-processes-at-fs-data/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 11:51:38 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=44</guid>
		<description><![CDATA[FS-data was the first web hotel in Sweden to support Ruby on Rails (in August 2006, I think) and I’m glad they did.  Unfortunately they haven’t touched their setup since, so patrons are still limited to (a) apps in subdirectories only and (b) FastCGI (FCGI).  I have seen many complaints about FCGI, but [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.fsdata.se/" onclick="pageTracker._trackPageview('/outgoing/www.fsdata.se/?referer=');">FS-data</a> was the first web hotel in Sweden to support Ruby on Rails (in August 2006, I think) and I’m glad they did.  Unfortunately they haven’t touched their setup since, so patrons are still limited to (a) apps in subdirectories only and (b) FastCGI (FCGI).  I have seen many complaints about FCGI, but I have only one: it’s really hard to know if it’s running my latest release.  FS-data have added a control panel of sorts, but it’s pretty unreliable.  Thus, I have to resort to <code>kill</code>ing.  But what to <code>kill</code>?</p>
<pre><code>$ ps -fe | grep rails
UID        PID  PPID  C STIME TTY          TIME CMD
wcj      27292  3558 27 13:41 ?        00:00:02 RAILS: /home/w/wcj/rails/sis/public/dispatch.fcgi
wcj      27365  3558 40 13:41 ?        00:00:02 RAILS: /home/w/wcj/rails/sis/public/dispatch.fcgi
...
</code></pre>
<p>With more than two processes I refuse to <code>kill</code> by PID – FCGI is just too quick to spawn new processes, and I’m not sure if they will run the right version of my app either.  So it’s <code>killall</code>.  But what to <code>killall</code>?</p>
<pre><code>$ killall -9 'RAILS: /home/w/wcj/rails/sis/public/dispatch.fcgi'
</code></pre>
<p>does not work.  So it’s <code>ps</code> to the rescue:</p>
<pre><code>$ ps -eo pid,comm:30
  PID COMMAND
27365 rails_dispatche
27292 rails_dispatche
</code></pre>
<p><code>rails_dispatche</code>, really?  No final ‘r’?  Whatever:</p>
<pre><code>killall -9 rails_dispatche
</code></pre>
<p>It works and I’m happy again.</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2009/04/really-killing-rails-processes-at-fs-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Same, same &#8211; but different</title>
		<link>http://notetoself.vrensk.com/2008/11/same-same-but-different/</link>
		<comments>http://notetoself.vrensk.com/2008/11/same-same-but-different/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 23:17:00 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[language]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=36</guid>
		<description><![CDATA[I read in New York Magazine this weekend that Malcolm Gladwell (author of The Tipping Point, Blink and Outliers) has a &#8220;regular biweekly &#8216;boys’ night out&#8217;&#8221; and that made me wonder if he went out with his friends every other Friday or perhaps every Tuesday and Saturday.  &#8221;Biweekly&#8221; is a word that makes me uncomfortable [...]]]></description>
			<content:encoded><![CDATA[<p>I read in <a href="http://nymag.com/" onclick="pageTracker._trackPageview('/outgoing/nymag.com/?referer=');">New York Magazine</a> this weekend that Malcolm Gladwell (author of <a href="http://www.adlibris.com/se/product.aspx?isbn=0349114463" onclick="pageTracker._trackPageview('/outgoing/www.adlibris.com/se/product.aspx?isbn=0349114463&amp;referer=');">The Tipping Point</a>, <a href="http://www.adlibris.com/se/product.aspx?isbn=0141022043" onclick="pageTracker._trackPageview('/outgoing/www.adlibris.com/se/product.aspx?isbn=0141022043&amp;referer=');">Blink</a> and <a href="http://www.adlibris.com/se/product.aspx?isbn=0141036249" onclick="pageTracker._trackPageview('/outgoing/www.adlibris.com/se/product.aspx?isbn=0141036249&amp;referer=');">Outliers</a>) has a <a href="http://nymag.com/arts/books/features/52014/index1.html#story" onclick="pageTracker._trackPageview('/outgoing/nymag.com/arts/books/features/52014/index1.html_story?referer=');">&#8220;regular biweekly &#8216;boys’ night out&#8217;&#8221;</a> and that made me wonder if he went out with his friends every other Friday or perhaps every Tuesday and Saturday.  &#8221;Biweekly&#8221; is a word that makes me uncomfortable since I hear it quite seldom, and it doesn&#8217;t seem to mean the same thing every time.  I&#8217;ve always thought that was because my otherwise near-perfect memory had a blind spot at that exact dictionary entry, so to speak.  Nevermind, I thought, if he invites me to join them I suppose he will be more specific, and if he doesn&#8217;t (quite likely) it doesn&#8217;t really matter, does it?</p>
<p>And then I read <a href="http://www.gocomics.com/bloomcounty/2008/11/19/" onclick="pageTracker._trackPageview('/outgoing/www.gocomics.com/bloomcounty/2008/11/19/?referer=');">today&#8217;s Bloom County strip</a> (re-runs from the &#8217;80s) where Opus arrives at the barber&#8217;s for his &#8220;biannual haircut&#8221; and I decided to take action.  I can deal with not knowing Malcolm Gladwell&#8217;s party schedule, but I really want to know if my favourite penguin gets a trim twice a year or every two years.  (I have tried both intervals, and each has its charm.)</p>
<p>I started with &#8220;biweekly&#8221; and here&#8217;s what the dictionary says:</p>
<p style="padding-left: 30px;"><span class="hwGrp"><span class="hw">biweekly</span><span class="pronGrp"><span class="pr"> |bʌɪˈwiːkli|<br />
</span></span></span><span class="SB"><span class="prelim"><span class="ps">adjective </span>&amp; <span class="ps">adverb<br />
</span></span><span class="sense"><span class="def">appearing or taking place every two weeks or twice a week </span><span class="exGrp"><span class="lbl">: </span><span class="gramGrp">[as <span class="syntax">adj. </span>] </span><span class="ex"><em>a biweekly bulletin</em> </span></span><span class="exGrp"><span class="lbl">| </span><span class="gramGrp">[as <span class="syntax">adv. </span>] </span><span class="ex"><em>she followed her doctor&#8217;s instructions to undergo health checks </em><em>biweekly</em><em>.</em></span></span></span></span></p>
<p>Wow.  I never finished my course in Language Philosophy in 1992, but I remember the Morning Star Paradox quite well.  It goes something like this:</p>
<ul>
<li>Mary belives that the Morning Star is Lucifer, and she believes that the Evening Star is the goddess Venus.  Her friend Tycho is aware of her beliefs, but&#8230;</li>
<li>Tycho knows that the Morning Star and the Evening Star refer to the same physical object, so&#8230;</li>
<li>Tycho thinks that Mary believes that Lucifer and Venus are one and the same.</li>
</ul>
<p>I remember that this was a useful tool for understanding the difference between a reference and a referent or somesuch, but most of all I thought it was beautiful.  Mary has romantic beliefs about the existance of deities and their position in the sky, and while scientists normally shrug at romantic beliefs, they (we) all have to stick our noses into this one.  Dear Mary, you can believe that the Morning Star is Lucifer, and you can believe that the Evening Star is Venus, but you can&#8217;t believe both.  If you can&#8217;t see the beauty in this I probably can&#8217;t help you.</p>
<p>Anyway, here are today&#8217;s more or less contradictory words:</p>
<p><strong>biweekly:</strong> (adj,adv) every two weeks or twice a week; (noun) a periodical that appears every two weeks or twice a week</p>
<p><strong>bimonthly:</strong> (adj,adv) occurring or produced twice a month or every two months; (noun) a periodical produced twice a month or every two months.  (With the added note that &#8220;[i]n the publishing world, the meaning of bimonthly is more fixed and is invariably used to mean ‘every two months.’&#8221;)</p>
<p><strong>biennal:</strong> (adj) taking place every other year, (noun) 1 a plant that takes two years to grow from seed to fruition and die. 2 an event celebrated or taking place every two years.</p>
<p><strong>biannual:</strong> (adj) occurring twice a year</p>
<p>There are a few other things that come to mind when I see these words together.  One is that &#8216;biannual&#8217; is never a noun.  Another is that the lexicographers chose to say &#8220;every two weeks or twice a week&#8221; but &#8220;twice a month or every two months&#8221;.  Order is not always significant in a dictionary, but it&#8217;s hard to fathom that not at least one of the two entries has a bias for &#8216;twice&#8217; or &#8216;every two&#8217;.  But it&#8217;s of course impossible to know which one it is.</p>
<p>And thirdly, the note for &#8216;bimonthly&#8217; as a noun makes me wonder if the notes are written by a different group of people from the ones who write the actual definitions, or if &#8216;publishing world&#8217; is the key word here.  You and I might call a periodical that appears every two weeks bimonthly since it appears twice a month, but in the publishing world, it will be a biweekly instead.</p>
<p>Wow.</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2008/11/same-same-but-different/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>It&#8217;s fun to thrash bikes</title>
		<link>http://notetoself.vrensk.com/2008/10/its-fun-to-thrash-bikes/</link>
		<comments>http://notetoself.vrensk.com/2008/10/its-fun-to-thrash-bikes/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 14:10:59 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Life outside work]]></category>
		<category><![CDATA[bike]]></category>
		<category><![CDATA[pleasure]]></category>
		<category><![CDATA[saving money]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=34</guid>
		<description><![CDATA[Note to self: don&#8217;t leave your bike parked downtown (or indeed on public streets) over the night.  Apparently there is a great deal of pleasure to be had by thrashing other people&#8217;s bicycles.  And while I take pleasure from seeing my fellow man enjoying himself, I cannot really afford to sponsor it any more.
I parked [...]]]></description>
			<content:encoded><![CDATA[<p>Note to self: don&#8217;t leave your bike parked downtown (or indeed on public streets) over the night.  Apparently there is a great deal of pleasure to be had by thrashing other people&#8217;s bicycles.  And while I take pleasure from seeing my fellow man enjoying himself, I cannot really afford to sponsor it any more.</p>
<p>I parked my bike on Magasinsgatan last night in order to watch <a href="http://www.korenrabalder.se/" onclick="pageTracker._trackPageview('/outgoing/www.korenrabalder.se/?referer=');">Rabalder</a> perform Requiem. (The concert was a treat in a way that would have made Mozart green with envy.  He would have died to have electric guitars in his setting!)  After the concert, I left the bike there and chose to walk to the next event (this being <a href="http://www.kulturnatta.goteborg.se/" onclick="pageTracker._trackPageview('/outgoing/www.kulturnatta.goteborg.se/?referer=');">Kulturnatta</a>) together with friends.  I live three blocks away and planned to pick up the bike on my way home.  Of course, I pride myself by not living by plans, and when picking up the bike on the way home turned out to be a six block detour, I decided to leave it for today.</p>
<p>I&#8217;ll have to walk more than six blocks to the bike shop to have the three kicked-off spokes replaced, though.  Hopefully it will be cheaper than having the front wheel replaced, like last time, or replacing the night lights the time before that.</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2008/10/its-fun-to-thrash-bikes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flash vulnerability</title>
		<link>http://notetoself.vrensk.com/2008/10/flash-vulnerability/</link>
		<comments>http://notetoself.vrensk.com/2008/10/flash-vulnerability/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 16:21:05 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Developer Client]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=32</guid>
		<description><![CDATA[Apparently something called &#8220;click-jacking&#8221; can be used to hijack the microphone and camera on my laptop and the way to avoid that is to tell Flash that it can never ever have access to mike and cam.  Fine, done.
There is a patch coming out in a few weeks (or it may just be included in [...]]]></description>
			<content:encoded><![CDATA[<p>Apparently something called &#8220;<a href="http://www.adobe.com/support/security/advisories/apsa08-08.html" onclick="pageTracker._trackPageview('/outgoing/www.adobe.com/support/security/advisories/apsa08-08.html?referer=');">click-jacking</a>&#8221; can be used to hijack the microphone and camera on my laptop and the way to avoid that is to tell Flash that it can never ever have access to mike and cam.  <a href="http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager02.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager02.html?referer=');">Fine, done</a>.</p>
<p>There is a patch coming out in a few weeks (or it may just be included in Flash 10 which I suppose will be a mandatory upgrade).  Fine again.  But how will I remember to go back and restore Flash&#8217;s access to my microphone and camera?  Well, hopefully I will see this blog entry the next time I write something.  Note to self.</p>
<p>Source: <a href="http://www.macworld.com/article/135961/2008/10/clickjackers.html" onclick="pageTracker._trackPageview('/outgoing/www.macworld.com/article/135961/2008/10/clickjackers.html?referer=');">Macworld</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2008/10/flash-vulnerability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Verified HTTPS in Ruby</title>
		<link>http://notetoself.vrensk.com/2008/09/verified-https-in-ruby/</link>
		<comments>http://notetoself.vrensk.com/2008/09/verified-https-in-ruby/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 22:06:32 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Certificate Authorities]]></category>
		<category><![CDATA[HTTPS]]></category>
		<category><![CDATA[peer validation]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=28</guid>
		<description><![CDATA[I need to pick up an XML file from a server every 30 minutes and process it.  I’ve done similar things before, and using Hpricot it is a pleasure:
#! /usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'

doc = Hpricot(open("http://example.com/the_file.xml"))
(doc / :person).each { &#124;person&#124; ... }

Couldn’t be simpler.  This time, there is a snag: the file is [...]]]></description>
			<content:encoded><![CDATA[<p>I need to pick up an XML file from a server every 30 minutes and process it.  I’ve done similar things before, and using <a href="http://code.whytheluckystiff.net/hpricot/" onclick="pageTracker._trackPageview('/outgoing/code.whytheluckystiff.net/hpricot/?referer=');">Hpricot</a> it is a pleasure:</p>
<pre><code>#! /usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'

doc = Hpricot(open("http://example.com/the_file.xml"))
(doc / :person).each { |person| ... }
</code></pre>
<p>Couldn’t be simpler.  This time, there is a snag: the file is sensitive, so the connection is encrypted using HTTPS.  For this article, let’s say we’re talking about <a href="http://www.cert.org/" onclick="pageTracker._trackPageview('/outgoing/www.cert.org/?referer=');">Cert’s</a> list of new vulnerabilities, which can be found at <a href="https://www.cert.org/blogs/vuls/rss.xml" onclick="pageTracker._trackPageview('/outgoing/www.cert.org/blogs/vuls/rss.xml?referer=');">https://www.cert.org/blogs/vuls/rss.xml</a>.  <code>open-uri</code> supports HTTPS, so it shouldn’t be a problem, but it is:</p>
<pre><code>doc = Hpricot(open("https://www.cert.org/blogs/vuls/rss.xml"))
# =&gt;
/usr/lib/ruby/1.8/net/http.rb:590:in `connect': certificate verify failed (OpenSSL::SSL::SSLError)
</code></pre>
<p><code>OpenSSL</code>, which <code>open-uri</code> uses behind the scenes, fails to verify Cert’s certificate and halts execution.</p>
<h2>Solution 1: skip verification</h2>
<p>Let’s assume that I don’t care much about the verification; all I want is the data, and it just so happens that it is only available through HTTPS.  <code>open-uri</code> doesn’t let me turn off verification so I have to dig deeper.</p>
<p><code>open-uri</code> is just a clever wrapper around Ruby’s comprehensive, but insufficiently documented, networking library that handles a variety of protocols, including HTTPS.  To fetch a web page over a secure connection, you can use something like this sample client (from <code>net/https.rb</code>):</p>
<pre><code>#! /usr/bin/env ruby
require 'net/https'
require 'uri'

uri = URI.parse(ARGV[0] || 'https://localhost/')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == "https"  # enable SSL/TLS
http.start {
  http.request_get(uri.path) {|res|
    print res.body
  }
}
</code></pre>
<p>There are three things to note in the sample client:</p>
<ol>
<li>You should <code>require</code> <code>net/https</code>, not <code>net/http</code>.</li>
<li>You create the client with <code>Net::HTTP.new</code>, not <code>Net::HTTPS.new</code>. (There is no <code>HTTPS</code> class despite the fact that you <code>require 'net/https'</code>.)</li>
<li>You need to set <code>use_ssl = true</code> explicitly.  The <code>URI</code> library is clever enough to set its port attribute to 443 when it parses a URI that starts with <code>https</code>, but <code>Net::HTTP</code> isn’t quite as clever.</li>
</ol>
<p>If you put the above code in <code>webclient.rb</code> and run it, you’ll see this:</p>
<pre><code>$ ruby webclient.rb https://www.cert.org/blogs/vuls/rss.xml
warning: peer certificate won't be verified in this SSL session
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;rss version="2.0"&gt;
    &lt;channel&gt;
        &lt;title&gt;Vulnerability Analysis Blog&lt;/title&gt;
[...]
</code></pre>
<p>Yes, it will fetch and print the RSS XML, but it will also warn you that it doesn’t verify the host’s certificate.  Let’s turn off the warning by telling <code>Net::HTTP</code> that we don’t expect it to perform any verification:</p>
<pre><code>uri = URI.parse(ARGV[0] || 'https://localhost/')
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https"  # enable SSL/TLS
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
http.start { ... }
</code></pre>
<p>Run this, and you get the same result without the warning.</p>
<h2>Solution 2: add verification</h2>
<p>Solution 1 is not enough for my current needs.  I want encryption, but I also want to know that I’m talking to the right server.  To turn on verification, I change <code>VERIFY_NONE</code> to <code>VERIFY_PEER</code> and run again.  Now I’m back on square one with <code>OpenSSL::SSL::SSLError: certificate verify failed</code>.  Uh-huh.  So what’s wrong with that one?  It works in my browser without problems.</p>
<p>I’m not going to go into how HTTPS and certificate validation works.  Suffice it so say that my browser is more trusting than <code>OpenSSL</code>.  And it’s not blind trust either; the browser knows more Certificate Authorities.  So how do I add them to Ruby and <code>OpenSSL</code>?  I looked around and found a solution to a similar problem, <a href="http://blog.seagul.co.uk/articles/2006-10-24-connecting-to-gmail-with-ruby-or-connecting-to-pop3-servers-over-ssl-with-ruby" onclick="pageTracker._trackPageview('/outgoing/blog.seagul.co.uk/articles/2006-10-24-connecting-to-gmail-with-ruby-or-connecting-to-pop3-servers-over-ssl-with-ruby?referer=');">Connecting to POP3 servers over SSL with Ruby</a>.  Adapting that to my HTTPS problem, it becomes a two-step solution:</p>
<ol>
<li>Download the <a href="http://curl.haxx.se/ca/cacert.pem" onclick="pageTracker._trackPageview('/outgoing/curl.haxx.se/ca/cacert.pem?referer=');">CA Root Certificates bundle</a> from haxx.se, the creators of <code>curl</code>.  Store the file in the same directory as <code>webclient.rb</code> and make sure that it’s called <code>cacert.pem</code>.  (But please see the discussion below on <em>Too much trust</em>.)</li>
<li>Make <code>webclient.rb</code> use this file instead of whatever is bundled with <code>OpenSSL</code>.</li>
</ol>
<p>Now we can tell <code>Net::HTTP</code> to use this CA file:</p>
<pre><code>uri = URI.parse(ARGV[0] || 'https://localhost/')
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https"  # enable SSL/TLS
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")
end
http.start { ... }
</code></pre>
<p>Look, it works!  It gives the expected output, and it is verifying… something.  But what?  Time to look under the hood again.  It turns out that with these settings, <code>OpenSSL</code> checks that the server certificate is signed by a known CA and has not expired, which is good, but not everything I’m looking for.  I also want it to check that the certificate belongs to the server that I’m talking to.  To see an example, go to <a href="https://google.com/" onclick="pageTracker._trackPageview('/outgoing/google.com/?referer=');">https://google.com/</a>.  In Firefox 3, you should get an iconic policeman telling you it’s a Page Load Error.  The certificate belongs to <code>www.google.com</code>, not <code>google.com</code>.  But our script is not quite as discerning:</p>
<pre><code>$ ruby webclient.rb https://google.com/
hostname was not match with the server certificate
&lt;HTML&gt;&lt;HEAD&gt;&lt;meta http-equiv="content-type" content="text/html;charset=utf-8"&gt;
&lt;TITLE&gt;302 Moved&lt;/TITLE&gt;&lt;/HEAD&gt;&lt;BODY&gt;
&lt;H1&gt;302 Moved&lt;/H1&gt;
The document has moved
&lt;A HREF="http://www.google.com"&gt;here&lt;/A&gt;.
&lt;/BODY&gt;&lt;/HTML&gt;
</code></pre>
<p>Note the warning on the first line of output.  Apparently <code>Net::HTTP</code> checks to see if the certificate belongs to the host, but it’s not a fatal error.  To change this, we need to enable the “post-connection check”.  So here is the final version of the script:</p>
<pre><code>#! /usr/bin/env ruby
require 'net/https'
require 'uri'

uri = URI.parse(ARGV[0] || 'https://localhost/')
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https"  # enable SSL/TLS
  http.use_ssl = true
  http.enable_post_connection_check = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")
end
http.start {
  http.request_get(uri.path) {|res|
    print res.body
  }
}
</code></pre>
<p>Now it will fail for <code>https://google.com/</code> but succeed for <code>https://www.google.com/</code>.  Done!</p>
<h2>Too much trust</h2>
<p>OK, I should admit that downloading a file from someplace called <code>haxx.se</code> doesn’t seem like the best way to raise security.  If you really want to know who you will be trusting, you should download Root Certificates from each of the CA’s that you trust.  That’s way too much work for the application I’m working on right now, but it might be a requirement for you.  If you don’t want to go mad, though, try doing it the same way the haxx people did.  They wrote a little tool to extract the Root Certificates from the source files of Mozilla, and they even have a tool for extracting it from your binary installation.  Check out <a href="http://curl.haxx.se/docs/caextract.html" onclick="pageTracker._trackPageview('/outgoing/curl.haxx.se/docs/caextract.html?referer=');">their documentation</a> for a full description and links to the tools (source code).</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2008/09/verified-https-in-ruby/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>XHTML unsupported, prefer HTML</title>
		<link>http://notetoself.vrensk.com/2008/08/xhtml-unsupported-prefer-html/</link>
		<comments>http://notetoself.vrensk.com/2008/08/xhtml-unsupported-prefer-html/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 15:27:04 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=19</guid>
		<description><![CDATA[[This is a re-write of a project note I wrote in project over a year ago.  Published here to make the world a better place.]
There has been some commotion recently regarding XHTML and HTML, where standardistas have reiterated their arguments about XHTML: it’s a nice standard, but since is isn’t actually treated as XHTML [...]]]></description>
			<content:encoded><![CDATA[<p><em>[This is a re-write of a project note I wrote in project over a year ago.  Published here to make the world a better place.]</em></p>
<p>There has been some commotion recently regarding XHTML and HTML, where standardistas have reiterated their arguments about XHTML: it’s a nice standard, but since is isn’t actually treated as XHTML by browsers, it’s better to use HTML.</p>
<p>The “standard” text on this (at least for me) is <a href="http://www.hixie.ch/advocacy/xhtml" onclick="pageTracker._trackPageview('/outgoing/www.hixie.ch/advocacy/xhtml?referer=');">http://www.hixie.ch/advocacy/xhtml</a> from which I&#8217;d like to quote the executive summary:</p>
<blockquote>
<p>If you use XHTML, you should deliver it with the application/xhtml+xml MIME type. If you do not do so, you should use HTML4 instead of XHTML. The alternative, using XHTML but   delivering it as text/html, causes numerous problems that are outlined below. Unfortunately, IE6   does not support application/xhtml+xml (in fact, it does not support XHTML at all).</p>
</blockquote>
<p>I have come back to that text on several occasions, but it never quite convinced me.  I didn&#8217;t want to lose the well-formedness of XHTML.  Then I ran across <a href="http://www.webdevout.net/articles/beware-of-xhtml" onclick="pageTracker._trackPageview('/outgoing/www.webdevout.net/articles/beware-of-xhtml?referer=');">http://www.webdevout.net/articles/beware-of-xhtml</a> which made me change my mind. The article uses numerous examples to show that XHTML is not just a syntactically nicer version of HTML, but it actually has slightly differing rules for how to apply CSS.  So basically, in all projects that I have used XHTML, I have been relying on bugs in present browsers.  Ouch.</p>
<h3 id="time_to_change8212back">Time to change&#8212;back</h3>
<p>They promised us that XHTML was the future, so I haven&#8217;t worried too much about HTML lately. Are there any downsides to using HTML instead?  Well, not per se.  But the tools and platforms I use are slightly XHTML-centric.</p>
<ol>
<li>
<p>All the standard Rails helpers (form helpers, JS helpers, etc.) produce xhtml.  The simple solution is to drop this in a file in <code>lib/</code>:</p>
<pre><code>module ActionView::Helpers::TagHelper
  def tag_with_html_syntax(name, options = nil, open = true, escape = true)
    tag_without_html_syntax(name, options, open, escape)
  end
  alias_method_chain :tag, :html_syntax
end
</code></pre>
</li>
<li>
<p><a href="http://macromates.com/" onclick="pageTracker._trackPageview('/outgoing/macromates.com/?referer=');">TextMate</a> snippets produce XHTML. Most of them can be controlled by an  environment variable, but there are exceptions, like C-ret which produces produces an XHTML self-closed br element.</p>
</li>
<li>External tools, data sources and parsers are usually xml-centric.</li>
<li><a href="http://wordpress.org/" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/?referer=');">WordPress</a>, which I have used for a few client projects lately, spits out XHTML. I&#8217;ll see if I can create a patch for that and have it accepted.</li>
</ol>
<p>Oh well.  XHTML, I&#8217;ll miss you.  HTML, can we be friends again?</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2008/08/xhtml-unsupported-prefer-html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Escaping single quotes in Ruby harder than expected</title>
		<link>http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/</link>
		<comments>http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 14:23:22 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[SQL escape]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=15</guid>
		<description><![CDATA[So I was writing this tool to create a bunch of SQL statements from a data dump.  Simple enough, right.  And as always when you generate SQL statements, you have to make sure that the data doesn’t interfere with the SQL syntax by escaping the single quotes (and generally any binary data, but [...]]]></description>
			<content:encoded><![CDATA[<p>So I was writing this tool to create a bunch of SQL statements from a data dump.  Simple enough, right.  And as always when you generate SQL statements, you have to make sure that the data doesn’t interfere with the SQL syntax by escaping the single quotes (and generally any binary data, but I didn’t have that).  Any database gem/module/library has that built-in, of course, but I didn’t want to use that.  So I said <strong>[Note: this doesn't work. Read on for the solution.]</strong></p>
<pre><code>def quote (str)
  str.gsub('\\','\\\\').gsub('\'','\\\'')
end
</code></pre>
<p>I read this as “replace all backslashes with double backslashes, and then replace all single quotes with a backslash and a single quote”.  I added a simple test for it (yay TestUnit!):</p>
<pre><code>def setup
  @m = Migrate.new
end

def test_quote
  assert_equal("I\\'m home", @m.quote("I'm home"))
end

</code></pre>
<p>But imagine my surprise when I got</p>
<pre><code>  1) Failure:
test_quote(TestMigrate) [migration/test_migrate.rb:29]:
&lt; "I\\'m home"&gt; expected but was
&lt; "Im homem home"&gt;.
</code></pre>
<p>Ooookay.  What’s wrong here?  Have I misunderstood the rules for escaping the escape sequence?  It’s supposed to be easier with single quotes, but maybe I got it wrong.  So I tried with double quotes:</p>
<pre><code>def quote (str)
  str.gsub("\\","\\\\").gsub("'","\\'")
end
</code></pre>
<p>Surely this would work?  Nope, it gives the exact same error.  Time to look up <code>gsub</code> in the <a href="http://www.ruby-doc.org/core/classes/String.html#M000749" onclick="pageTracker._trackPageview('/outgoing/www.ruby-doc.org/core/classes/String.html_M000749?referer=');">manual</a>:</p>
<blockquote><p><strong>str.gsub(pattern, replacement) =&gt; new_str<br />
str.gsub(pattern) {|match| block } =&gt; new_str</strong></p>
<p>[…] If a string is used as the replacement, special variables from the match (such as $&amp; and $1) cannot be substituted into it, as substitution into the string occurs before the pattern match starts. However, the sequences \1, \2, <strong>and so on</strong> [my emphasis] may be used to interpolate successive groups in the match.</p></blockquote>
<p>“And so on”?  Oh, so obviously <code>\'</code> (escaped <code>\\'</code> in the string literal) is the replacement string equivalent of <code>$'</code>, which means everything afther the match (as all regexp hackers know).  So I need to escape the backslash for regexp engine too:</p>
<pre><code>def quote (str)
  str.gsub("\\","\\\\").gsub("'","\\\\'")
end
</code></pre>
<p>OK, the tests pass.  But the code looks wrong.  Four backslashes can’t work for both cases, can they?  Let’s add a test case:</p>
<pre><code>def test_quote
  assert_equal("I\\'m home", @m.quote("I'm home"))
  assert_equal("S\\\\N", @m.quote("S\\N"))
end

</code></pre>
<p>Nope, that fails.  So we need this:</p>
<pre><code>def quote (str)
  str.gsub("\\","\\\\\\\\").gsub("'","\\\\'")
end
</code></pre>
<p>Eight backslashes.  Yes, the test passes, but is it worth it?  Is it understandable?  I don’t want comments to explain my code.  Comments are good to provide a raison d’être for something, but not to explain its looks.  Let’s switch to the other form of gsub:</p>
<pre><code>def quote (str)
  str.gsub(/\\|'/) { |c| "\\#{c}" }
end
</code></pre>
<p>“If you see a backslash or a single quote, replace it with a backslash and whatever you saw.”  That’s what I wanted to say anyway.</p>
<p>Good.  But I wrote this in <a href="http://daringfireball.net/projects/markdown/syntax" onclick="pageTracker._trackPageview('/outgoing/daringfireball.net/projects/markdown/syntax?referer=');">Markdown</a>, so now I have to generate the HTML and the go through it and make sure that I restore whatever backslashes Markdown ate. (It turns out it didn&#8217;t eat any.  TextMate has a Markdown Preview function that ate a lot of backslashes, but when I said &#8220;Convert to HTML&#8221; it didn&#8217;t eat any at all.  Go figure.)</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The survey</title>
		<link>http://notetoself.vrensk.com/2008/08/the-survey/</link>
		<comments>http://notetoself.vrensk.com/2008/08/the-survey/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 12:44:40 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[The daily grind]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=12</guid>
		<description><![CDATA[It&#8217;s time for the yearly survey for web professionals:

But that&#8217;s hardly a note to self.  Looks like I&#8217;m turning this into a blog.
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s time for the yearly survey for web professionals:<br />
<a href="http://www.alistapart.com/articles/survey2008" onclick="pageTracker._trackPageview('/outgoing/www.alistapart.com/articles/survey2008?referer=');"><img class="aligncenter size-full wp-image-13" title="i-took-the-2008-survey" src="http://notetoself.vrensk.com/wp-content/uploads/2008/08/i-took-the-2008-survey.gif" alt="" width="180" height="46" /></a></p>
<p>But that&#8217;s hardly a note to self.  Looks like I&#8217;m turning this into a blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2008/08/the-survey/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql gem on OS X Leopard</title>
		<link>http://notetoself.vrensk.com/2008/07/mysql-gem-on-os-x-leopard/</link>
		<comments>http://notetoself.vrensk.com/2008/07/mysql-gem-on-os-x-leopard/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 14:03:54 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Developer Client]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[Leopard]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[works for me]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=9</guid>
		<description><![CDATA[Installing the mysql gem for Ruby is almost always a mess, as witnessed by the large number of hits one get when googling for &#8220;mysql gem leopard&#8221;.  To make the gem work with your platform, you need to ensure that the &#8216;make&#8217; command run internally by &#8216;gem&#8217; has the right ARCHFLAGS, which most of the [...]]]></description>
			<content:encoded><![CDATA[<p>Installing the mysql gem for Ruby is almost always a mess, as witnessed by the <a href="http://www.notsostupid.com/blog/2007/10/25/ruby-leopard-and-gems/" onclick="pageTracker._trackPageview('/outgoing/www.notsostupid.com/blog/2007/10/25/ruby-leopard-and-gems/?referer=');">large</a> <a href="http://www.schmidp.com/2007/9/29/rails-mysql-and-leopard" onclick="pageTracker._trackPageview('/outgoing/www.schmidp.com/2007/9/29/rails-mysql-and-leopard?referer=');">number</a> <a href="http://www.rubyhead.com/2007/10/29/mysql-gem-in-leopard/" onclick="pageTracker._trackPageview('/outgoing/www.rubyhead.com/2007/10/29/mysql-gem-in-leopard/?referer=');">of</a> <a href="http://weblog.rubyonrails.org/2007/10/26/today-is-leopard-day" onclick="pageTracker._trackPageview('/outgoing/weblog.rubyonrails.org/2007/10/26/today-is-leopard-day?referer=');">hits</a> one get when googling for &#8220;mysql gem leopard&#8221;.  To make the gem work with your platform, you need to ensure that the &#8216;make&#8217; command run internally by &#8216;gem&#8217; has the right ARCHFLAGS, which most of the web pages will tell you about.  So</p>
<pre>sudo env ARCHFLAGS='-arch i386' gem install mysql</pre>
<p>should handle it, more or less.  But since Leopard (the client version) does not have mysql, you will have had to install that on your own (I installed the MySQL binary package for 10.4, from <a href="http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg" onclick="pageTracker._trackPageview('/outgoing/dev.mysql.com/downloads/mysql/5.0.html_macosx-dmg?referer=');">dev.mysql.com</a>, because there was no 10.5 package available the day after I Leopard was released), and &#8216;gem&#8217; isn&#8217;t good at guessing where it is.  So I need to say</p>
<pre>sudo env ARCHFLAGS='-arch i386' gem install mysql -- --with-mysql-dir=/usr/local/mysql</pre>
<p>But for some reason that is not quite enough either.  I get this error:</p>
<pre>/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle:
dlopen(/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9):
Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib (LoadError)

  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle

  Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
      from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:32:in `require'
      from my_script.rb:6</pre>
<p>Hey, look at that.  It actually tries to load the lib from `/usr/local/mysql/lib/mysql` rather than `/usr/local/mysql/lib`.  Why?  I don&#8217;t know.  I couldn&#8217;t be bothered to dive into the code, so I went for the quick workaround:</p>
<pre>sudo ln -s . /usr/local/mysql/lib/mysql</pre>
<p>Silly, and perhaps not the cleanest way to do it, but it works for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2008/07/mysql-gem-on-os-x-leopard/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Apache with PHP on FC6</title>
		<link>http://notetoself.vrensk.com/2008/07/apache-with-php-on-fc6/</link>
		<comments>http://notetoself.vrensk.com/2008/07/apache-with-php-on-fc6/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 18:00:08 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Server Configuration]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[FC6]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[private DNS]]></category>
		<category><![CDATA[SELinux]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=7</guid>
		<description><![CDATA[I acquired this server in December 2006 to host a few Rails projects and one of the first things I did was to disable Apache and install Nginx.  Once I decided to use Wordpress for this blog, I needed PHP, and while I could have tried to set up PHP for Nginx, I decided to [...]]]></description>
			<content:encoded><![CDATA[<p>I acquired this server in December 2006 to host a few <a href="http://www.rubyonrails.org/" onclick="pageTracker._trackPageview('/outgoing/www.rubyonrails.org/?referer=');">Rails</a> projects and one of the first things I did was to disable Apache and install Nginx.  Once I decided to use Wordpress for this blog, I needed PHP, and while I could have tried to set up PHP for Nginx, I decided to go the easy route and use the familiar LAMP combo.  I have after all used Apache in various guises ever since it was the Cern httpd back in 1993, so it should be no match for me.</p>
<p>Not so.  But to make a long story short and save myself some time next time around, here are the mistakes I made:</p>
<h2>Private DNS</h2>
<p>My wardrobe server (on my home network) hosts a number of public-facing web servers; little things that I set up for friends before I started doing web work professionally.  So, for instance www.norbusam.org points to my fixed home IP, and all traffic on port 80 is forwarded to my server.  The WGR614 that I use for NAT and routing is not smart enough to let me use the public interface from the private part of the network, i.e. if I sit at my desk at home and enter www.norbusam.org into my web browser, I won&#8217;t get anywhere.  That would have annoyed me if I hadn&#8217;t liked the solution so much: I set up a DNS daemon on the home server and let it trick all home computers to use the internal interface (192.168.x.y) for norbusam.org and others.  Easy as pie.</p>
<p>This came back to bite me for hours on end last night.  notetoself.vrensk.com was pointing at my home server, so while I was hacking the Apache settings on this server and reloading my browser furiously, all I got was my home server.  And since both run Apache, I never got suspicious—it just looked like my changes didn&#8217;t take.  Ouch.</p>
<h2>SELinux</h2>
<p>This server is running Security Enhanced Linux out of the box.  I asked for a vanilla install of FC6, and apparently SELinux is switched on by default.  I decided to keep it on when I got the server since I saw it as a learning opportunity.  It caused me some problems when I set up Postfix when the server was new, but I sorted it out and haven&#8217;t thought about it since then.</p>
<p>This, too, came back to bite me for a couple of hours.  It turns out that the default setting of SE for Apache are somewhere between frugal and paranoid.  There are various security bits to be set or cleared, and the default setting assumes that I only want to publish pages from a root-blessed directory and that I don&#8217;t want to run any scripts, use a database or have httpd talk to any other servers out there.  Rather than go through all these settings one by one and reverse them (and risk disabling something that was actually permissive to start with) I decided to turn off SELinux for Apache:</p>
<pre># setsebool -P httpd_disable_trans 1</pre>
<p>Followed by a restart (not reload) of Apache.  I&#8217;m indebted to <a href="http://beginlinux.com/index.php/server_training/web-server/117-web-server/976-apache-and-selinux" onclick="pageTracker._trackPageview('/outgoing/beginlinux.com/index.php/server_training/web-server/117-web-server/976-apache-and-selinux?referer=');">an article at Begin Linux</a> for this solution.  I can&#8217;t recommend reading the actual article though, as it is just a long recapitulation of man pages and other documentation without a trace of explanation or even a try to put things in context.</p>
<p>Oh well.  Next time I will make sure to double check my IPs and disable SELinux at least while setting up a system.</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2008/07/apache-with-php-on-fc6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Manifesto</title>
		<link>http://notetoself.vrensk.com/2008/07/manifesto/</link>
		<comments>http://notetoself.vrensk.com/2008/07/manifesto/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 16:57:43 +0000</pubDate>
		<dc:creator>David Vrensk</dc:creator>
				<category><![CDATA[Meta]]></category>

		<guid isPermaLink="false">http://notetoself.vrensk.com/?p=3</guid>
		<description><![CDATA[While this is a public blog, its primary audience is not the meandering surfers of the inter-tubes, but myself.  I need someplace to store various findings and HOWTOs that I write for myself.  I assume that they will prove useful for others too, from time to time, but that is mostly a side-effect.
That being said, [...]]]></description>
			<content:encoded><![CDATA[<p>While this is a public blog, its primary audience is not the meandering surfers of the inter-tubes, but myself.  I need someplace to store various findings and HOWTOs that I write for myself.  I assume that they will prove useful for others too, from time to time, but that is mostly a side-effect.</p>
<p>That being said, I might produce the occasional rant or Instruction For Your Betterment or something else intended for public consumption.  I will let you know.</p>
]]></content:encoded>
			<wfw:commentRss>http://notetoself.vrensk.com/2008/07/manifesto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
