<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>mwcz</title>
    <link>http://mwcz.org</link>
    <description>I finally created a blog.</description>
    <pubDate>Mon, 13 Feb 2012 04:42:26 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>ColorPal palettes improved!</title>
      <link>http://mwcz.org/2012/02/10/colorpal-palettes-improved!</link>
      <pubDate>Fri, 10 Feb 2012 22:44:50 EST</pubDate>
      <category><![CDATA[color]]></category>
      <category><![CDATA[javascript]]></category>
      <category><![CDATA[html5]]></category>
      <guid>b'oJHLN3K51SbbtoLgDiDfCafURCk='</guid>
      <description>ColorPal palettes improved!</description>
      <content:encoded><![CDATA[<p><a href="/projects/colorpal"><img src="/img/019/colorpal_logo.png" alt="ColorPal logo" title=""
style="float:right" /></a></p>
<p>In my <a href="/2012/01/16/colorpal-alpha/">last post</a> on the subject, I introduced
ColorPal, my HTML5 color palette generation tool.  It didn't perform well with
certain types of images, so I fixed it. :)</p>
<p>Color palettes will now match the image even better.  Especially for images
with infrequent but <em>important</em> colors.  Here's a comparison of the old and new
methods, on an image that is mostly black:</p>
<p><img alt="comparison of palettes generated with median and
mean" src="/img/019/median-mean-comparison.png" /></p>
<p>You can see that with the old method, the black pixels definitely took over the
palette.</p>
<p><a href="/projects/colorpal">Try it with your own images!</a></p>
<p>For some images, this change won't affect palettes at all.  But for images with
low-population, high-importance colors, like the one above, palettes will look
<em>much</em> better!</p>
<p>Technical discussion below.</p>
<h1>Why the 'median' in median-cut?</h1>
<p>Median Cut is an algorithm typically used to reduce the number of colors in an
image.</p>
<p><img alt="16 million colors versus 16 colors" src="/img/019/median-cut-example.png" /></p>
<p>The steps to perform median cut are fairly straightforward:</p>
<div class="pygments_murphy syntax_highlight"><pre>  <span class="mi">1</span><span class="p">.</span> <span class="nx">Find</span> <span class="nx">the</span> <span class="nx">smallest</span> <span class="nx">box</span> <span class="nx">which</span> <span class="nx">contains</span> <span class="nx">all</span> <span class="nx">the</span> <span class="nx">colors</span><span class="p">.</span><br/>  <br/>  <span class="mi">2</span><span class="p">.</span> <span class="nx">Sort</span> <span class="nx">the</span> <span class="nx">enclosed</span> <span class="nx">colors</span> <span class="nx">along</span> <span class="nx">the</span> <span class="nx">longest</span> <span class="nx">axis</span> <span class="nx">of</span> <span class="nx">the</span> <span class="nx">box</span><span class="p">.</span><br/>  <br/>  <span class="mi">3</span><span class="p">.</span> <span class="nx">Split</span> <span class="nx">the</span> <span class="nx">box</span> <span class="nx">into</span> <span class="nx">two</span> <span class="nx">regions</span> <span class="nx">at</span> <span class="nx">median</span> <span class="nx">of</span> <span class="nx">the</span> <span class="nx">sorted</span> <span class="nx">list</span><span class="p">.</span><br/>  <br/>  <span class="mi">4</span><span class="p">.</span> <span class="nx">Repeat</span> <span class="nx">the</span> <span class="nx">above</span> <span class="nx">process</span> <span class="nx">until</span> <span class="nx">the</span> <span class="nx">original</span> <span class="nx">color</span> <span class="nx">space</span> <span class="nx">has</span> <span class="nx">been</span> <span class="nx">divided</span><br/>     <span class="nx">into</span> <span class="nx">N</span> <span class="nx">regions</span> <span class="nx">where</span> <span class="nx">N</span> <span class="nx">is</span> <span class="nx">the</span> <span class="nx">number</span> <span class="nx">of</span> <span class="nx">colors</span> <span class="nx">you</span> <span class="nx">want</span><span class="p">.</span><br/></pre></div>

<p>Not too bad, right?  The question remains, though, why median?</p>
<p>Mean, median, and mode all attempt to measure the
<a href="http://en.wikipedia.org/wiki/Location_parameter">location</a> of a probability
distribution.  Worded more intuitively... they try to find the center of a set
of numbers.  They just employ different definitions of "center".</p>
<p><img alt="mean, median, and mode graphed" src="/img/019/mean_median_mode.png" />
(Thanks <a href="http://en.wikipedia.org/wiki/Median">Wikipedia</a>)</p>
<p>As you can see clearly in the dashed data set, the mean tends to follow the
tail.  In other words, mean is useful when outliers are important.  When
generating a color palette, outliers are essential.  Outliers may be the small
streak of color in an otherwise drab sky, or a small red rose in the middle of
a green field.</p>
<p>The goal of median cut is <em>not</em> to generate a color palette.  It's to
efficiently reduce the number of colors in an image.  Since my goal with
ColorPal is to find good-lookin' colors, I've modified the algorithm to split
boxes at the <strong>mean</strong> instead of the <strong>median</strong>.  Mean splits boxes closer to
the outliers, which keeps low-population colors nicely segregated from the
high-population colors.</p>
<p>Thus step 3 becomes:</p>
<div class="pygments_murphy syntax_highlight">
  3. Split the box into two regions at the <b>mean</b> of the sorted list.
</div>

<p>The result?  Mean Cut!  Also: awesome color palettes.</p>
<h2>Interesting side-note on color distributions</h2>
<p>Interestingly, photographs of nature tend to have nice, close-to-normal color
distributions.  A "normal distribution" is a formal term for a "bell curve".</p>
<p>Check out the red, green, and blue distributions for a photograph of a forest.</p>
<p><img alt="Forest red   pixel distribution" src="/img/019/forest_r.png" />
<img alt="Forest green pixel distribution" src="/img/019/forest_g.png" />
<img alt="Forest blue  pixel distribution" src="/img/019/forest_b.png" /></p>
<p>For comparison, here are the distributions for a shot of NYC.</p>
<p><img alt="City   red   pixel distribution" src="/img/019/city_r.png" />
<img alt="City   green pixel distribution" src="/img/019/city_g.png" />
<img alt="City   blue  pixel distribution" src="/img/019/city_b.png" /></p>
<h2>What's next for ColorPal?  Color spaces.</h2>
<p>Mean-cut improves ColorPal dramatically for some images, but it's still not
perfect.  Perfection probably won't be attainable, but there are still many
ways to improve.</p>
<p>My next test will be converting to a color space other than RGB.</p>
<p>HSL is common, and the RGB/HSL conversion formulas are in my very old JSImage
project.  It may not turn out well, though, as the concept of "widest box"
loses most of its meaning when each axis is a completely different unit of
measure.  Although, in a way, I suppose RGB has a similar problem.  Red, Green,
and Blue could be thought of as unrelated units.  I'll try it out and see how
it goes.  I wonder if my old JavaScript RGB/HSL code has rotted away yet...</p>
<p>Most likely, I'll skip HSL and try one of the
<a href="http://en.wikipedia.org/wiki/Lab_color_space">Lab</a> color spaces first, since
they are not composed linear values like RGB and HSL.  Instead, Lab color
spaces use non-linear scales that closely match human perception of color.
Perfect for my purposes.  How fortuitious for me that CIE invented it way back
in 1931.</p>
<p>There are three "Lab" color spaces: XYZ, Hunter-Lab,
and CIELAB.  XYZ will be first to the plate, since the RGB/XYZ formulas are
the simplest.  Let me take this opportune moment to plug
<a href="http://www.easyrgb.com/index.php?X=MATH">EasyRGB.com</a>.</p>
<h2>Lend a hand</h2>
<p>As I've mentioned before, ColorPal is in an early stage of development.  It
needs testing in multiple browsers, and I'm very interested in hearing people's
feedback.  Code development help is welcomed too.</p>
<p>If you try out ColorPal, shoot me an <a href="mailto:mwc@clayto.org">email</a>
or give me a shout on <a href="https://twitter.com/#!/mwcz">Twitter</a> with your
thoughts.  Thanks!</p>
<p>Here are github repos for <a href="https://github.com/mwcz/ColorPal">ColorPal</a> and
<a href="https://github.com/mwcz/median-cut-js">median-cut.js</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>Toy javascript unit tester</title>
      <link>http://mwcz.org/2012/01/30/toy-javascript-unit-tester</link>
      <pubDate>Mon, 30 Jan 2012 21:50:00 EST</pubDate>
      <category><![CDATA[javascript]]></category>
      <category><![CDATA[testing]]></category>
      <guid>b'JwjZs5NqO7otncYUL432iLrBdFI='</guid>
      <description>Toy javascript unit tester</description>
      <content:encoded><![CDATA[<p>Last week I was sitting in a meeting, thinking about unit testing frameworks (not the subject of the meeting), and had a minor epiphany.  In the back of my mind, there has always been a bit of uncertainty as to how unit testing frameworks work.  Deep in my brain I knew there was something I didn't understand, but I wasn't quite sure what.  I never gave it any conscious thought.</p>
<p>As a developer, I'd use a framework, write a bunch of <code>testBlahFoo</code> functions, and the framework would magically run them.<br />
</p>
<p>Then I realized... "Oh, it's just introspection."</p>
<div class="pygments_murphy syntax_highlight"><pre><span class="c1">// Create an object with three properties, all functions</span><br/><span class="kd">var</span> <span class="nx">myfuncs</span> <span class="o">=</span> <span class="p">{</span><br/>    <span class="nx">func1</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;func it up&quot;</span><span class="p">);</span> <span class="p">},</span><br/>    <span class="nx">func2</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;func&#39;s old brother&quot;</span><span class="p">);</span> <span class="p">},</span><br/>    <span class="nx">func3</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;bring back da func&quot;</span><span class="p">);</span> <span class="p">}</span><br/><span class="p">};</span><br/><br/><span class="c1">// Run all functions attached to myfuncs</span><br/><span class="k">for</span><span class="p">(</span> <span class="nx">func</span> <span class="k">in</span> <span class="nx">myfuncs</span> <span class="p">)</span> <span class="p">{</span><br/>    <span class="nx">myfuncs</span><span class="p">[</span> <span class="nx">func</span> <span class="p">]();</span><br/><span class="p">}</span><br/><br/><span class="c1">// Outputs:</span><br/><span class="c1">// </span><br/><span class="c1">// func it up</span><br/><span class="c1">// func&#39;s old brother</span><br/><span class="c1">// bring back da func</span><br/></pre></div>

<p>So simple.  Later, I wrote a very basic unit testing framework, purely as an educational excercise.</p>
<p>The guts are almost simple as the example above.</p>
<div class="pygments_murphy syntax_highlight"><pre><span class="kd">var</span> <span class="nx">JTestSuite</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>                                                                                                                                                                         <br/><br/>    <span class="kd">var</span> <span class="nx">version</span> <span class="o">=</span> <span class="mf">0.1</span><span class="p">,</span><br/>        <span class="nx">jt</span><span class="p">,</span><br/><br/>    <span class="nx">init</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span> <span class="nx">callback</span> <span class="p">)</span> <span class="p">{</span><br/>        <span class="nx">jt</span> <span class="o">=</span> <span class="nx">JTests</span><span class="p">();</span><br/>        <span class="nx">jt</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span> <span class="nx">callback</span> <span class="p">);</span><br/>    <span class="p">},</span><br/><br/>    <span class="nx">run</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span><br/>        <span class="kd">var</span> <span class="nx">fn</span><span class="p">,</span><br/>            <span class="nx">prop</span><span class="p">;</span><br/><br/>        <span class="c1">// Run all functions that begin with &quot;test&quot;</span><br/>        <span class="k">for</span><span class="p">(</span> <span class="nx">prop</span> <span class="k">in</span> <span class="k">this</span> <span class="p">)</span> <span class="p">{</span><br/>            <span class="k">if</span><span class="p">(</span> <span class="k">typeof</span> <span class="k">this</span><span class="p">[</span><span class="nx">prop</span><span class="p">]</span> <span class="o">===</span> <span class="s2">&quot;function&quot;</span> <span class="p">)</span> <span class="p">{</span><br/>                <span class="k">if</span><span class="p">(</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">4</span><span class="p">)</span> <span class="o">===</span> <span class="s2">&quot;test&quot;</span> <span class="p">)</span> <span class="p">{</span><br/>                    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span> <span class="k">this</span><span class="p">[</span><span class="nx">prop</span><span class="p">](</span><span class="nx">jt</span><span class="p">)</span> <span class="p">);</span><br/>                <span class="p">}</span><br/>            <span class="p">}</span><br/>        <span class="p">}</span><br/>    <span class="p">};</span><br/><br/>    <span class="k">if</span><span class="p">(</span> <span class="o">!</span><span class="p">(</span><span class="k">this</span> <span class="k">instanceof</span> <span class="nx">JTestSuite</span><span class="p">)</span> <span class="p">)</span> <span class="k">return</span> <span class="k">new</span> <span class="nx">JTestSuite</span><span class="p">();</span><br/><br/>    <span class="k">return</span> <span class="p">{</span><br/>        <span class="nx">init</span> <span class="o">:</span> <span class="nx">init</span><span class="p">,</span><br/>        <span class="nx">run</span>  <span class="o">:</span> <span class="nx">run</span><br/>    <span class="p">};</span><br/><br/><span class="p">};</span><br/></pre></div>

<p>In the <code>run</code> function's loop, I first check that each property is a function before attemping to run it.  This avoids a <code>called_non_callable TypeError</code>.  I then check that the name of the property begins with the string "test".  When dynamically calling functions, it's usually a good idea to call <code>obj.hasOwnProperty(propname)</code> to ensure the property wasn't inherited from some unknown source (especially if the property you wanted to reference may have been <code>delete</code>d, but a property with the same name is now surfacing from a parent object), but in this case I'd like to leave open the possibility for inherited Test Suites.</p>
<p>The <code>JTests</code> object created in the <code>init</code> function is a separate object that contains a bunch of assertions.  It looks something like this:</p>
<div class="pygments_murphy syntax_highlight"><pre><span class="kd">var</span> <span class="nx">JTests</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span><br/><br/>    <span class="kd">var</span> <span class="nx">version</span> <span class="o">=</span> <span class="mf">0.1</span><span class="p">,</span><br/>        <span class="nx">result_callback</span><span class="p">,</span><br/><br/>    <span class="nx">init</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span> <span class="nx">callback</span> <span class="p">)</span> <span class="p">{</span><br/>        <span class="nx">result_callback</span> <span class="o">=</span> <span class="nx">callback</span><span class="p">;</span><br/>    <span class="p">}</span><br/><br/>    <span class="nx">assertTrue</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span> <span class="nx">a</span> <span class="p">)</span> <span class="p">{</span><br/>        <span class="kd">var</span> <span class="nx">result</span> <span class="o">=</span> <span class="nx">a</span> <span class="o">===</span> <span class="kc">false</span><span class="p">;</span><br/>        <span class="nx">result_callback</span><span class="p">(</span> <span class="p">{</span>                                                                                                                                                                         <br/>            <span class="nx">name</span>   <span class="o">:</span> <span class="s2">&quot;assertTrue&quot;</span><span class="p">,</span><br/>            <span class="nx">args</span>   <span class="o">:</span> <span class="p">[</span> <span class="nx">a</span> <span class="p">],</span><br/>            <span class="nx">result</span> <span class="o">:</span> <span class="nx">result</span><br/>        <span class="p">}</span> <span class="p">);</span><br/>    <span class="p">};</span><br/>    <br/>    <span class="k">return</span> <span class="p">{</span><br/>        <span class="nx">assertTrue</span> <span class="o">:</span> <span class="nx">assertTrue</span><br/>    <span class="p">};</span><br/><br/><span class="p">};</span><br/></pre></div>

<p>...except with many more assertions. :)</p>
<p>Both <code>JTestSuite</code> and <code>JTests</code> use the <a href="http://stackoverflow.com/a/5647397/215148">revealing module pattern</a>. </p>
<p>I have a lot of ideas for improvement, like <a href="http://en.wikipedia.org/wiki/Don&apos;t_repeat_yourself">DRY</a>ing up the assertions, so the <code>{name,args,result}</code> object doesn't have to be defined in each assertion.  But <a href="http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript">many others</a> have already done a great job, and I don't want to reinvent too many wheels.</p>
<div class="pygments_murphy syntax_highlight"><pre><span class="c1">// Define a custom handler for the result</span><br/><span class="kd">function</span> <span class="nx">test_callback</span><span class="p">(</span> <span class="nx">result</span> <span class="p">)</span> <span class="p">{</span><br/>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">result</span><span class="p">);</span><br/><span class="p">}</span><br/><br/><span class="c1">// Create a new JTestSuite object and initialize it with the callback</span><br/><span class="kd">var</span> <span class="nx">TestSuite</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">JTestSuite</span><span class="p">();</span><br/><span class="nx">TestSuite</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span> <span class="nx">test_callback</span> <span class="p">);</span><br/><br/><span class="c1">// Create some tests</span><br/><span class="nx">TestSuite</span><span class="p">.</span><span class="nx">testMath</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">jt</span><span class="p">)</span> <span class="p">{</span><br/>    <span class="nx">jt</span><span class="p">.</span><span class="nx">assertEquals</span><span class="p">(</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span> <span class="p">);</span><br/><span class="p">};</span><br/><br/><span class="nx">TestSuite</span><span class="p">.</span><span class="nx">testFalsy</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">jt</span><span class="p">)</span> <span class="p">{</span><br/>    <span class="c1">// [], &quot;&quot;, and &quot;0&quot; all == false in javascript</span><br/>    <span class="nx">jt</span><span class="p">.</span><span class="nx">assertFalsy</span><span class="p">(</span> <span class="p">[]</span> <span class="p">);</span><br/>    <span class="nx">jt</span><span class="p">.</span><span class="nx">assertFalsy</span><span class="p">(</span> <span class="s2">&quot;&quot;</span> <span class="p">);</span><br/>    <span class="nx">jt</span><span class="p">.</span><span class="nx">assertFalsy</span><span class="p">(</span> <span class="s2">&quot;0&quot;</span> <span class="p">);</span><br/><span class="p">};</span><br/><br/><span class="c1">// Run all the tests</span><br/><span class="nx">TestSuite</span><span class="p">.</span><span class="nx">run</span><span class="p">();</span><br/></pre></div>

<p>The callback allows a user to determine how the results from the unit test should be processed or displayed.  Results could be printed to console.log, displayed on a page by adding them to the DOM, sent to a Web service with AJAX, or any arbitrary service with Web Sockets.</p>
<p>After writing this toy framework, and explaining it to a colleague, I was told that the Rails unit tester uses almost the exact same approach.  I'd wager a few bucks that JUnit uses the Reflection API's <code>Class.getMethods()</code> to find and run all the methods added to a TestCase class.  Only a few bucks, though.</p>]]></content:encoded>
    </item>
    <item>
      <title>ColorPal Alpha</title>
      <link>http://mwcz.org/2012/01/16/colorpal-alpha</link>
      <pubDate>Mon, 16 Jan 2012 22:15:50 EST</pubDate>
      <category><![CDATA[color]]></category>
      <category><![CDATA[javascript]]></category>
      <category><![CDATA[html5]]></category>
      <guid>b'yjHyVy_AvOOJ3jMuXx8IXMnMgH4='</guid>
      <description>ColorPal Alpha</description>
      <content:encoded><![CDATA[<p>Introducing ColorPal!</p>
<p><img alt="ColorPal screenshot" src="/img/015/ss.png" /></p>
<p>I've been toying with color palette generation for years.  My photography website has always had some form of dynamic palette, so the theme of each page matches the photo.  You can see the current iteration <a href="http://clayto.com/">here</a>:</p>
<p><img src="/img/015/tarsi.png" alt="clayto.com" title="My photo, 'Tarsi', at clayto.com" /></p>

<p>I owe the idea of photo-matching website palettes to <a href="http://noahgrey.com">Noah Grey</a>.  Each iteration of my photo site has gotten a slightly more advanced palette generation tool.  You can see murmurs of them in the <a href="http://localhost:8080/2011/11/16/html5-canvas-eyedropper/">old</a> <a href="http://localhost:8080/2011/11/16/html5-canvas-area-selection-averaging/">canvas</a> <a href="http://localhost:8080/2011/11/17/html5-tool-for-creating-color-palettes-from-an-image/">demos</a> I've posted.  Sooner or later I'll make a more thorough post about the tools I've created for each iteration of the site.  Anyway, back to ColorPal.</p>
<p>ColorPal is an HTML5 palette generation tool.  Currently it's in a very early stage, and I've only tested it in Chrome.  I have many ideas for improvements, and I'd love to hear anyone's ideas as well.<br />
</p>
<p><img src="/img/015/colorpal_logo.png" alt="ColorPal logo" title="" style="float: right; margin: 8px" /></p>

<p>It's powered by <a href="http://en.wikipedia.org/wiki/Canvas_element">canvas</a>, <a href="https://developer.mozilla.org/en/data_URIs">data URIs</a>, <a href="http://dev.w3.org/2006/webapi/FileAPI/">File API</a>, and my homespun <a href="http://en.wikipedia.org/wiki/Median_cut">median-cut</a> implementation, which I'm calling <em>median-cut.js</em>.</p>
<p>Bear in mind that while I've kept median-cut.js nice and clean, I did hammer out ColorPal as quickly as possible, so it's a mess.  Why?  I expect median-cut.js to be useful to other programmers, but ColorPal is just a tool for designers.  Or it will be, anyway. :)</p>
<p>Here are github repos for <a href="https://github.com/mwcz/ColorPal">ColorPal</a> and <a href="https://github.com/mwcz/median-cut-js">median-cut.js</a>.</p>
<p>And, as a reward for reading to the end, a <a href="/projects/colorpal/">live demo</a>!</p>]]></content:encoded>
    </item>
    <item>
      <title>The N9, QR-Codes, and KeePassX</title>
      <link>http://mwcz.org/2012/01/08/the-n9,-qr-codes,-and-keepassx</link>
      <pubDate>Sun, 08 Jan 2012 22:27:50 EST</pubDate>
      <category><![CDATA[n9]]></category>
      <category><![CDATA[keepass]]></category>
      <category><![CDATA[general]]></category>
      <guid>b'av6euvqkN_75DCjB7lp8jqUPiDw='</guid>
      <description>The N9, QR-Codes, and KeePassX</description>
      <content:encoded><![CDATA[<p><em>Update: I happened across a <a href="http://keepass.info/plugins.html#qrcodegen">KeePass
plugin</a> (not the same as KeePassX)
that displays passwords as QR codes, just like my hack below.</em></p>
<p>Poor, glorious N9.</p>
<p>It's impossible not to love the N9 if you're a geek, especially a programming,
bash-loving, Linux-hankering geek.  It's like a nerd talisman.  This post isn't
about the N9, specifically, so I'll save the love-fest for another time.</p>
<p>This post is about how difficult it can be to get text (especially passwords)
onto a smartphone securely.  I've come to like the approach of using QR codes.
Most (all?) smartphones have a barcode scanner, and QR codes are one of <a href="http://en.wikipedia.org/wiki/Barcode">many
convenient ways</a> to encode text into an
image.  In the case of the N9, it's
<a href="http://store.ovi.com/content/231518">MeeScan</a>.</p>
<p><img alt="meescan" src="/img/011/meescan.png" /></p>
<p><a href="http://fukuchi.org/works/qrencode/index.html.en">qrencode</a> is an extremely
easy to use encoder.  Pass it a string, it produces an image.</p>
<pre><code>qrencode "mypassword" -o mypass.png
</code></pre>
<p><a href="http://keepassx.org">KeePassX</a> is an excellent password manager.
Unfortunately...</p>
<p><img alt="KeePassX not in N9" src="/img/011/keepass_not_in_n9.png" /></p>
<p>Sadly, there is no KeePassX client on the N9.  At least, not yet.  Even if
there were, I'm skeptical that it's a good idea at all to be carrying around a
database of personal passwords on a smartphone.  It's encrypted, sure, but
touchscreen keyboards encourage weak passphrases.  Who wants to enter a 64+
character passphrase on a <abbr title="Virtual keyboard">vkbd</abbr>?</p>
<p>This evening, I spent about an hour hacking QR-code support into KeePassX.
It's a seriously messy hack, using
<a href="http://en.cppreference.com/w/cpp/utility/program/system">system()</a> to call
<code>qrencode</code>, pass in the password, then call
<a href="http://projects.gnome.org/evince/?guid=ON">evince</a> to view it.  Even worse, I
just tacked it onto the "Copy Password" function, instead of figuring out how
to create a new menu item.  It doesn't even delete the generated image after
viewing.  Definitely nothing more than a proof of concept.</p>
<p>Here it is in action.</p>
<p><a href="/img/011/keepassx_demo.png"><img class="grid_7"
src="/img/011/keepassx_demo.png" alt="KeePassX generating a QR code" title=""
/></a></p>

<div class="clear"></div>

<p>I won't be distributing my mod unless someone <em>really</em> wants it, but it would
be cool to see this available as plugin to any password managers that support
plugins.  It could be handy to have clipboard managers generate QR codes too.</p>]]></content:encoded>
    </item>
    <item>
      <title>HTML5 tool for creating color palettes from an image</title>
      <link>http://mwcz.org/2011/11/17/html5-tool-for-creating-color-palettes-from-an-image</link>
      <pubDate>Thu, 17 Nov 2011 22:25:00 EST</pubDate>
      <category><![CDATA[color]]></category>
      <category><![CDATA[colorpal]]></category>
      <category><![CDATA[canvas]]></category>
      <category><![CDATA[html5]]></category>
      <guid>b'eb0msgpTGJeEpYHR5R-z1pMSuUk='</guid>
      <description>HTML5 tool for creating color palettes from an image</description>
      <content:encoded><![CDATA[<p>For an <a href="http://en.wikipedia.org/wiki/Human%E2%80%93computer_interaction">HCI</a> class project in Fall 2009, I pulled together some of my previous demos to make this integrated tool.  It was just a prototype, and I haven't taken the time to get the code set up and working on this blog.  If anyone is interested, I can dig up the code and send it along.</p>
<iframe width="580" height="550" src="http://www.youtube.com/embed/p9QiGPUiXdc" frameborder="0" allowfullscreen></iframe>

<p>In retrospect, it really could have used some narration...</p>]]></content:encoded>
    </item>
    <item>
      <title>Bouncey returns - more canvas physics</title>
      <link>http://mwcz.org/2011/11/17/bouncey-returns---more-canvas-physics</link>
      <pubDate>Thu, 17 Nov 2011 22:25:00 EST</pubDate>
      <category><![CDATA[canvas]]></category>
      <category><![CDATA[javascript]]></category>
      <category><![CDATA[physics]]></category>
      <category><![CDATA[html5]]></category>
      <category><![CDATA[bouncey]]></category>
      <guid>b'2xt0h5v9PdQpOWIQqUDpRdUg6RE='</guid>
      <description>Bouncey returns - more canvas physics</description>
      <content:encoded><![CDATA[<p>This is a slightly upgraded version of the physics demo I showed in my <a href="/blog/2011/11/17/bouncey---canvas-physics/">last post</a>.</p>
<p>It is still...</p>
<p><quote>"a buggy, rudimentary, just-for-fun javascript physics simulator."</quote></p>
<p>This version has:</p>
<ul>
<li>pre-defined initial states</li>
<li>gravity</li>
<li>friction</li>
</ul>
<p>It still has the "clinging" bug.  I know how to fix it, but didn't deem it important enough to spend time on it. :)</p>
<p>The <a href="https://github.com/mwcz/bouncey/blob/master/bounce.html">code</a> is well commented, so feel free to hack on it.</p>
<p>Click on one of the initial states to begin the simulation.</p>
<style type="text/css">
#cnvs {
    margin: 0 auto;
    border: 1px solid black;
    -webkit-box-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.7 );
       -moz-box-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.7 );
         -o-box-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.7 );
            box-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.7 );
}
</style>

<script type="text/javascript" src="/js/008/bouncey.js"></script>

<p>Initial states:
<button onclick="RANDOM();">Random</button>
<button onclick="POOL();">POOL</button>
<button onclick="HEAD_ON_COLLISION();">HEAD_ON_COLLISION</button></p>
<p><canvas id="cnvs" width="500" height="375"> 
    Sorry, your browser does not support HTML5 canvas.  Lame.
</canvas> </p>
<p><button onclick="paused++;paused%=2;">Pause</button> </p>
<pre>
  velocity sum: <span id="txt_velocity_sum">NONE</span>
x velocity sum: <span id="txt_velocity_sum_x">NONE</span>
y velocity sum: <span id="txt_velocity_sum_y">NONE</span>
</pre>

<p>(The POOL initial state reproduces the clinging bug.)</p>]]></content:encoded>
    </item>
    <item>
      <title>Bouncey - canvas physics</title>
      <link>http://mwcz.org/2011/11/17/bouncey---canvas-physics</link>
      <pubDate>Thu, 17 Nov 2011 21:25:00 EST</pubDate>
      <category><![CDATA[canvas]]></category>
      <category><![CDATA[javascript]]></category>
      <category><![CDATA[physics]]></category>
      <category><![CDATA[html5]]></category>
      <category><![CDATA[bouncey]]></category>
      <guid>b'lme0L3L_sUuiXWqzNi0W4eTQuUQ='</guid>
      <description>Bouncey - canvas physics</description>
      <content:encoded><![CDATA[<p>This is Bouncey.  It's a simple physics demo I wrote in early/mid 2011, with some contributions and bugfixes from my good friend Greg Gardner.</p>
<p>The description for <a href="https://github.com/mwcz/bouncey">bouncey's github repo</a> is:</p>
<p><quote>"a buggy, rudimentary, just-for-fun javascript physics simulator."</quote></p>
<p>It covers <a href="http://en.wikipedia.org/wiki/Newton&apos;s_laws_of_motion">Newton's laws of motion</a>.</p>
<style type="text/css">
#cnvs {
    margin: 0 auto;
    border: 1px solid black;
    -webkit-box-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.7 );
       -moz-box-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.7 );
         -o-box-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.7 );
            box-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.7 );
}
</style>

<script type="text/javascript" src="/js/007/bouncey.js"></script>

<script type="text/javascript">

window.onload = function() {

canvas_element        = document.getElementById('cnvs');
    canvas_element.width  = W;
    canvas_element.height = H;

canvas = canvas_element.getContext('2d');

// create some squares with random velocities in the center of the canvas
    // objects are stored in the format 
    //      [ X, Y, X_velocity, Y_velocity, width, height, [R,G,B] ]
    var x, y, w, h, v_x, v_y, r, g, b, new_obj;

// calculate all the possible initial y positions
    y_positions = [];
    for( var i = OBJ_HEIGHT; i < H - OBJ_HEIGHT; i += 2 * OBJ_HEIGHT )
        y_positions.push( i );

// calculate all the possible initial x positions
    x_positions = [];
    for( var i = OBJ_WIDTH; i < W - OBJ_WIDTH; i += 2 * OBJ_WIDTH )
        x_positions.push( i );

/*
    */
    for( var i = 0; i < 40; ++i ) {

// create values for the object
        x   = x_positions[ i % x_positions.length ];
        y   = y_positions[ Math.floor( i / x_positions.length ) % y_positions.length ];
        v_x = Math.random() * OBJ_MAX_VELOCITY*2 - OBJ_MAX_VELOCITY;
        v_y = Math.random() * OBJ_MAX_VELOCITY*2 - OBJ_MAX_VELOCITY;
        r   = Math.floor( Math.random() * 200 + 55 ); // random value 55..255
        g   = Math.floor( Math.random() * 200 + 55 );
        b   = Math.floor( Math.random() * 200 + 55 );

// add the object to the scene
        var color = 'rgb(' + r + ',' + g + ',' + b + ')';
        var new_obj = new Circle( x, y, OBJ_R, v_x, v_y, color );

objs.push( new_obj );
    }

setInterval( make_frame, PERIOD );

}

</script>

<p><button onclick="paused++;paused%=2;">Pause</button> </p>
<p><canvas id="cnvs" width="500" height="375"> 
    Sorry, your browser does not support HTML5 canvas.  Lame.
</canvas> </p>]]></content:encoded>
    </item>
    <item>
      <title>How not to use CSS3</title>
      <link>http://mwcz.org/2011/11/17/how-not-to-use-css3</link>
      <pubDate>Thu, 17 Nov 2011 20:25:00 EST</pubDate>
      <category><![CDATA[css3]]></category>
      <category><![CDATA[html5]]></category>
      <category><![CDATA[typography]]></category>
      <guid>b'JBKP5FvAeqiopawktJcLqDN-QpM='</guid>
      <description>How not to use CSS3</description>
      <content:encoded><![CDATA[<p>How to ruin a good thing...</p>
<p>Try refreshing.</p>
<style type="text/css">

.css3_demo {
    font-family: FreeSansBold;
    text-align: center;
    color: #efefef;
    position: relative;
    top: 0;
    left: 50px;
    font-size: 9em;
    padding: 0;
}

@font-face { font-family: "FreeSansBold"; src: url("FreeSansBold.ttf"); }

</style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script type="text/javascript">

// Random factors to determine x/y offsets for text shadows and amount of blur
var x_factor    = Math.floor( Math.random() * 20 ) - 10;
var y_factor    = Math.floor( Math.random() * 20 ) - 10;
var blur_factor = Math.floor( Math.random() * 10 ) + 1;

// Pretty colors
var the_colors = 
                [
                '#7f9f7f',
                '#dca3a3',
                '#80d4aa',
                '#f8f893',
                '#ffcfaf',
                '#e89393',
                '#9ece9e',
                '#c0bed1',
                '#6c6c9c',
                '#71d3b4',
                '#a0afa0',
                '#efefef'
                ];

function make_it() { // MAKE IT SHINE
    // Build a string containing a comma-delimited list of the each shadow we want to apply
    // sprintf would be nice here.
    var shadows = "";
    for( var color_index in the_colors ) {
        shadows += 
            color_index * x_factor + "px " + 
            color_index * y_factor + "px " + 
            color_index * blur_factor + "px " + 
            the_colors[ color_index ];

// Add a comma unless we're at the end of the color set
        if( color_index != the_colors.length - 1 )
            shadows += ',';
    }
    $('.css3_demo').css( 'textShadow', shadows ); // apply the new style
    the_colors.push( the_colors.shift() ); // move first color to the end of the list
    //console.log( shadows );
    setTimeout( 'make_it()', 50 ); // make the function async (kinda... effectively...) with setTimeout()
}

function move_it() { // MAKE IT MOVE
    /* uncomment this to make it move up and down...
    $('.css3_demo').animate( {top:'+=200'},2000, "linear" )
           .animate( {top:'-=200'},2000, "linear", move_it );
    */
}

$(document).ready( function() {
    make_it();
    move_it();
});
</script>

<p><span class="css3_demo">CSS3!</span> </p>]]></content:encoded>
    </item>
    <item>
      <title>HTML5 canvas point operations</title>
      <link>http://mwcz.org/2011/11/17/html5-canvas-point-operations</link>
      <pubDate>Thu, 17 Nov 2011 19:25:00 EST</pubDate>
      <category><![CDATA[color]]></category>
      <category><![CDATA[canvas]]></category>
      <category><![CDATA[jsimage]]></category>
      <category><![CDATA[image processing]]></category>
      <category><![CDATA[html5]]></category>
      <guid>b'2uP1qAr8SfbHgvsg46MdoeZsgcc='</guid>
      <description>HTML5 canvas point operations</description>
      <content:encoded><![CDATA[<p>This is the last demo I made using <a href="https://github.com/mwcz/jsimage">JSImage</a>.  I created it some time around 2009-2010.  At the time, I had checked out an <a href="http://www.amazon.com/Digital-Image-Processing-Algorithmic-Introduction/dp/1846283795">imaging book</a> from my university's library at least ten times.  Most of the exercises in that book I implemented in Python using <a href="http://www.pythonware.com/products/pil/">PIL</a>, but point operations were simple enough to port to JavaScript quickly.</p>
<p>Point operations are image alterations that affect all pixels equally.  Other operations, like blurring for example, each result pixel depends on adjacent pixels.</p>
<p>This demonstrates changing contrast, value, saturation, hue, color inversion, and threshold point operations.  Note that there is a bug with increasing value and increasing saturation which I never got around to fixing.</p>
<script type="text/javascript" src="/js/005/jquery.min.js"></script> 
<script type="text/javascript" src="/js/005/jsimage.js"></script> 
<script type="text/javascript" src="/js/005/colorspace.js"></script>

<script type="text/javascript">

var img0; // make img0 public so I can play with it in firebug more easily

window.onload = function() {
        img0 = new JSImage( "img0", "/img/005/bee.jpg" );
    }

</script>

<p><canvas id="img0">your browser does not support canvas</canvas> </p>
<table cellpadding="4" cellspacing="0"> 
<tr>

<th>Value</th> 
    <th>Contrast</th> 
    <th>Saturation</th> 
    <th>Hue</th> 
    <th>Invert</th> 
    <th>Threshold</th> 
</tr>

<tr> 
    <td> 
        <!-- using onmousedown instead of onclick because it improves perceived performance.
             definitely an accessibility problem, though --> 
        <input type="image" src="/img/005/arrow_up.png" onmousedown="img0.value( img0.canvas, 10 )" /> 
        <input type="image" src="/img/005/arrow_down.png" onmousedown="img0.value( img0.canvas, -10 )" /> 
    </td> 
    <td> 
        <input type="image" src="/img/005/arrow_up.png" onmousedown="img0.contrast( img0.canvas, 1.1)" /> 
        <input type="image" src="/img/005/arrow_down.png" onmousedown="img0.contrast( img0.canvas, 0.9)" /> 
    </td> 
    <td> 
        <input type="image" src="/img/005/arrow_up.png" onmousedown="img0.saturation( img0.canvas, 25 )" /> 
        <input type="image" src="/img/005/arrow_down.png" onmousedown="img0.saturation( img0.canvas, -25 )" /> 
    </td> 
    <td> 
        <input type="image" src="/img/005/arrow_up.png" onmousedown="img0.hue( img0.canvas, 20)" /> 
        <input type="image" src="/img/005/arrow_down.png" onmousedown="img0.hue( img0.canvas, -20)" /> 
    </td> 
    <td> 
        <button type="button" onmousedown="img0.invert()">invert</button> 
    </td> 
    <td> 
        <button type="button" onmousedown="img0.threshold( img0.canvas, document.getElementById('t').value )">threshold</button> 
        <br /> 
        <input type="text" value="127" maxlength="3" size="3" id="t" /> 
    </td> 
</tr>

</table>]]></content:encoded>
    </item>
    <item>
      <title>HTML5 canvas area selection averaging</title>
      <link>http://mwcz.org/2011/11/16/html5-canvas-area-selection-averaging</link>
      <pubDate>Wed, 16 Nov 2011 18:25:00 EST</pubDate>
      <category><![CDATA[color]]></category>
      <category><![CDATA[colorpal]]></category>
      <category><![CDATA[canvas]]></category>
      <category><![CDATA[jsimage]]></category>
      <category><![CDATA[html5]]></category>
      <guid>b'C9TlJjRziEuKR3rVgcQw66ug5QQ='</guid>
      <description>HTML5 canvas area selection averaging</description>
      <content:encoded><![CDATA[<p>This is a demo from late 2009.  It's an extension of the single-pixel <a href="/blog/2011/11/16/html5-canvas-eyedropper/">eyedropper</a> I wrote previously.</p>
<p>It's powered by an early version of an old JS toolkit I wrote called JSImage.  The latest version is available at my <a href="https://github.com/mwcz/jsimage">JSImage github repo</a>.  Don't be fooled by the 2011 commits, those are just artifacts from svn-&gt;git migration.  No guarantees that the histo's are actually correct. :)</p>
<p>I used an old version of a rectangular selection tool called marquee.  I believe it's still located <a href="http://marqueetool.net/">here</a> but I can't be totally sure that's the same project.</p>
<p>Click, drag, and taste the magic. :|</p>
<link rel="stylesheet" type="text/css" href="/css/004/marker.css" /> 
<script type="text/javascript" src="/js/004/marquee/prototype_reduced.js"></script> 
<script type="text/javascript" src="/js/004/marquee/rectmarquee.js"></script> 
<script type="text/javascript" src="/js/004/JSImage.js"></script>

<script type="text/javascript">

window.onload = function() {

img0 = new JSImage( "c0", "/img/004/kazoo.png" );
    setTimeout("img0.draggable();",100); // enable the selection

}

var img0; // make img0 public so I can play with it in firebug more easily

</script>

<canvas id="c0"> 
    Your browser does not support the <canvas> element. Lame.
</canvas>]]></content:encoded>
    </item>
  </channel>
</rss>

