<?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>self.d-struct.org &#187; work</title>
	<atom:link href="http://self.d-struct.org/category/work/feed" rel="self" type="application/rss+xml" />
	<link>http://self.d-struct.org</link>
	<description></description>
	<lastBuildDate>Mon, 23 Jan 2012 04:49:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[scene]</title>
		<link>http://self.d-struct.org/435/scene</link>
		<comments>http://self.d-struct.org/435/scene#comments</comments>
		<pubDate>Fri, 16 Sep 2011 21:01:55 +0000</pubDate>
		<dc:creator>Chris Gansen</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[ibm]]></category>
		<category><![CDATA[ofa]]></category>

		<guid isPermaLink="false">http://self.d-struct.org/?p=435</guid>
		<description><![CDATA[Today is my last day with IBM Interactive. After six years, I&#8217;m moving on. Working for IBM has been a tremendous experience. Fresh out of college in 2005, I had little idea what I was signing up for. My first task was rather menial: packing the office for its move across town. Immediately after that, [...]]]></description>
			<content:encoded><![CDATA[<p>Today is my last day with <a href="http://www.ibminteractive.com" target="_blank">IBM Interactive</a>. After six years, I&#8217;m moving on.</p>
<p>Working for IBM has been a tremendous experience. Fresh out of college in 2005, I had little idea what I was signing up for. My first task was rather menial: packing the office for its move across town. Immediately after that, Katrina hit and I was tasked with building a quick-and-dirty job search engine to help displaced workers. It was that project that revealed to me the scope and reach of IBM&#8217;s influence. No longer was I hacking on dorm room projects; now I was building sites that ended up featured on cable news broadcasts.</p>
<p>In the years that followed, I had the great fortune and privilege to work on a variety of projects supported by IBM&#8217;s corporate citizenship group: designing and building the platform that powers the <a href="http://www.smetoolkit.org/" target="_blank">SME Toolkit</a>, a partnership with the International Finance Group and the World Bank; rebuilding the online presence of the <a href="http://www.hermitage.ru" target="_blank">State Hermitage Museum in St. Petersburg, Russia</a>; and building tools for <a href="http://www.acp-usa.org/" target="_blank">American Corporate Partners</a> to help our nation&#8217;s veterans.</p>
<p>By far the most exciting experience I had at IBM was the Corporate Service Corps, a 4 week leadership development program in Arusha, Tanzania. Paired with 7 other IBMers, we assisted local NGO and a college with various projects. This was unlike anything I have done: no programming, no Internet. Every day was a new challenge, a new surprise, and we did our best to help our partners with whatever they could throw at us.</p>
<p>What&#8217;s next? I&#8217;m joining the <a href="http://www.barackobama.com/">Obama for America re-election campaign</a>. It&#8217;ll be fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://self.d-struct.org/435/scene/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Handling Nested CDATA With Builder</title>
		<link>http://self.d-struct.org/361/handling-nested-cdata-with-builder</link>
		<comments>http://self.d-struct.org/361/handling-nested-cdata-with-builder#comments</comments>
		<pubDate>Tue, 21 Sep 2010 21:19:29 +0000</pubDate>
		<dc:creator>Chris Gansen</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://self.d-struct.org/?p=361</guid>
		<description><![CDATA[As noted by our associates at Atomic Object, XML doesn&#8217;t allow for nested&#60;![CDATA[&#8230;]]&#62; elements. In the course of rewriting some pieces of code, I developed the following Builder workaround to allow our application to export valid XML by breaking the nested CDATA elements into distinct chunks. When read back in via our Nokogiri-based parser, it [...]]]></description>
			<content:encoded><![CDATA[<p>As <a href="http://spin.atomicobject.com/2010/09/01/working-with-embedded-cdata-in-xml-documents" target="_blank">noted by our associates at Atomic Object</a>, XML doesn&#8217;t allow for nested&lt;![CDATA[&hellip;]]&gt; elements. In the course of rewriting some pieces of code, I developed the following <a href="http://builder.rubyforge.org/" target="_blank">Builder</a> workaround to allow our application to export valid XML by breaking the nested CDATA elements into distinct chunks. When read back in via our <a href="http://nokogiri.org/Nokogiri.html" target="_blank">Nokogiri</a>-based parser, it concatenates the values automagically, and the end result is clean, valid XML.</p>
<p>Fix code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> Builder
  <span style="color:#9966CC; font-weight:bold;">class</span> XmlMarkup <span style="color:#006600; font-weight:bold;">&lt;</span> XmlBase
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> cdata_with_escaping!<span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> text =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>\<span style="color:#006600; font-weight:bold;">&#93;</span>\<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>
        text.<span style="color:#CC0066; font-weight:bold;">gsub!</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>\<span style="color:#006600; font-weight:bold;">&#93;</span>\<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">&quot;]]]]&gt;&lt;![CDATA[&gt;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      cdata_without_escaping!<span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    alias_method_chain <span style="color:#996600;">'cdata!'</span>, <span style="color:#996600;">'escaping'</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Sample output:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> xml = <span style="color:#6666ff; font-weight:bold;">Builder::XmlMarkup</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>str<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> xml.<span style="color:#9900CC;">cdata</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;&lt;![CDATA[Foo bar sna]]&gt;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> xml.<span style="color:#9900CC;">target</span>!
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&lt;![CDATA[&lt;![CDATA[Foo bar sna]]]]&gt;&lt;![CDATA[&gt;]]&gt;&quot;</span>  <span style="color:#008000; font-style:italic;"># valid XML!</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> xml.<span style="color:#9900CC;">cdata_without_escaping</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;&lt;![CDATA[Foo bar sna]]&gt;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> xml.<span style="color:#9900CC;">target</span>!
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&lt;![CDATA[&lt;![CDATA[Foo bar sna]]&gt;]]&gt;&quot;</span> <span style="color:#008000; font-style:italic;"># invalid XML!</span></pre></div></div>

<p>Sample parsing with Nokogiri:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> doc = <span style="color:#6666ff; font-weight:bold;">Nokogiri::XML</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;&lt;baz&gt;&lt;![CDATA[&lt;![CDATA[Foo bar sna]]]]&gt;&lt;![CDATA[&gt;]]&gt;&lt;/baz&gt;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#008000; font-style:italic;">#&lt;Nokogiri::XML::Document:0x825aff3c name=&quot;document&quot; children=[#&lt;Nokogiri::XML::Element:0x825afc1c name=&quot;baz&quot; children=[#&lt;Nokogiri::XML::CDATA:0x825af99c &quot;&lt;![CDATA[Foo bar sna]]&gt;&quot;&gt;]&gt;]&gt;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> doc.<span style="color:#9900CC;">css</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'baz'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">content</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&lt;![CDATA[Foo bar sna]]&gt;&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://self.d-struct.org/361/handling-nested-cdata-with-builder/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tracking Drupal User Registrations by Date</title>
		<link>http://self.d-struct.org/354/tracking-drupal-user-registrations-by-date</link>
		<comments>http://self.d-struct.org/354/tracking-drupal-user-registrations-by-date#comments</comments>
		<pubDate>Fri, 10 Sep 2010 22:26:40 +0000</pubDate>
		<dc:creator>Chris Gansen</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://self.d-struct.org/?p=354</guid>
		<description><![CDATA[Today I wanted to graph the number of registrations recorded by a Drupal site grouped by date. Drupal stores all account data in the users table. To identify accounts that are registered and verified, I queried with &#8220;login != 0&#8243; in my WHERE clause, e.g. SELECT COUNT&#40;*&#41; FROM user WHERE login != 0; Since Drupal [...]]]></description>
			<content:encoded><![CDATA[<p>Today I wanted to graph the number of registrations recorded by a Drupal site grouped by date. Drupal stores all account data in the users table. To identify accounts that are registered and verified, I queried with &#8220;login != 0&#8243; in my WHERE clause, e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">COUNT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #CC0099;">*</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #000099;">user</span> <span style="color: #990099; font-weight: bold;">WHERE</span> login <span style="color: #CC0099;">!=</span> <span style="color: #008080;">0</span><span style="color: #000033;">;</span></pre></div></div>

<p>Since Drupal stores all dates as PHP-style Unix timestamps, e.g. <a href="http://www.epochconverter.com/">1284157128</a>, I needed to convert those into a form that MySQL understands. I used <a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_from-unixtime" target="_blank">from_unixtime()</a> to convert the date to a MySQL date type. By casting, I was then able to use the column in a GROUP BY clause, yielding my result:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">COUNT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #CC0099;">*</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #000099;">DATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">FROM_UNIXTIME</span><span style="color: #FF00FF;">&#40;</span>created<span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">as</span> created_date
<span style="color: #990099; font-weight: bold;">FROM</span> users <span style="color: #990099; font-weight: bold;">WHERE</span> login <span style="color: #CC0099;">!=</span> <span style="color: #008080;">0</span> <span style="color: #990099; font-weight: bold;">GROUP BY</span> created_date<span style="color: #000033;">;</span></pre></div></div>

<p>Which produced results just as I wanted them:</p>
<p><a href="http://self.d-struct.org/wp-content/uploads/2010/09/registrations.png"><img class="size-full wp-image-355 alignnone" title="registrations" src="http://self.d-struct.org/wp-content/uploads/2010/09/registrations.png" alt="" width="211" height="271" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://self.d-struct.org/354/tracking-drupal-user-registrations-by-date/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOWTO: Watermarking Images with ImageMagick and attachment_fu</title>
		<link>http://self.d-struct.org/175/watermarking-images-with-imagemagick-and-attachment_fu</link>
		<comments>http://self.d-struct.org/175/watermarking-images-with-imagemagick-and-attachment_fu#comments</comments>
		<pubDate>Fri, 15 Jan 2010 04:50:12 +0000</pubDate>
		<dc:creator>Chris Gansen</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://self.d-struct.org/?p=175</guid>
		<description><![CDATA[While working on a project for the State Hermitage Museum last year, I had to implement some image watermarking. The basic requirement was that for a certain type of uploaded image, its largest thumbnail should have the museum&#8217;s logo tiled across it. I was using attachment_fu to handle the image upload, and ImageMagick/RMagick to process [...]]]></description>
			<content:encoded><![CDATA[<p>While working on a project for the <a href="http://www.hermitage.ru/" target="_blank">State Hermitage Museum</a> last year, I had to implement some image watermarking. The basic requirement was that for a certain type of uploaded image, its largest thumbnail should have the museum&#8217;s logo tiled across it. I was using <a href="http://github.com/technoweenie/attachment_fu" target="_blank">attachment_fu</a> to handle the image upload, and <a href="http://www.imagemagick.org/script/index.php" target="_blank">ImageMagick</a>/<a href="http://rmagick.rubyforge.org/" target="_blank">RMagick</a> to process the thumbnails.</p>
<p>After some cursory Googling, I found the<a href="http://www.imagemagick.org/Usage/annotating/#grey_tiled" target="_blank"> ImageMagick Annotating guide</a>, which had this sample watermark command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> $ convert overlay.png  <span style="color: #660033;">-fill</span> grey50 <span style="color: #660033;">-colorize</span> <span style="color: #000000;">40</span>  miff:- <span style="color: #000000; font-weight: bold;">|</span>\
    composite <span style="color: #660033;">-dissolve</span> <span style="color: #000000;">15</span> <span style="color: #660033;">-tile</span>  -  original.jpg watermarked_image.jpg</pre></div></div>

<p>The dissection of the command:</p>
<p><strong>overlay.png</strong>: The source image to overlay</p>
<p><strong>-fill grey50 -colorize 40</strong>: Alter the colors of the watermark file</p>
<p><strong>composite</strong>: command to overlay the watermark</p>
<p><strong>-dissolve 15 -tile</strong>: &#8220;dissolve&#8221; the overlay at 15%, for good transparency, and tile (repeat) the watermark over the source image.</p>
<p>That&#8217;s simple enough, and with these source files:</p>
<div id="attachment_245" class="wp-caption aligncenter" style="width: 160px"><a href="http://self.d-struct.org/wp-content/uploads/2010/01/overlay.png"><img class="size-full wp-image-245" title="overlay" src="http://self.d-struct.org/wp-content/uploads/2010/01/overlay.png" alt="" width="150" height="150" /></a><p class="wp-caption-text">overlay.png</p></div>
<p style="text-align: center;">and dearest Rufus:</p>
<div id="attachment_246" class="wp-caption aligncenter" style="width: 510px"><a href="http://self.d-struct.org/wp-content/uploads/2010/01/rufus.jpg"><img class="size-full wp-image-246" title="rufus" src="http://self.d-struct.org/wp-content/uploads/2010/01/rufus.jpg" alt="rufus.jpg" width="500" height="344" /></a><p class="wp-caption-text">rufus.jpg</p></div>
<p style="text-align: center;">

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> $ convert overlay.png <span style="color: #660033;">-fill</span> grey50 <span style="color: #660033;">-colorize</span> <span style="color: #000000;">40</span> miff:- <span style="color: #000000; font-weight: bold;">|</span>\
    composite <span style="color: #660033;">-dissolve</span> <span style="color: #000000;">15</span> <span style="color: #660033;">-tile</span> - rufus.jpg result-15.jpg</pre></div></div>

<p>Produces:</p>
<div id="attachment_247" class="wp-caption aligncenter" style="width: 510px"><a href="http://self.d-struct.org/wp-content/uploads/2010/01/result-15.jpg"><img class="size-full wp-image-247" title="result-15" src="http://self.d-struct.org/wp-content/uploads/2010/01/result-15.jpg" alt="" width="500" height="344" /></a><p class="wp-caption-text">Overlay with 15% dissolve</p></div>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">convert overlay.png <span style="color: #660033;">-fill</span> grey50 <span style="color: #660033;">-colorize</span> <span style="color: #000000;">40</span> miff:- <span style="color: #000000; font-weight: bold;">|</span>\
  composite <span style="color: #660033;">-dissolve</span> <span style="color: #000000;">50</span> <span style="color: #660033;">-tile</span> - rufus.jpg result-50.jpg</pre></div></div>

<div id="attachment_248" class="wp-caption aligncenter" style="width: 510px"><a href="http://self.d-struct.org/wp-content/uploads/2010/01/result-50.jpg"><img class="size-full wp-image-248" title="result-50" src="http://self.d-struct.org/wp-content/uploads/2010/01/result-50.jpg" alt="" width="500" height="344" /></a><p class="wp-caption-text">Overlay with 50% dissolve</p></div>
<p>Unfortunately, RMagick&#8217;s <code>watermark</code> method doesn&#8217;t support tiling. To work around, I had to call the <code>composite_tiled!</code> method on a colorized image. This code is in my Thumbnail model, which includes attachment_fu:</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Thumbnail <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_attachment  <span style="color:#ff3333; font-weight:bold;">:content_type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:image</span>,
   <span style="color:#008000; font-style:italic;"># some settings omitted</span>
   <span style="color:#ff3333; font-weight:bold;">:watermark_overlay</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'/public/images/watermark-overlay-image.png'</span><span style="color:#006600; font-weight:bold;">&#41;</span>,
   <span style="color:#ff3333; font-weight:bold;">:watermarkable_size</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;1500&gt;&quot;</span> 
&nbsp;
  after_attachment_saved <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>record<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> record.<span style="color:#5A0A0A; font-weight:bold;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:parent_id</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">and</span> record.<span style="color:#9900CC;">parent_id</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#008000; font-style:italic;"># the original image, not the smaller thumbnails</span>
      with_image record.<span style="color:#9900CC;">full_filename</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>img<span style="color:#006600; font-weight:bold;">|</span>
        img.<span style="color:#9900CC;">composite_tiled</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>
          <span style="color:#6666ff; font-weight:bold;">Magick::ImageList</span>.<span style="color:#5A0A0A; font-weight:bold;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>attachment_options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:watermark_overlay</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#5A0A0A; font-weight:bold;">first</span>.<span style="color:#9900CC;">colorize</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0.4</span>, <span style="color:#006666;">0.4</span>, <span style="color:#006666;">0.4</span>, <span style="color:#996600;">'grey'</span><span style="color:#006600; font-weight:bold;">&#41;</span>,   <span style="color:#008000; font-style:italic;"># process and colorize image</span>
          <span style="color:#6666ff; font-weight:bold;">Magick::SoftLightCompositeOp</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        img.<span style="color:#9900CC;">write</span> record.<span style="color:#9900CC;">full_filename</span>  <span style="color:#008000; font-style:italic;"># save image</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now every Thumbnail record will automatically have a watermarked large image.</p>
]]></content:encoded>
			<wfw:commentRss>http://self.d-struct.org/175/watermarking-images-with-imagemagick-and-attachment_fu/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOWTO: Remove Byte-order Mark with Ruby and Iconv</title>
		<link>http://self.d-struct.org/195/howto-remove-byte-order-mark-with-ruby-and-iconv</link>
		<comments>http://self.d-struct.org/195/howto-remove-byte-order-mark-with-ruby-and-iconv#comments</comments>
		<pubDate>Mon, 19 Oct 2009 20:24:32 +0000</pubDate>
		<dc:creator>Chris Gansen</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://self.d-struct.org/?p=195</guid>
		<description><![CDATA[I&#8217;m working on a small project that involves loading a UTF-16LE (16-bit Unicode, Little Endian) CSV file, converting it to UTF-8 (normal Unicode, as it may be) with iconv, then parsing the values with FasterCSV. Everything was working fine except for loading the first column of data by the column header value. For example, given [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a small project that involves loading a UTF-16LE (16-bit Unicode, Little Endian) CSV file, converting it to UTF-8 (normal Unicode, as it may be) with <a href="http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/index.html">iconv</a>, then parsing the values with FasterCSV. Everything was working fine except for loading the first column of data by the column header value. For example, given data:</p>
<table style="width: 75%; border:1px">
<tbody>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
<tr>
<td>Jimbo</td>
<td>Jones</td>
<td>jimbo.jones@example.com</td>
</tr>
</tbody>
</table>
<p>I could access column 2 (Last Name) as either <code>row.field("Last Name")</code> or <code>row.field(1)</code>. However, if I tried to access the first column using <code>row.field("First Name")</code>, it would return <code>nil</code>. <code>row.field(0)</code>, on the other hand, would return the proper value.</p>
<p>Hmmmm.</p>
<p>After some sleuthing, I examined the raw content of the string:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#40;</span>rdb:<span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#CC0066; font-weight:bold;">p</span> row.<span style="color:#9900CC;">headers</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">unpack</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'C*'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">239</span>, <span style="color:#006666;">187</span>, <span style="color:#006666;">191</span>, <span style="color:#006666;">70</span>, <span style="color:#006666;">105</span>, <span style="color:#006666;">114</span>, <span style="color:#006666;">115</span>, <span style="color:#006666;">116</span>, <span style="color:#006666;">32</span>, <span style="color:#006666;">78</span>, <span style="color:#006666;">97</span>, <span style="color:#006666;">109</span>, <span style="color:#006666;">101</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>Ah, ha! The first three characters are the <a href="http://en.wikipedia.org/wiki/Byte-order_mark">byte-order mark, or BOM</a>. Ruby, for whatever reason, does not strip it when reading a file as input, so it&#8217;s passed along in the input stream. When loading a file with <a href="http://fastercsv.rubyforge.org">FasterCSV</a>, it&#8217;ll keep those characters in the key name, causing lookups by the first column key name to return nil.</p>
<p>I modified my file conversion code as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> convert_to_utf8
    <span style="color:#008000; font-style:italic;"># Data files are exported as Little Endian UTF-16. We need to parse as UTF-8</span>
    contents = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>@file_name<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">read</span>      
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      converted = <span style="color:#CC00FF; font-weight:bold;">Iconv</span>.<span style="color:#9900CC;">iconv</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'UTF-8'</span>, <span style="color:#996600;">'UTF-16LE'</span>, contents<span style="color:#006600; font-weight:bold;">&#41;</span>
      converted.<span style="color:#9900CC;">first</span>.<span style="color:#CC0066; font-weight:bold;">gsub!</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\x</span>EF<span style="color:#000099;">\x</span>BB<span style="color:#000099;">\x</span>BF&quot;</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># strip the BOM (byte order mark) from the first line of input</span>
      output = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>@file_name, <span style="color:#996600;">'w'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      output.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>converted<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">Iconv::Failure</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> $!.<span style="color:#9900CC;">inspect</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And all is well in the world.</p>
]]></content:encoded>
			<wfw:commentRss>http://self.d-struct.org/195/howto-remove-byte-order-mark-with-ruby-and-iconv/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>rsync</title>
		<link>http://self.d-struct.org/169/rsync</link>
		<comments>http://self.d-struct.org/169/rsync#comments</comments>
		<pubDate>Thu, 13 Aug 2009 20:08:45 +0000</pubDate>
		<dc:creator>Chris Gansen</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[rsync]]></category>

		<guid isPermaLink="false">http://self.d-struct.org/?p=169</guid>
		<description><![CDATA[Note that doubling a single-quote inside a single-quoted string gives you a single-quote; likewise for double-quotes (though you need to pay attention to which quotes your shell is parsing and which quotes rsync is parsing). &#8211; rsync man page Ow, my head hurts.]]></description>
			<content:encoded><![CDATA[<blockquote><p><em>Note that doubling a single-quote inside a single-quoted string gives you a single-quote; likewise for double-quotes (though you need to pay attention to which quotes your shell is parsing and which quotes rsync is parsing).</em></p>
<p>&#8211; <a href="http://www.samba.org/ftp/rsync/rsync.html">rsync man page</a></p></blockquote>
<p>Ow, my head hurts.</p>
]]></content:encoded>
			<wfw:commentRss>http://self.d-struct.org/169/rsync/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Directory tree</title>
		<link>http://self.d-struct.org/161/directory-tree</link>
		<comments>http://self.d-struct.org/161/directory-tree#comments</comments>
		<pubDate>Mon, 10 Aug 2009 23:42:13 +0000</pubDate>
		<dc:creator>Chris Gansen</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://self.d-struct.org/?p=161</guid>
		<description><![CDATA[A handy Bash script to display a tree view of a directory, adapted from http://www.centerkey.com/tree. This version omits .svn and .git directories, and uses the find utility. echo if &#91; &#34;$1&#34; != &#34;&#34; &#93; #if parameter exists, use as base folder then cd &#34;$1&#34; fi pwd find . \! \&#40; -path &#34;*.svn*&#34; -or -path &#34;*.git*&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>A handy Bash script to display a tree view of a directory, adapted from <a href="http://www.centerkey.com/tree">http://www.centerkey.com/tree</a>. This version omits .svn and .git directories, and uses the find utility.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>  <span style="color: #666666; font-style: italic;">#if parameter exists, use as base folder</span>
   <span style="color: #000000; font-weight: bold;">then</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #ff0000;">&quot;$1&quot;</span>
   <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">pwd</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> . \<span style="color: #000000; font-weight: bold;">!</span> \<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #660033;">-path</span> <span style="color: #ff0000;">&quot;*.svn*&quot;</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-path</span> <span style="color: #ff0000;">&quot;*.git*&quot;</span> \<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #660033;">-type</span> d <span style="color: #000000; font-weight: bold;">|</span> \
   <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/:$//'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/[^-][^\/]*\//--/g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^/   /'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/-/|/'</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-F</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;/&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #000000; font-weight: bold;">`</span> = <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
   <span style="color: #000000; font-weight: bold;">then</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;   -&amp;gt; no sub-directories&quot;</span>
   <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #7a0874; font-weight: bold;">exit</span></pre></div></div>

<p>Example use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>cgansen<span style="color: #000000; font-weight: bold;">@</span>Crystal-Frontier ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">tree</span> projects<span style="color: #000000; font-weight: bold;">/</span>self.d-struct.org<span style="color: #000000; font-weight: bold;">/</span>wp-admin<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>cgansen<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>self.d-struct.org<span style="color: #000000; font-weight: bold;">/</span>wp-admin
   .
   <span style="color: #000000; font-weight: bold;">|</span>-css
   <span style="color: #000000; font-weight: bold;">|</span>-images
   <span style="color: #000000; font-weight: bold;">|</span>-import
   <span style="color: #000000; font-weight: bold;">|</span>-includes
   <span style="color: #000000; font-weight: bold;">|</span>-js
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>cgansen<span style="color: #000000; font-weight: bold;">@</span>Crystal-Frontier ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://self.d-struct.org/161/directory-tree/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jobs4Recovery 2.0</title>
		<link>http://self.d-struct.org/130/jobs4recovery-2-0</link>
		<comments>http://self.d-struct.org/130/jobs4recovery-2-0#comments</comments>
		<pubDate>Mon, 04 May 2009 14:11:39 +0000</pubDate>
		<dc:creator>Chris Gansen</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[j4r]]></category>

		<guid isPermaLink="false">http://self.d-struct.org/?p=130</guid>
		<description><![CDATA[I&#8217;m pleased to announce the relaunch of Jobs4Recovery.com. I programmed the first version of this site in September 2005, in the aftermath of the Katrina-Rita one-two hurricane punch. After the initial wave of activity, the site fell by the wayside. The US Chamber of Commerce, in partnership with IBM, is ressurecting the site to deal [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jobs4recovery.com/" target="_blank"><img class="aligncenter size-full wp-image-131" title="j4r-logo" src="http://self.d-struct.org/wp-content/uploads/2009/05/j4r-logo.png" alt="j4r-logo" width="237" height="39" /></a></p>
<p>I&#8217;m pleased to announce the relaunch of <a href="http://jobs4recovery.com/" target="_blank">Jobs4Recovery.com</a>. I programmed the first version of this site in September 2005, in the aftermath of the Katrina-Rita one-two hurricane punch. After the initial wave of activity, the site fell by the wayside. The <a href="http://www.uschamber.com/">US Chamber of Commerce</a>, in partnership with IBM, is ressurecting the site to deal with both economic events and natural disasters. Over the past few weeks I&#8217;ve worked on upgrading and refreshing the site. I&#8217;m pleased with how it turned out, and I hope it&#8217;ll help folks when they need it the most.</p>
<p>On a technical note, sometimes it&#8217;s fun to switch your whole working environment for a while. I&#8217;ve been hacking Ruby on Rails for the past few years, but went back to PHP for this project. While I&#8217;ve fallen in love with the Ruby language and the Rails framework, the <a href="http://www.loudthinking.com/posts/23-the-immediacy-of-php">immediacy of PHP</a> is refreshing. To upgrade this site, almost all of the effort was in modifying the Javascript calls to reflect changes in the Google Maps API, or tweaking layout issues in Internet Explorer. The same core PHP code from 3.5 years ago worked flawlessly, without changing a single line.</p>
]]></content:encoded>
			<wfw:commentRss>http://self.d-struct.org/130/jobs4recovery-2-0/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>African Adventure</title>
		<link>http://self.d-struct.org/14/african-adventure</link>
		<comments>http://self.d-struct.org/14/african-adventure#comments</comments>
		<pubDate>Sat, 28 Feb 2009 07:11:44 +0000</pubDate>
		<dc:creator>Chris Gansen</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[csc]]></category>
		<category><![CDATA[tanzania]]></category>

		<guid isPermaLink="false">http://self.d-struct.org/?p=14</guid>
		<description><![CDATA[I&#8217;m heading to Africa in a few days as a part of the IBM Corporate Service Corps. Despite the mildly awkward name, it&#8217;s a rather interesting program. IBM is sending 600 of its best and brightest to work with NGO in emerging markets. It&#8217;s a mish-mash of corporate citizenship, good public relations, philanthropy, and advance [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_30" class="wp-caption alignright" style="width: 214px"><img class="size-full wp-image-30" title="tz-flag" src="http://self.d-struct.org/wp-content/uploads/2009/02/tz-flag.png" alt="tz-flag" width="204" height="139" /><p class="wp-caption-text">Flag of Tanzania</p></div>
<p>I&#8217;m heading to Africa in a few days as a part of the <a href="http://www.ibm.com/corporateservicecorps">IBM Corporate Service Corps</a>. Despite the mildly awkward name, it&#8217;s a rather interesting program. IBM is sending 600 of its best and brightest to work with NGO in emerging markets. It&#8217;s a mish-mash of corporate citizenship, good public relations, philanthropy, and advance market research. I&#8217;m joining 8 other IBMers from around the globe &#8212; the Philippines, India, Brazil, Great Britain, Italy, Japan, and the United States &#8212; to work for one month with three organizations in <a href="http://en.wikipedia.org/wiki/Arusha">Arusha, Tanzania</a>. We have never worked together as a team before, let alone ever met in person. We&#8217;re all hail from various backgrounds which run the gamut from technical skills to sales to marketing to management. Some of us don&#8217;t speak English very well, and none of us speak any Swahili.</p>
<p>I learned just a few days ago that I&#8217;ll be working with the <a href="http://www.iaa.ac.tz/08/">Institute of Accountancy Arusha (IAA)</a>. They offer various undergradute and postgraduate programs in business, accounting, and information technology. I&#8217;ll be working with them to assess their current infrastructure, plan upgrades, and various other IT-related tasks. Other team members are working with the <a href="http://www.awf.org/">African Wildlife Foundation</a> and the <a href="http://www.tatotz.org/">Tanzanian Association of Tour Operators</a> on projects ranging from AIDS outreach to marketing to business planning. We&#8217;re not the only IBM team that has been to Tanzania. Two teams visited in 2008 to work with TATO and AWF. They accomplished a lot, including creating the current TATO web site, numerous business plans, and lots of consulting work. A fourth team is leaving in a month to go work in the capital of Tanzania, Dodoma.</p>
<p>Overall, I am quite excited for this. It is certainly the most interesting task I&#8217;ve taken on in my short tenure with IBM, and I have no doubts that it will be the most challenging. It&#8217;s a bit intimidating going into a new country, culture, and pace fo life. Things I take for granted here like instant, always-available Internet access, are simply not available there. What will I ever do with out Google? But that&#8217;s all part of the experience, and I look forward to it. I am also quite eager to join this new team. Just from the few weeks of conference calls and uncountable email chains, they have demonstarated a great level of capability and profressionalism.</p>
]]></content:encoded>
			<wfw:commentRss>http://self.d-struct.org/14/african-adventure/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

