vemod.net http://vemod.net/ ... Mini-Review of Griffin Simplifi http://vemod.net/mini-review-of-griffin-simplifi <p><small>Tags: <a href="http://vemod.net/mac" class="tag" rel="tag">Mac</a> and <a href="http://vemod.net/mini-reviews" class="tag" rel="tag">Mini-Reviews</a></small></p><div class="full-width" style="position: absolute; top: 0; left: 1.5em; right: 1.5em; padding: 19px; background-color: rgba(250, 246, 234, 0.9); text-align: center"> <h1>Mini-Review of <a href="http://www.griffintechnology.com/products/simplifi" class="external">Griffin Simplifi</a></h1> <div>An iPhone/iPod dock, flash card reader and <span class="caps">USB</span> hub &ndash; all in one!</div> </div> <div class="full-width" style="margin-top: -1em"> <img src="/stuff/simplifi_4.jpg" alt="" style="width: 100%" /> </div> <p style="opacity: 0.8; float: right">Photo by Griffin.</p> <h2>The Good</h2> <ul> <li>Compact 3-in-1! Space saving, yay.</li> <li>All components work as expected.</li> <li>Decent design.</li> </ul> <h2>The Bad</h2> <ul> <li>The bright blue <span class="caps">LED</span> in the front is annoying. See note below.</li> <li>The product is a bit pricey but not too bad.</li> </ul> <h2>The Links</h2> <ul> <li><a href="http://www.amazon.com/gp/product/B001DQNAK2?tag=vemodnet-20">Amazon&#8217;s product page</a> <img src="http://www.assoc-amazon.com/e/ir?t=vemodnet-20&#38;l=as2&#38;o=1&#38;a=B001DQNAK2" border="0" height="1" alt="" style="border:none !important; margin:0px !important;" width="1" /></li> <li><a href="http://www.griffintechnology.com/products/simplifi" class="external">Manufacturer&#8217;s product page</a></li> </ul> <h2>The Blue <span class="caps">LED</span> <small>(UPDATE!)</small></h2> <p>Three months after installing the Simplifi I got so fed up with bright blue <span class="caps">LED</span> that I killed it by opening the case. (I have the Simplifi in my bedroom and blue is the color of daylight.)</p> <h2>The Ending Credits</h2> <p>Thanks to my friend Felix who bought a copy of this product for me in <span class="caps">USA</span>. It&#8217;s not available in the Swedish market and Amazon doesn&#8217;t ship it here for some reason.</p> Fri, 08 Oct 2010 19:26:59 +0200 http://vemod.net/mini-review-of-griffin-simplifi 2010-10-08T19:26:59+02:00 Mini-Reviews http://vemod.net/mini-reviews Fri, 08 Oct 2010 19:34:47 +0200 http://vemod.net/mini-reviews 2010-10-08T19:34:47+02:00 unfoldRight http://vemod.net/unfoldright <p><small>Tags: <a href="http://vemod.net/scala" class="tag" rel="tag">Scala</a></small></p><pre><code class="scala pygments"><span class="k">def</span> <span class="n">unfoldRight</span><span class="o">[</span><span class="kt">A</span>, <span class="kt">B</span><span class="o">](</span><span class="n">f</span><span class="k">:</span> <span class="kt">B</span> <span class="o">=&gt;</span> <span class="nc">Option</span><span class="o">[(</span><span class="kt">A</span>, <span class="kt">B</span><span class="o">)],</span> <span class="n">x</span><span class="k">:</span> <span class="kt">B</span><span class="o">)</span><span class="k">:</span> <span class="kt">List</span><span class="o">[</span><span class="kt">A</span><span class="o">]</span> <span class="k">=</span> <span class="o">{</span> <span class="n">f</span><span class="o">(</span><span class="n">x</span><span class="o">)</span> <span class="k">match</span> <span class="o">{</span> <span class="k">case</span> <span class="nc">Some</span><span class="o">((</span><span class="n">a</span><span class="o">,</span> <span class="n">b</span><span class="o">))</span> <span class="k">=&gt;</span> <span class="n">a</span> <span class="o">::</span> <span class="n">unfoldRight</span><span class="o">(</span><span class="n">f</span><span class="o">,</span> <span class="n">b</span><span class="o">)</span> <span class="k">case</span> <span class="nc">None</span> <span class="k">=&gt;</span> <span class="nc">Nil</span> <span class="o">}</span> <span class="o">}</span> </code></pre> <p>See also: <a href="http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Data-List.html#v:unfoldr" class="external">unfoldr in Haskell</a></p> Thu, 04 Nov 2010 16:44:02 +0100 http://vemod.net/unfoldright 2010-11-04T16:44:02+01:00 Lisp http://vemod.net/lisp <p><small>Tags: <a href="http://vemod.net/programming-languages" class="tag" rel="tag">Programming Languages</a></small></p><h1 style="text-align: center"><img src="/stuff/lisplogo_alien_256.png" alt="Lisp" /></h1> <blockquote style="margin: 1em 100px"> <p> Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot. &mdash; Eric S. Raymond </p> </blockquote> <div style="clear: both"></div> Sun, 09 Jan 2011 13:08:33 +0100 http://vemod.net/lisp 2011-01-09T13:08:33.372764+01:00 Elektronikförsäljare http://vemod.net/elektronikforsaljare <ul> <li><a href="http://www.electrokit.se/" class="external">electrokit</a> <code>[A,S]</code></li> <li><a href="https://www.elfa.se/" class="external"><span class="caps">ELFA</span></a></li> <li><a href="http://www.jelu.se/" class="external"><span class="caps">JEMU</span></a></li> <li><a href="http://www.lawicel-shop.se/" class="external">Lawicel</a> <code>[A,S]</code></li> <li><a href="http://medial.se/" class="external"><span class="caps">MEDIAL</span></a> <code>[A,S]</code></li> </ul> <p><code>[A]</code> = Säljer Arduino<br /> <code>[S]</code> = Säljer produkter från Sparkfun</p> <p>Var vänlig och <a href="mailto:christoffer.sawicki@gmail.com?subject=Elektronikförsäljare">meddela mig</a> om någon elektronikförsäljare saknas; mitt mål är att denna lista ska vara fullständig.</p> Tue, 11 Jan 2011 11:33:49 +0100 http://vemod.net/elektronikforsaljare 2011-01-11T11:33:49.473691+01:00 def state = 'confused http://vemod.net/def-state-confused <p><small>Tags: <a href="http://vemod.net/scala" class="tag" rel="tag">Scala</a></small></p><p>I think method definitions in <a href="http://vemod.net/scala">Scala</a> can be a bit confusing. Here&#8217;s a <span class="caps">REPL</span> session with some comments and questions:</p> <pre style="color: #585858"><code>scala&gt; def A() = 'A A: ()Symbol scala&gt; def B = () =&gt; 'B B: () =&gt; Symbol scala&gt; def C = 'C C: Symbol</code></pre> <p>So far nothing strange, but note the the type of <code>C</code>; is it really a function? We&#8217;ll see later, so let&#8217;s move on:</p> <pre style="color: #585858"><code>scala&gt; A() res: Symbol = 'A scala&gt; B() res: Symbol = 'B</code></pre> <p>Note that <code>A</code> and <code>B</code> can be called in the same way, even though <code>B</code> was defined in terms of an anonymous function.</p> <pre style="color: #585858"><code>scala&gt; C() &lt;console&gt;:7: error: C of type Symbol does not take parameters C() ^</code></pre> <p>Well, seems like we&#8217;ve discovered that <code>C</code> isn&#8217;t really a function and we could have defined it with <code>val</code> instead&#8230; Or? No, it&#8217;s still a function: the function body wasn&#8217;t <em>evaluated</em> until we referred to the function. Look here:</p> <pre style="color: #585858"><code>scala&gt; def t = currentTime t: Long scala&gt; t res: Long = 1296163141271 scala&gt; t res: Long = 1296163141949</code></pre> <p>Clever and useful, but not completely obvious.</p> <p>Back to <code>A</code>, <code>B</code> and <code>C</code>. Let&#8217;s try grabbing a function reference Scheme/Haskell/Python style:</p> <pre style="color: #585858"><code>scala&gt; A res: Symbol = 'A scala&gt; B res: () =&gt; Symbol = &lt;function0&gt; scala&gt; C res: Symbol = 'C</code></pre> <p><code>B</code> worked fine and <code>C</code> was expected because of what we previously discovered, but what about <code>A</code>? It surprised me that it evaluated to <code>'A </code> instead of a function that returns <code>'A</code>. What would the result be if the method took arguments?</p> <pre style="color: #585858"><code>scala&gt; def id[T](x: T) = x id: [T](x: T)T scala&gt; id &lt;console&gt;:7: error: missing arguments for method id in object $iw; follow this method with `_' if you want to treat it as a partially applied function id ^</code></pre> <p>Different result &ndash; yes &ndash; but not valid as is. It is noteworthy that it is possible to referr to <code>id</code> like this:</p> <pre style="color: #585858"><code>scala> Some(123).map(id) res: Option[Int] = Some(123)</code></pre> <p>It seems like the expression is context-sensitive. :/</p> <p>What I&#8217;ve learnt from this that you can&#8217;t consider functions and methods as equals in Scala (like in Python); they live in two different worlds and you need to bridge them explicitly sometimes.</p> <p>To be continued&#8230;</p> <!-- def a() = 'A def b = () => 'B def c = 'C a() b() c() a b c --> Thu, 27 Jan 2011 22:22:40 +0100 http://vemod.net/def-state-confused 2011-01-27T22:22:40.898491+01:00 Using Racket to Configure Apache http://vemod.net/using-racket-to-configure-apache <p><small>Tags: <a href="http://vemod.net/racket" class="tag" rel="tag">Racket</a> and <a href="http://vemod.net/lisp" class="tag" rel="tag">Lisp</a></small></p><p><em>I have a confession to make: I really hate writing boilerplate code.</em></p> <p>I use Apache to serve lots of websites, have many lines of configuration code and have often longed for a way to capture all the patterns and reduce code duplication. I thought about using a macro language like m4 or the C preprocessor or even <a href="http://vemod.net/ruby">Ruby</a> but neither alternative was particulary attractive. Then it hit me that I could describe the Apache configuration with plain <nobr>S-expressions</nobr> and use the full power of <a href="http://vemod.net/racket">Racket</a> to manipulate these and output normal configuration files. What makes this a compelling alternative is of course that <nobr>S-expressions</nobr> allow one to express tree-structured data very succinctly, like here:</p> <pre><code class="scheme pygments"><span class="p">(</span><span class="nf">group</span> <span class="p">(</span><span class="nf">VirtualHost</span> <span class="nv">*</span><span class="p">)</span> <span class="p">(</span><span class="nf">ServerName</span> <span class="nv">www</span><span class="o">.</span><span class="nv">defsoftware</span><span class="o">.</span><span class="nv">se</span><span class="p">)</span> <span class="p">(</span><span class="nf">RedirectPermanent</span> <span class="nv">/</span> <span class="nv">http://defsoftware</span><span class="o">.</span><span class="nv">se/</span><span class="p">))</span> </code></pre> <p>Racket&#8212;being a Lisp equipped with many powerful built-in functions&#8212;makes a full translator for these kind of trees simple to write.</p> <div style="border: 1px solid #E8E8E8; padding: 5px 10px"> <p><strong>Update:</strong> I got an e-mail from <a href="http://barzilay.org/" class="external">Eli Barzilay</a> (of Racket fame) with some valuable feedback on how to improve my code by using functions in the <code>scribble/text</code> and <code>racket/list</code> libraries that are included with Racket. I&#8217;ve updated my code and put the old code at the bottom<sup><a href="#fn1">1</a></sup> for reference. Eli also wrote about using the cool <a href="http://docs.racket-lang.org/scribble/reader-internals.html#(mod-path._at-exp)"><code>at-exp</code></a> reader to mix text and code.</p> </div> <pre><code class="scheme pygments"><span class="p">(</span><span class="nf">require</span> <span class="nv">scribble/text</span> <span class="nv">racket/list</span><span class="p">)</span> <span class="p">(</span><span class="k">define </span><span class="p">(</span><span class="nf">apache-config</span> <span class="o">.</span> <span class="nv">complete-config</span><span class="p">)</span> <span class="p">(</span><span class="k">define </span><span class="p">(</span><span class="nf">format-apache-config</span> <span class="nv">config</span><span class="p">)</span> <span class="p">(</span><span class="nf">match</span> <span class="nv">config</span> <span class="p">((</span><span class="nb">list </span><span class="ss">&#39;group</span> <span class="p">(</span><span class="nb">list </span><span class="nv">group</span> <span class="o">...</span><span class="p">)</span> <span class="nv">directives</span> <span class="o">...</span><span class="p">)</span> <span class="p">(</span><span class="nb">list </span><span class="s">&quot;&lt;&quot;</span> <span class="p">(</span><span class="nf">add-between</span> <span class="nv">group</span> <span class="s">&quot; &quot;</span><span class="p">)</span> <span class="s">&quot;&gt;&quot;</span> <span class="s">&quot;\n&quot;</span> <span class="s">&quot; &quot;</span> <span class="p">(</span><span class="nf">add-newlines</span> <span class="p">(</span><span class="nb">map </span><span class="nv">format-apache-config</span> <span class="nv">directives</span><span class="p">))</span> <span class="s">&quot;\n&quot;</span> <span class="s">&quot;&lt;/&quot;</span> <span class="p">(</span><span class="nf">first</span> <span class="nv">group</span><span class="p">)</span> <span class="s">&quot;&gt;&quot;</span><span class="p">))</span> <span class="p">((</span><span class="nb">list </span><span class="p">(</span><span class="nb">list </span><span class="nv">_</span> <span class="o">...</span><span class="p">)</span> <span class="o">...</span><span class="p">)</span> <span class="p">(</span><span class="nf">add-newlines</span> <span class="p">(</span><span class="nb">map </span><span class="nv">format-apache-config</span> <span class="nv">config</span><span class="p">)))</span> <span class="p">((</span><span class="nb">list </span><span class="nv">_</span> <span class="o">...</span><span class="p">)</span> <span class="p">(</span><span class="nf">add-between</span> <span class="nv">config</span> <span class="s">&quot; &quot;</span><span class="p">))))</span> <span class="p">(</span><span class="nf">output</span> <span class="p">(</span><span class="nf">format-apache-config</span> <span class="nv">complete-config</span><span class="p">))</span> <span class="p">(</span><span class="nf">newline</span><span class="p">))</span> </code></pre> <p>The <code>output</code> function takes care of the indentation in <a href="http://docs.racket-lang.org/scribble/text.html#(part._.Indentation_in_.Preprocessed_output)">a pretty clever way</a>.</p> <p>Now&#8212;equipped with <code>apache-config</code>&#8212;we can start building functions that work with Apache S-expressions:</p> <pre><code class="scheme pygments"><span class="p">(</span><span class="k">define </span><span class="p">(</span><span class="nf">host-redirect</span> <span class="nv">from-hostname</span> <span class="nv">to-hostname</span><span class="p">)</span> <span class="o">`</span><span class="p">(</span><span class="nf">group</span> <span class="p">(</span><span class="nf">VirtualHost</span> <span class="nv">*</span><span class="p">)</span> <span class="p">(</span><span class="nf">ServerName</span> <span class="o">,</span><span class="nv">from-hostname</span><span class="p">)</span> <span class="p">(</span><span class="nf">RedirectPermanent</span> <span class="nv">/</span> <span class="o">,</span><span class="p">(</span><span class="nb">string-append </span><span class="s">&quot;http://&quot;</span> <span class="nv">to-hostname</span> <span class="s">&quot;/&quot;</span><span class="p">))))</span> <span class="p">(</span><span class="nf">apache-config</span> <span class="p">(</span><span class="nf">host-redirect</span> <span class="s">&quot;defsoftware.com&quot;</span> <span class="s">&quot;defsoftware.se&quot;</span><span class="p">)</span> <span class="p">(</span><span class="nf">host-redirect</span> <span class="s">&quot;defsoftware.net&quot;</span> <span class="s">&quot;defsoftware.se&quot;</span><span class="p">))</span> </code></pre> <p>Output:</p> <pre><code class="apache pygments"><span class="nt">&lt;VirtualHost</span> <span class="s">*</span><span class="nt">&gt;</span> <span class="nb">ServerName</span> defsoftware.com <span class="nb">RedirectPermanent</span> / http://defsoftware.se/ <span class="nt">&lt;/VirtualHost&gt;</span> <span class="nt">&lt;VirtualHost</span> <span class="s">*</span><span class="nt">&gt;</span> <span class="nb">ServerName</span> defsoftware.net <span class="nb">RedirectPermanent</span> / http://defsoftware.se/ <span class="nt">&lt;/VirtualHost&gt;</span> </code></pre> <p>Now I&#8217;m happy.</p> <p id="fn1"><sup>1</sup> <a href="#javascript" onclick="javascript:document.getElementById('old-code').setAttribute('style', 'display: block'); this.removeAttribute('href'); return false">Click here to see the old code.</a></p> <div id="old-code" style="display: none"><pre><code class="scheme pygments"><span class="p">(</span><span class="k">define </span><span class="p">(</span><span class="nf">apache-config</span> <span class="o">.</span> <span class="nv">config</span><span class="p">)</span> <span class="p">(</span><span class="k">let </span><span class="nv">self</span> <span class="p">((</span><span class="nf">config-fragment</span> <span class="nv">config</span><span class="p">)</span> <span class="p">(</span><span class="nf">indent</span> <span class="mi">0</span><span class="p">))</span> <span class="p">(</span><span class="k">define </span><span class="p">(</span><span class="nf">line-with-indent</span> <span class="o">.</span> <span class="nv">args</span><span class="p">)</span> <span class="p">(</span><span class="nb">display </span><span class="p">(</span><span class="nb">make-string </span><span class="p">(</span><span class="nb">* </span><span class="mi">2</span> <span class="nv">indent</span><span class="p">)</span> <span class="sc">#\ </span><span class="p">))</span> <span class="p">(</span><span class="nb">apply </span><span class="nv">printf</span> <span class="nv">args</span><span class="p">)</span> <span class="p">(</span><span class="nf">newline</span><span class="p">))</span> <span class="p">(</span><span class="k">define </span><span class="p">(</span><span class="nf">join</span> <span class="nv">xs</span> <span class="p">(</span><span class="nf">sep</span> <span class="s">&quot; &quot;</span><span class="p">))</span> <span class="p">(</span><span class="nf">string-join</span> <span class="p">(</span><span class="nb">map </span><span class="p">(</span><span class="nf">curry</span> <span class="nv">format</span> <span class="s">&quot;~a&quot;</span><span class="p">)</span> <span class="nv">xs</span><span class="p">)</span> <span class="nv">sep</span><span class="p">))</span> <span class="p">(</span><span class="nf">match</span> <span class="nv">config-fragment</span> <span class="p">((</span><span class="nf">list</span><span class="p">)</span> <span class="p">(</span><span class="nf">void</span><span class="p">))</span> <span class="p">((</span><span class="nb">list </span><span class="p">(</span><span class="nb">list </span><span class="nv">nested</span> <span class="o">...</span><span class="p">)</span> <span class="nv">more</span> <span class="o">...</span><span class="p">)</span> <span class="p">(</span><span class="nf">self</span> <span class="nv">nested</span> <span class="nv">indent</span><span class="p">)</span> <span class="p">(</span><span class="nf">self</span> <span class="nv">more</span> <span class="nv">indent</span><span class="p">))</span> <span class="p">((</span><span class="nb">list </span><span class="ss">&#39;group</span> <span class="p">(</span><span class="nb">list </span><span class="nv">group</span> <span class="o">...</span><span class="p">)</span> <span class="nv">directives</span> <span class="o">...</span><span class="p">)</span> <span class="p">(</span><span class="nf">line-with-indent</span> <span class="s">&quot;&lt;~a&gt;&quot;</span> <span class="p">(</span><span class="nf">join</span> <span class="nv">group</span><span class="p">))</span> <span class="p">(</span><span class="nf">self</span> <span class="nv">directives</span> <span class="p">(</span><span class="nf">add1</span> <span class="nv">indent</span><span class="p">))</span> <span class="p">(</span><span class="nf">line-with-indent</span> <span class="s">&quot;&lt;/~a&gt;&quot;</span> <span class="p">(</span><span class="nf">first</span> <span class="nv">group</span><span class="p">)))</span> <span class="p">((</span><span class="nb">list </span><span class="p">(</span><span class="k">or </span><span class="p">(</span><span class="nf">?</span> <span class="nv">string?</span><span class="p">)</span> <span class="p">(</span><span class="nf">?</span> <span class="nv">symbol?</span><span class="p">))</span> <span class="o">...</span><span class="p">)</span> <span class="p">(</span><span class="nf">line-with-indent</span> <span class="p">(</span><span class="nf">join</span> <span class="nv">config-fragment</span><span class="p">))))))</span> </code></pre></div> Sun, 10 Apr 2011 10:52:30 +0200 http://vemod.net/using-racket-to-configure-apache 2011-04-10T10:52:30.911508+02:00 Liquorice http://vemod.net/liquorice <p>I&#8217;m a big fan of liquorice. Here are my top dealers:</p> <h2>1. <a href="http://www.liquirizia.it/" class="external">Amarelli</a></h2> <p>Their spezzatina/spezzata (pastilles of pure liquorice) can&#8217;t be beaten. The variants flavoured with anise are great as well.</p> <h2>2. <a href="http://lakrids.nu/" class="external">Lakrids by Johan Bülow</a></h2> <p>If you like soft liquorice this is for you. Great flavours: <a href="http://lakrids.nu/site/Salmiak/" class="external">salmiak</a>, <a href="http://lakrids.nu/site/Habanero_Chili/" class="external">habanero chili</a> and more. The product names are stupid. Don&#8217;t miss the <a href="http://lakrids.nu/site/Lakrids_Drops/">raw liquorice drops</a>; they are almost as good as Amarelli&#8217;s.</p> <h2>3. <a href="http://www.lakritsfabriken.se/" class="external">Lakritsfabriken</a> (&#8220;The Liquorice Factory&#8221;)</h2> <p>Soft liquorice with simple but good flavours.</p> <div class="full-width" style="text-align: center; margin-bottom: -16px"> <img src="/stuff/amarelli.jpg" alt="" style="width: 50%" /> </div> Thu, 22 Sep 2011 19:24:17 +0200 http://vemod.net/liquorice 2011-09-22T19:24:17.368259+02:00 Music Players for OS X http://vemod.net/music-players-for-os-x <p><small>Tags: <a href="http://vemod.net/mac" class="tag" rel="tag">Mac</a></small></p><ul> <li><a href="http://sbooth.org/Decibel/" class="external">Decibel</a></li> <li><a href="http://flavio.tordini.org/musique" class="external">Musique</a></li> <li><a href="http://www.machinecodex.com/neutrino/" class="external">Neutrino</a></li> <li><a href="http://getsongbird.com/" class="external">Songbird</a></li> <li><a href="http://www.videolan.org/vlc/" class="external"><span class="caps">VLC</span></a></li> <li><a href="http://voxapp.didgeroo.com/" class="external">Vox</a> </li> <li><a href="http://www.winamp.com/mac" class="external">Winamp</a></li> <li><a href="http://www.apple.com/itunes/" class="external">iTunes</a> (<a href="http://vemod.net/itunes-complements">with several shells</a>)</li> </ul> <h2>…with Music Streaming Services</h2> <ul> <li><a href="http://www.wimpmusic.se/" class="external">WiMP</a></li> <li><a href="http://www.spotify.com/" class="external">Spotify</a></li> </ul> Wed, 04 Apr 2012 20:01:40 +0200 http://vemod.net/music-players-for-os-x 2012-04-04T20:01:40.181918+02:00 PostgreSQL http://vemod.net/postgresql <h1 style="text-align:center;"><a href="http://www.postgresql.org/"><img title="PostgreSQL" src="/stuff/postgresql.png" alt="PostgreSQL" /></a></h1> <p style="text-align:center;">Probably the best relational database system in the world.</p> Mon, 28 May 2012 21:16:39 +0200 http://vemod.net/postgresql 2012-05-28T21:16:39.549134+02:00 Termos