<?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>lankycoder</title>
	<atom:link href="http://www.lorrin.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lorrin.org/blog</link>
	<description>Assorted Adventures in Software Development</description>
	<lastBuildDate>Tue, 21 Feb 2012 18:28:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Random file selections with Python</title>
		<link>http://www.lorrin.org/blog/2012/02/21/random-file-selections-with-python/</link>
		<comments>http://www.lorrin.org/blog/2012/02/21/random-file-selections-with-python/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 18:28:50 +0000</pubDate>
		<dc:creator>lorrin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[ZSH]]></category>

		<guid isPermaLink="false">http://www.lorrin.org/blog/?p=109</guid>
		<description><![CDATA[After my previous adventures in slicing and dicing a huge XML file, I wanted a means to randomly select files. But first, the directory had so many entries it was unwieldy on my laptop. The Python script below divvies the files up into directories of up to 1000 files each. (Adaptable to other contexts via [...]]]></description>
			<content:encoded><![CDATA[<p>After my previous adventures in <a title="Splitting large XML files with xml_split and sed (preserving root element and namespace declaration)" href="http://www.lorrin.org/blog/?p=93">slicing and dicing a huge XML</a> file, I wanted a means to randomly select files. But first, the directory had so many entries it was unwieldy on my laptop. The Python script below divvies the files up into directories of up to 1000 files each. (Adaptable to other contexts via slight tweaking of the filename regex and subdir name generation.)</p>
<pre class="brush:py">#!/usr/bin/python
import os
import re
where = '.' # source directory 

ls = os.listdir(where)
for f in ls:
  m = re.search('.*_COMM-([0-9]+).xml', f)
  if m:
    subdir = "%03d" % (int(m.group(1)) / 1000)
    try:
      os.mkdir(subdir)
    except OSError as e:
      pass
    os.rename(f, os.path.join(subdir, f))</pre>
<p>Now on to the random selection, again with Python:</p>
<pre class="brush:py">#!/usr/bin/python
import os
import random
import re
import sys

if len(sys.argv) &gt; 1:
  where = sys.argv[1]
else:
  where = '.' # source directory 

subdirs = filter(lambda x: re.search('^[0-9]*$', x), os.listdir(where))
subdir = os.path.join(where,random.choice(subdirs))
print os.path.join(subdir,random.choice(os.listdir(subdir)))</pre>
<p>A quick shell loop leverages the Python script to grab files and dump into a repository of test data. Works on ZSH, Bash, perhaps others:</p>
<pre class="brush:shell">for i in {1..250}; do cp $(./pick_a_file.py sub_dir_with_files) /destination/dir/filename_prefix_$(printf "%03d" $i).xml; done;</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lorrin.org/blog/2012/02/21/random-file-selections-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thunderbird still displays expunged IMAP messages</title>
		<link>http://www.lorrin.org/blog/2012/02/14/thunderbird-still-displays-expunged-imap-messages/</link>
		<comments>http://www.lorrin.org/blog/2012/02/14/thunderbird-still-displays-expunged-imap-messages/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 06:11:12 +0000</pubDate>
		<dc:creator>lorrin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Thunderbird]]></category>

		<guid isPermaLink="false">http://www.lorrin.org/blog/?p=104</guid>
		<description><![CDATA[There is lots to be said about the intricacies of IMAP delete flags vs. actual expunging of deleted messages and the confusion caused when something is merely flagged for deletion and the user expected it to be really gone. This post is not about that. Everyone agrees that once a message is expunged, it definitely [...]]]></description>
			<content:encoded><![CDATA[<p>There is <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=220064">lots to be said</a> about the intricacies of IMAP <a href="http://kb.mozillazine.org/Deleting_messages_in_IMAP_accounts">delete flags vs. actual expunging</a> of deleted messages and the confusion caused when something is merely flagged for deletion and the user expected it to be really gone. This post is not about that. <em>Everyone agrees that once a message is expunged, it definitely should be gone.</em> But sometimes expunged messages still display in Thunderbird!</p>
<p>I often observe this:</p>
<ol>
<li>Delete message on the way to work using <a href="https://code.google.com/p/k9mail/">K-9</a> on my phone.</li>
<li>Arrive at work and message is gone from my Inbox in <a href="https://en.wikipedia.org/wiki/Mail_%28application%29">Mail.app</a></li>
<li>Come home, download new mail in <a href="https://www.mozilla.org/en-US/thunderbird/">Thunderbird</a> and see an Inbox full of undead messages.</li>
</ol>
<p>No amount of re-expunging and re-fetching mail helps. Grepping through the server-side Maildir shows the messages really are gone from the folders in which Thunderbird is still showing them.</p>
<p>It turns out the reason they are still displaying in Thunderbird is mundane client-side index corruption. To clean things up:</p>
<ol>
<li>Right-click on mailbox</li>
<li>Choose <tt>Properties...</tt></li>
<li>Click <tt>Repair Folder</tt></li>
<li>Rejoice at tidy mailbox</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.lorrin.org/blog/2012/02/14/thunderbird-still-displays-expunged-imap-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to treat a bare value as an Array in Ruby</title>
		<link>http://www.lorrin.org/blog/2012/02/08/how-to-treat-a-bare-value-as-an-array-in-ruby/</link>
		<comments>http://www.lorrin.org/blog/2012/02/08/how-to-treat-a-bare-value-as-an-array-in-ruby/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 05:40:43 +0000</pubDate>
		<dc:creator>lorrin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.lorrin.org/blog/?p=99</guid>
		<description><![CDATA[Often Array(arg) is used for this, but is flawed. Note the last result when applied to a Hash: &#62; Array(42)  =&#62; [42] &#62; Array([1,2,3])  =&#62; [1, 2, 3] &#62; Array(nil)  =&#62; [] &#62; Array("foo")  =&#62; ["foo"] &#62; Array({"foo" =&#62; "bar", "biz" =&#62; "baz"})  =&#62; [["foo", "bar"], ["biz", "baz"]] What went wrong is that Array() calls [...]]]></description>
			<content:encoded><![CDATA[<p>Often <code>Array(arg)</code> is used for this, but is flawed. Note the last result when applied to a Hash:</p>
<pre class="brush:ruby">&gt; Array(42)
 =&gt; [42]
&gt; Array([1,2,3])
 =&gt; [1, 2, 3]
&gt; Array(nil)
 =&gt; []
&gt; Array("foo")
 =&gt; ["foo"]
&gt; Array({"foo" =&gt; "bar", "biz" =&gt; "baz"})
 =&gt; [["foo", "bar"], ["biz", "baz"]]</pre>
<p>What went wrong is that Array() calls the (now deprecated) <code>to_a</code> on each of its arguments. Hash has a custom <code>to_a</code> implementation with different semantics. Instead, do  this:</p>
<pre class="brush:ruby">class Array
  def self.wrap(args)
    return [] unless args
    args.is_a?(Array) ? args : [args]
  end
end</pre>
<p>That yields the expected results, even for Hashes:</p>
<pre class="brush:ruby">&gt; Array.wrap(42)
 =&gt; [42]
&gt; Array.wrap([1,2,3])
 =&gt; [1, 2, 3]
&gt; Array.wrap(nil)
 =&gt; []
&gt; Array.wrap("foo")
 =&gt; ["foo"]
&gt; Array.wrap({"foo" =&gt; "bar", "biz" =&gt; "baz"})
 =&gt; [{"foo"=&gt;"bar", "biz"=&gt;"baz"}]</pre>
<p>Use of <code>is_a?</code> is deliberate; duck-typing in this situation (<code>[:[], :each].all? { |m| args.respond_to? m }</code>) yields unexpected surprises since e.g. String is Enumerable and would not get wrapped.</p>
<p>For further discussion see Ruby-forum thread &#8220;<a href="http://www.ruby-forum.com/topic/145515">shortcut for x = [x] unless x.is_a?(Array)</a>&#8221; and StackOverflow &#8220;<a href="http://stackoverflow.com/questions/385912/ruby-object-to-a-replacement">Ruby: Object.to_a replacement</a>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lorrin.org/blog/2012/02/08/how-to-treat-a-bare-value-as-an-array-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Splitting large XML files with xml_split and sed (preserving root element and namespace declaration)</title>
		<link>http://www.lorrin.org/blog/2012/02/08/splitting-large-xml-files-with-xml_split-and-sed/</link>
		<comments>http://www.lorrin.org/blog/2012/02/08/splitting-large-xml-files-with-xml_split-and-sed/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 04:47:42 +0000</pubDate>
		<dc:creator>lorrin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.lorrin.org/blog/?p=93</guid>
		<description><![CDATA[Slicing up XML files is best done with an XML parser. (Regular expressions, csplit, etc. are too easily confused by arbitrary strings in CDATA sections.) xml_split (may be obtained with CPAN by installing XML::Twig) mostly does the trick. Given a file like: &#60;?xml version="1.0" encoding="UTF-8"?&#62; &#60;foo:Root xmlns:foo="http://www.foo.bar/fnarf/foo"&#62; &#60;foo:child&#62; ... &#60;/foo:child&#62; &#60;foo:child&#62; ... &#60;/foo:child&#62; &#60;/foo:Root&#62; &#8230;xml_split [...]]]></description>
			<content:encoded><![CDATA[<p>Slicing up XML files is best done with an XML parser. (Regular expressions, csplit, etc. are too easily confused by arbitrary strings in CDATA sections.) <a href="http://search.cpan.org/perldoc?xml_split">xml_split</a> (may be obtained with CPAN by installing <a href="http://search.cpan.org/~mirod/XML-Twig-3.39/">XML::Twig</a>) <em>mostly</em> does the trick. Given a file like:</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;foo:Root xmlns:foo="http://www.foo.bar/fnarf/foo"&gt;
  &lt;foo:child&gt;
    ...
  &lt;/foo:child&gt;
  &lt;foo:child&gt;
    ...
  &lt;/foo:child&gt;
&lt;/foo:Root&gt;</pre>
<p>&#8230;xml_split can create many files, each containing:</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;foo:child&gt;
  ...
&lt;/foo:child&gt;</pre>
<p>However, this loses the namespace declaration and the enclosing root element. Luckily, a little sed magic can bring those back:</p>
<pre class="brush:shell">find . -name '*.xml' | xargs -n1 sed -e '1 a\
&lt;foo:Root xmlns:foo="http://www.foo.bar/fnarf/foo"&gt;
' -e '$ a\
&lt;/foo:Root&gt;
' -i ''</pre>
<p>find lists all the files, xargs invokes sed on them one by one (<code>-n1</code>), and sed adds the opening tag with namespace declaration after the first line (<code>1 a</code>) and the closing tag after the last line (<code>$ a</code>). Now each file looks like this:</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;foo:Root xmlns:foo="http://www.foo.bar/fnarf/foo"&gt;
  &lt;foo:child&gt;
    ...
  &lt;/foo:child&gt;
&lt;/foo:Root&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lorrin.org/blog/2012/02/08/splitting-large-xml-files-with-xml_split-and-sed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing predicted runtime on APC UPS after replacing battery</title>
		<link>http://www.lorrin.org/blog/2011/11/27/fixing-predicted-runtime-on-apc-ups/</link>
		<comments>http://www.lorrin.org/blog/2011/11/27/fixing-predicted-runtime-on-apc-ups/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 09:44:48 +0000</pubDate>
		<dc:creator>lorrin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[apctest]]></category>
		<category><![CDATA[apcupsd]]></category>
		<category><![CDATA[ups]]></category>

		<guid isPermaLink="false">http://www.lorrin.org/blog/?p=78</guid>
		<description><![CDATA[The battery in my APC Back-UPS BR 800 was worn out after years of service, so I bought a replacement from APC.com. However, apcupsd still reported zero runtime and erratic charge and load percentages. I did some manual recalibration attempts (charge fully, discharge completely using constant load). This got my estimated runtime from zero up [...]]]></description>
			<content:encoded><![CDATA[<p>The battery in my APC Back-UPS BR 800 was worn out after years of service, so I bought a replacement from APC.com. However, <tt>apcupsd</tt> still reported zero runtime and erratic charge and load percentages. I did some manual recalibration attempts (charge fully, discharge completely using constant load). This got my estimated runtime from zero up to a few seconds, but the UPS was still not useful. A couple seconds of power outage would lead to bogus critically low battery readings and trigger automated shutdown. (Despite the fact that it took me about half an hour to complete the run-down under a similar load.)</p>
<p>This evening I was preparing for another recalibration attempt by looking for a way to disable the beeping when power is disconnected. It turns out <tt>apctest</tt> can <a href="http://jace.zaiki.in/2009/09/14/disabling-the-alarm-on-apc-upses">disable the alarm</a>. In the process, I noticed <tt>apctest</tt> can also read and write the battery date. On a whim, I updated the date. And, magic: <strong><em>Merely changing the battery date fixed the reported runtime, charge, and load percentages!</em></strong></p>
<p>Changing the battery date back to the original value did not bring the bogus readings back. Presumably the behavior is based on dead-reckoning of time elapsed since last battery change rather than any knowledge of what the current date actually is.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lorrin.org/blog/2011/11/27/fixing-predicted-runtime-on-apc-ups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>error: File name too long during Scala compile</title>
		<link>http://www.lorrin.org/blog/2011/11/17/error-file-name-too-long-during-scala-compile/</link>
		<comments>http://www.lorrin.org/blog/2011/11/17/error-file-name-too-long-during-scala-compile/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 20:17:45 +0000</pubDate>
		<dc:creator>lorrin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ecryptfs]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.lorrin.org/blog/?p=67</guid>
		<description><![CDATA[[ERROR] error: File name too long A common way to install Ubuntu is with an underlying ext4 file system and eCryptfs encrypted home directories. ext4, like many other file systems, has a maximum filename limit of 255 bytes. eCryptfs creates filenames much longer than the original. Compiled Scala classes tend to have long file names [...]]]></description>
			<content:encoded><![CDATA[<p><code>[ERROR] error: File name too long</code></p>
<p>A common way to install Ubuntu is with an underlying ext4 file system and eCryptfs encrypted home directories. ext4, <a href="https://en.wikipedia.org/wiki/Comparison_of_file_systems" title="comparison of file systems">like many other file systems</a>, has a maximum filename limit of 255 bytes. eCryptfs <a href="https://bugs.launchpad.net/ecryptfs/+bug/344878">creates filenames much longer than the original</a>. Compiled Scala classes tend to have long file names since anonymous classes end up in their own files. Therefore, when compiling Scala projects within eCryptfs on ext4, it is <a href="https://github.com/dcaoyuan/nbscala/issues/9">easy to get file name too long</a> errors. <img src='http://www.lorrin.org/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lorrin.org/blog/2011/11/17/error-file-name-too-long-during-scala-compile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala&#8217;s missing splat operator</title>
		<link>http://www.lorrin.org/blog/2011/10/04/scalas-missing-splat-operator/</link>
		<comments>http://www.lorrin.org/blog/2011/10/04/scalas-missing-splat-operator/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 07:38:16 +0000</pubDate>
		<dc:creator>lorrin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://www.lorrin.org/blog/?p=59</guid>
		<description><![CDATA[Ruby, Python, and many other dynamic languages have a so-called splat operator that lets you easily invoke a function by providing a list of argument values: def f(x,y) x*y end &#62; fArgs = [6,7.0] =&#62; [6, 7.0] &#62; f(*fArgs) =&#62; 42.0 Scala does not have a splat operator per se, but you can achieve the [...]]]></description>
			<content:encoded><![CDATA[<p>Ruby, Python, and many other dynamic languages have a so-called splat operator that lets you easily invoke a function by providing a list of argument values:</p>
<pre class="brush:ruby">def f(x,y)
  x*y
end

&gt; fArgs = [6,7.0]
=&gt; [6, 7.0]

&gt; f(*fArgs)
=&gt; 42.0</pre>
<p>Scala does not have a splat operator per se, but you can achieve the same effect without too much work. Sadly the syntax is different for fixed-<a href="https://secure.wikimedia.org/wikipedia/en/wiki/Arity">arity</a> and <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Variadic_function">variadic</a> functions.</p>
<h3>Scala splat for variadic functions</h3>
<p>For variadic functions there effectively is a splat operator. If you invoke a variadic function and append <code>:_*</code> to the argument the compiler will perform the splat:</p>
<pre class="brush:scala">&gt; def g(xs:Int*) = (0 /: xs) (_ + _)
g: (xs: Int*)Int

&gt; val gArgs = List(1,2,3,4)
gArgs: List[Int] = List(1, 2, 3, 4)

&gt; g(gArgs:_*)
res23: Int = 10</pre>
<h3>Scala splat for fixed-arity functions</h3>
<pre class="brush:scala">&gt; def f(x:Int, y:Double) = x * y
f: (x: Int, y: Double)Double

&gt; val fArgs = (6, 7.0)
fArgs: (Int, Double) = (6,7.0)

&gt; f _ tupled fArgs
res8: Double = 42.0</pre>
<p>Magic! The first part, <code>f _</code>, is the syntax for a partially applied function in which none of the arguments have been specified. This works as a mechanism to get a hold of the function object. <code>tupled</code> returns a new function which of arity-1 that takes a single arity-n tuple. It is defined in the Scala <a href="http://www.scala-lang.org/api/current/index.html#scala.Function$">Function object</a>,</p>
<p>However, given a <em>List</em> of arguments to pass to f, I&#8217;m not sure how to easily convert the List to a Tuple.</p>
<p>p.s. There&#8217;s a stackoverflow post about this called &#8220;<a href="http://stackoverflow.com/questions/3568002/scala-tuple-unpacking">scala tuple unpacking</a>.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lorrin.org/blog/2011/10/04/scalas-missing-splat-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Argumentless git pull and git push</title>
		<link>http://www.lorrin.org/blog/2011/10/03/argumentless-git-pull-and-git-push/</link>
		<comments>http://www.lorrin.org/blog/2011/10/03/argumentless-git-pull-and-git-push/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 05:55:38 +0000</pubDate>
		<dc:creator>lorrin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.lorrin.org/blog/?p=56</guid>
		<description><![CDATA[Pulling and pushing with git can be a bit verbose.  This post explains how to get from git pull --rebase origin master and git push origin master to just typing git pull and git push. Rebase First, set rebase for every new upstream branch (Why rebase? It makes your history easier to understand.) git config [...]]]></description>
			<content:encoded><![CDATA[<p>Pulling and pushing with git can be a bit verbose.  This post explains how to get from <code>git pull --rebase origin master</code> and <code>git push origin master</code> to just typing <code>git pull</code> and <code>git push</code>.</p>
<h4>Rebase</h4>
<p>First, set <em>rebase</em> for every new upstream branch (Why rebase? It <a title="git pull with rebase" href="http://gitready.com/advanced/2009/02/11/pull-with-rebase.html">makes your history easier to understand</a>.)</p>
<p><code>git config --global branch.autosetuprebase always </code></p>
<p>This is explained in more detail (and with other helpful hints) in Mislav Marohnić&#8217;s post <a href="http://mislav.uniqpath.com/2010/07/git-tips/">A few git tips you didn&#8217;t know about</a>.</p>
<h4>Tracking</h4>
<p>Second, make <code>git push</code> only send the current branch to its matching upstream (aka tracking) branch. (Otherwise the default behavior is to push <em>all</em> branches that have the same name on both ends.)</p>
<p><code>git config --global push.default upstream</code></p>
<p>This is covered in some detail in Mark Longhair&#8217;s post <a href="http://longair.net/blog/2011/02/27/an-asymmetry-between-git-pull-and-git-push/">An asymmetry between git pull and push</a>.</p>
<p>On any existing branches, you can set up tracking by doing an explicit push:</p>
<p><code>git push -u origin <em>branchname</em></code></p>
<h4>Default refspec</h4>
<p>At this point you should be set according to all the tutorials I came across. In my experience, however, this only works for branches other than master. A plain <code>git push</code> on master yields the error:</p>
<p><code>fatal: The current branch master has multiple upstream branches, refusing to push.</code></p>
<p>The solution is to set the default refspec for git push. I&#8217;m unclear on why this needed for master but not for other branches.</p>
<p><code>git config remote.origin.push HEAD</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lorrin.org/blog/2011/10/03/argumentless-git-pull-and-git-push/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Fruitless Search for a Password Bookmarklet</title>
		<link>http://www.lorrin.org/blog/2011/06/15/a-fruitless-search-for-a-password-bookmarklet/</link>
		<comments>http://www.lorrin.org/blog/2011/06/15/a-fruitless-search-for-a-password-bookmarklet/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 07:41:43 +0000</pubDate>
		<dc:creator>lorrin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.lorrin.org/blog/?p=53</guid>
		<description><![CDATA[Using a bookmarklet to store passwords is appealingly simple. Alas, after doing some digging, I couldn&#8217;t find any viable options. The first concern I came across is that it important to use a hash algorithm that&#8217;s slow (e.g. bcrypt or scrypt). Otherwise it&#8217;s too easy to brute-force the master password based on a site password. [...]]]></description>
			<content:encoded><![CDATA[<p>Using a bookmarklet to store passwords is appealingly simple. Alas,  after doing some digging, I couldn&#8217;t find any viable options.</p>
<p>The first concern I came across is that it important to <a href="http://codahale.com/how-to-safely-store-a-password/">use a hash algorithm that&#8217;s </a><em><a href="http://codahale.com/how-to-safely-store-a-password/">slow</a></em> (e.g. <a href="https://secure.wikimedia.org/wikipedia/en/wiki/bcrypt">bcrypt</a> or <a href="http://www.tarsnap.com/scrypt.html">scrypt</a>)<em>.</em> Otherwise it&#8217;s too easy to brute-force the master password based on a  site password. Suppose site you visit stores your password in plaintext  and gets hacked. That breach then compromises your master password, even  though only your site-specific password was revealed.</p>
<p>I couldn&#8217;t find a JavaScript implementation of scrypt, but I found a <a href="https://code.google.com/p/javascript-bcrypt/">JavaScript bcrypt implementation</a>. Better yet, I found a derivative that tidies up the first one, removing dependencies  on e.g. <a href="http://www.clipperz.com/">ClipperZ</a>, and wraps it in a <a href="http://scripts.cwillu.com/passwords/">simple bookmarklet</a>. <a href="http://supergenpass.com/">SuperGenPass</a> provides a much more user-friendly bookmarklet, so I started gearing up to replace it&#8217;s MD5 hashing with bcrypt.</p>
<p>But, alas, SuperGenPass (and any other simple bookmarklet) is <a href="http://akibjorklund.com/2009/supergenpass-is-not-that-secure">not secure</a> in the face of a malicious website that contains JavaScript designed to sniff entry of the master  password in to the bookmarklet. <a href="http://crypto.stanford.edu/PwdHash/">PwdHash</a> is a browser extension based  approach from the Stanford Security Lab designed to combat the weaknesses of the bookmarklet based  approach. Their paper, <a href="http://crypto.stanford.edu/PwdHash/pwdhash.pdf">Stronger Password Authentication Using Browser Extensions</a>, is interesting reading and explains a variety of ways to compromise a bookmarklet based approach. PwdHash has already spawned a number of ports to other browsers and  mobile devices, but alas they&#8217;re all based on prototype code that uses  HMAC-MD5 as the hashing algorithm (even though the paper points out  PwdHash is a good candidate for a better hashing algorithm).</p>
<p>I was not able to find any PwdHash derivative that used bcrypt. I did find a simple <a href="http://blog.derekmauro.com/2011/04/how-i-manage-passwords.html">command-line tool based on scrypt</a>, but that&#8217;s not great if you don&#8217;t have easy access to your own computer.</p>
<p>Solutions like <a href="http://www.passpack.com/">PassPack</a> offer the  potential to solve these problems (extension rather than bookmarklet,  use of strong encryption rather than weak hashing), but have an Achilles  heel of their own: <a href="http://maltainfosec.org/archives/88-PassPack-and-why-it-does-not-work.html">the service provider has the power to decrypt all your passwords</a>. For now I&#8217;ll stick with my <a href="../2011/03/30/introducing-moinmoin-client-crypt/">moinmoin-client-crypt</a> approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lorrin.org/blog/2011/06/15/a-fruitless-search-for-a-password-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Misadventures in Breaking Actors with Scala Self-Types</title>
		<link>http://www.lorrin.org/blog/2011/06/05/misadventures-in-breaking-actors-with-scala-self-types/</link>
		<comments>http://www.lorrin.org/blog/2011/06/05/misadventures-in-breaking-actors-with-scala-self-types/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 06:49:11 +0000</pubDate>
		<dc:creator>lorrin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[self-type]]></category>

		<guid isPermaLink="false">http://www.lorrin.org/blog/?p=48</guid>
		<description><![CDATA[Quick refresher: self-types are commonly used when writing traits that want to proscribe that they get mixed in to a particular class. For example, the cake-pattern leverages them. In the example below, FooTrait specifies a self-type of FooTraitConfiguration to insure that it is mixed in to a class that provides the expected times val. import [...]]]></description>
			<content:encoded><![CDATA[<p>Quick refresher: <a href="http://www.scala-lang.org/node/124">self-types</a> are commonly used when writing traits that want to proscribe that they get mixed in to a particular class. For example, the <a href="http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di.html">cake-pattern</a> leverages them. In the example below, <code>FooTrait</code> specifies a self-type of <code>FooTraitConfiguration</code> to insure that it is mixed in to a class that provides the expected <code>times</code> val.</p>
<pre>
<pre class="brush:scala">import actors.Actor
import actors.Actor._

trait FooTraitConfiguration { val times : Int }

trait FooTrait { self:FooTraitConfiguration =&gt;
  case object Ping
  case object Pong

  val a = actor {
    loop {
      react {
        case Ping =&gt;
          self ! Pong
        case Pong =&gt;
          for(_ &lt;- (1 to times)) { print(".") }
          System.out.println("pong.")
  } } }

  def ping = a ! Ping
  def pong = a ! Pong
}

class Foo extends FooTrait with FooTraitConfiguration { @Override val times = 5 }</pre>
</pre>
<p>But, alas, this fails to compile:</p>
<pre>error: value ! is not a member of FooTrait with FooTraitConfiguration
self ! Pong</pre>
<p>It seems that the self-trait has broken the Actor API! And indeed, it has. Because self-traits are not usually specified with <code>self</code>! It should have been:<br />
<code><strong>this</strong>:FooTraitConfiguration =&gt;</code></p>
<p>The self-type means that within <code>FooTrait</code> the type of <code>this</code> is considered to be <code>FooTrait with FooTraitConfiguration</code>. Using a word other than <code>this</code> <a href="http://stackoverflow.com/questions/4017357/difference-between-this-and-self-in-self-type-annotations/4018995#4018995">additionally sets up an alias to that type for e.g. use within nested classes</a>. And there&#8217;s the rub: Actors depend on a method named <code>self</code> which is shadowed when the alias to the type is named <code>self</code>.</p>
<p>Note to self: <strong>Don&#8217;t use <code>self</code> when specifying self types!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lorrin.org/blog/2011/06/05/misadventures-in-breaking-actors-with-scala-self-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

