<?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>Tobias Aigner &#187; Blog</title>
	<atom:link href="http://tobiasaigner.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://tobiasaigner.com</link>
	<description></description>
	<lastBuildDate>Sun, 27 Oct 2013 09:09:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<atom:link rel='hub' href='http://tobiasaigner.com/?pushpress=hub'/>
		<item>
		<title>Continuous Testing in the Browser</title>
		<link>http://tobiasaigner.com/blog/2013/10/continuous-testing-in-the-browser/</link>
		<comments>http://tobiasaigner.com/blog/2013/10/continuous-testing-in-the-browser/#comments</comments>
		<pubDate>Sat, 26 Oct 2013 21:26:02 +0000</pubDate>
		<dc:creator>tobiasaigner</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://tobiasaigner.com/?p=204</guid>
		<description><![CDATA[When developing in JavaScript I think it is beneficial to have short feedback cycles. For instance, every time I change or write a unit test I want to see the results immediately. The same applies for changes in the application itself. I came across a handy tool named xdootool. It simulates keyboard or mouse presses and [...]]]></description>
			<content:encoded><![CDATA[<p>When developing in JavaScript I think it is beneficial to have short feedback cycles. For instance, every time I change or write a unit test I want to see the results immediately. The same applies for changes in the application itself.</p>
<p>I came across a handy tool named <a title="xdotool" href="http://www.semicomplete.com/projects/xdotool/" target="_blank">xdootool</a>. It simulates keyboard or mouse presses and sends them to a window.</p>
<p>The following bash script sends a reload command to a window named <code>Jasmine Spec Runner</code> every time a file is changed in the directories <code>src</code> and <code>spec</code>.</p>
<div class="highlight">
<pre><span class="c">#!/bin/bash</span>

<span class="k">while </span><span class="nb">true</span>; <span class="k">do</span>
    xdotool search --name <span class="s2">"Jasmine Spec Runner"</span> key --clearmodifiers <span class="s2">"CTRL+R"</span>;
    inotifywait -r -qq -e modify -e delete src spec;
<span class="k">done</span></pre>
</div>
<p>Both <code>xdotool</code> and <code>inotifywait</code> work on Linux based systems. However, equivalent tools or ports may exist for Windows or Mac OS X.</p>
]]></content:encoded>
			<wfw:commentRss>http://tobiasaigner.com/blog/2013/10/continuous-testing-in-the-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accumulating With reduce</title>
		<link>http://tobiasaigner.com/blog/2013/07/accumulating-with-reduce/</link>
		<comments>http://tobiasaigner.com/blog/2013/07/accumulating-with-reduce/#comments</comments>
		<pubDate>Wed, 10 Jul 2013 17:16:33 +0000</pubDate>
		<dc:creator>tobiasaigner</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://tobiasaigner.com/?p=184</guid>
		<description><![CDATA[Recently, I discovered that I needed a way to accumulate results of function calls. My first attempt utilized a recursive function that accumulated the results in a parameter. However, after looking at my solution I noticed that the same behavior can be achieved with Clojure&#8217;s built-in function reduce. To illustrate this point, I&#8217;ll use the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I discovered that I needed a way to accumulate results of function calls. My first attempt utilized a recursive function that accumulated the results in a parameter. However, after looking at my solution I noticed that the same behavior can be achieved with Clojure&#8217;s built-in function <code>reduce</code>.</p>
<p>To illustrate this point, I&#8217;ll use the following example: An ordered list of dates is processed until a specified date. To each matching date a function is applied. In addition, the results of the function calls are accumulated and returned.</p>
<p>My first attempt is shown below:</p>
<div class="highlight">
<pre><span class="p">(</span><span class="kd">ns </span><span class="nv">accumulator.core</span>
  <span class="p">(</span><span class="ss">:require</span> <span class="p">[</span><span class="nv">clj-time.core</span> <span class="ss">:as</span> <span class="nv">t</span><span class="p">]))</span>

<span class="p">(</span><span class="k">def </span><span class="nv">all-dates</span> <span class="p">(</span><span class="nb">reverse </span><span class="p">(</span><span class="nb">map </span><span class="o">#</span><span class="p">(</span><span class="nf">t/date-time</span> <span class="mi">2013</span> <span class="nv">%</span><span class="p">)</span> <span class="p">(</span><span class="nb">range </span><span class="mi">1</span> <span class="mi">13</span><span class="p">))))</span>

<span class="p">(</span><span class="kd">defn </span><span class="nv">get-month</span> <span class="p">[</span><span class="nv">date</span><span class="p">]</span>
  <span class="p">(</span><span class="nf">t/month</span> <span class="nv">date</span><span class="p">))</span>

<span class="p">(</span><span class="kd">defn </span><span class="nv">process-dates-accumulator</span> <span class="p">[</span><span class="nv">all-dates</span> <span class="nv">until</span> <span class="nv">f</span><span class="p">]</span>
  <span class="p">(</span><span class="k">loop </span><span class="p">[</span><span class="nv">dates</span> <span class="nv">all-dates</span>
         <span class="nv">result</span> <span class="p">[]]</span>
    <span class="p">(</span><span class="k">if </span><span class="p">(</span><span class="nf">t/before?</span> <span class="p">(</span><span class="nb">first </span><span class="nv">dates</span><span class="p">)</span> <span class="nv">until</span><span class="p">)</span>
      <span class="nv">result</span>
      <span class="p">(</span><span class="nf">recur</span> <span class="p">(</span><span class="nb">rest </span><span class="nv">dates</span><span class="p">)</span>
             <span class="p">(</span><span class="nb">conj </span><span class="nv">result</span> <span class="p">(</span><span class="nf">f</span> <span class="p">(</span><span class="nb">first </span><span class="nv">dates</span><span class="p">)))))))</span>

<span class="p">(</span><span class="nf">process-dates-accumulator</span> <span class="nv">all-dates</span> <span class="p">(</span><span class="nf">t/date-time</span> <span class="mi">2013</span> <span class="mi">06</span><span class="p">)</span> <span class="nv">get-month</span><span class="p">)</span></pre>
</div>
<p>The <code>process-dates-accumulator</code> iterates over the range of dates. For each date more recent than <code>until</code> the function <code>f</code> is applied. In this example <code>get-month</code> is used. Furthermore, the accumulation is done in <code>results</code>.</p>
<h2>Accumulating With reduce</h2>
<p>Being a functional language Clojure embraces the use of generic combinator functions like <code>map</code> and <code>reduce</code>.</p>
<p>Consider this implementation of the example described above:</p>
<div class="highlight">
<pre><span class="p">(</span><span class="kd">defn </span><span class="nv">process-dates-reduce</span> <span class="p">[</span><span class="nv">all-dates</span> <span class="nv">until</span> <span class="nv">f</span><span class="p">]</span>
  <span class="p">(</span><span class="nb">reduce </span><span class="o">#</span><span class="p">(</span><span class="nb">conj </span><span class="nv">%1</span> <span class="p">(</span><span class="nf">f</span> <span class="nv">%2</span><span class="p">))</span>
          <span class="p">[]</span>
          <span class="p">(</span><span class="nb">filter </span><span class="o">#</span><span class="p">(</span><span class="nb">not </span><span class="p">(</span><span class="nf">t/after?</span> <span class="nv">until</span> <span class="nv">%</span><span class="p">))</span> <span class="nv">all-dates</span><span class="p">)))</span></pre>
</div>
<p>First, the initial list of dates is filtered to include all candidates. Afterwards, <code>reduce</code> accumulates the results of applying the function <code>f</code> to each candidate.</p>
<h2>Conclusion</h2>
<p>As shown above standard functions like <code>reduce</code> offers powerful abstractions. The advantage of using these functions is that those are highly optimized. Moreover, they can be applied to a wide range of situations.</p>
]]></content:encoded>
			<wfw:commentRss>http://tobiasaigner.com/blog/2013/07/accumulating-with-reduce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualizing Recursion</title>
		<link>http://tobiasaigner.com/blog/2013/02/visualizing-recursion/</link>
		<comments>http://tobiasaigner.com/blog/2013/02/visualizing-recursion/#comments</comments>
		<pubDate>Wed, 20 Feb 2013 18:11:40 +0000</pubDate>
		<dc:creator>tobiasaigner</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://tobiasaigner.com/?p=93</guid>
		<description><![CDATA[It seems that when the concept of recursion is introduced, a lot of people (including myself) have a hard time to understand it. Although, it is a powerful technique that is used in important algorithms. In addition, recursion often leads to simple and straightforward solutions. I think one way of making things more clear is [...]]]></description>
			<content:encoded><![CDATA[<p>It seems that when the concept of recursion is introduced, a lot of people (including myself) have a hard time to understand it. Although, it is a powerful technique that is used in important algorithms. In addition, recursion often leads to simple and straightforward solutions.</p>
<p>I think one way of making things more clear is to visualize the process that is generated by a recursive algorithm.</p>
<h2>Fibonacci Numbers</h2>
<p>The classical example for introducing recursion is <a title="Fibonacci Numbers" href="http://en.wikipedia.org/wiki/Fibonacci_number" target="_blank">Fibonacci numbers</a>. Consider this implementation in Python:</p>
<div class="highlight">
<pre><span class="k">def</span> <span class="nf">fib</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
    <span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
        <span class="k">return</span> <span class="mi">0</span>
    <span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
        <span class="k">return</span> <span class="mi">1</span>
    <span class="k">return</span> <span class="n">fib</span><span class="p">(</span><span class="n">n </span><span class="o">- </span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">fib</span><span class="p">(</span><span class="n">n </span><span class="o">- </span><span class="mi">2</span><span class="p">)</span></pre>
</div>
<p>What is interesting about this algorithm is that it generates a process with a tree structure. This is illustrated in the following.</p>
<p><a href="http://tobiasaigner.com/wp-content/uploads/2013/02/Fibonacci-Numbers-Process.png"><img class="size-full wp-image-121 aligncenter" title="Fibonacci-Numbers-Process" src="http://tobiasaigner.com/wp-content/uploads/2013/02/Fibonacci-Numbers-Process.png" alt="" width="615" height="328" /></a></p>
<p>Just by looking at the source code it is hard to reason about its generated process. In contrast, I think the illustration helps.</p>
<p>The picture also shows why this naive implementation is quite slow. A large number of function calls are computed multiple times.</p>
<h2>Merge Sort</h2>
<p>Another classical recursive algorithm is <a title="Merge Sort" href="http://en.wikipedia.org/wiki/Mergesort" target="_blank">Merge sort</a>. It is a divide and conquer algorithm that recursively breaks the input down into smaller problems and merges it back in sorted order. The algorithm is implemented like this (full implementation is available <a title="Merge Sort Implementation in Python" href="http://en.literateprograms.org/Merge_sort_(Python)" target="_blank">here</a>):</p>
<div class="highlight">
<pre><span class="k">def</span> <span class="nf">mergesort</span><span class="p">(</span><span class="n">lst</span><span class="p">):</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">lst</span>
    <span class="n">middle</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">lst</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span>
    <span class="n">left</span> <span class="o">=</span> <span class="n">mergesort</span><span class="p">(</span><span class="n">lst</span><span class="p">[:</span><span class="n">middle</span><span class="p">])</span>
    <span class="n">right</span> <span class="o">=</span> <span class="n">mergesort</span><span class="p">(</span><span class="n">lst</span><span class="p">[</span><span class="n">middle</span><span class="p">:])</span>
    <span class="k">return</span> <span class="n">merge</span><span class="p">(</span><span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">)</span></pre>
</div>
<p>The generated process of sorting 9, 1, 4, 6, 3, 2, 7, 8 is shown below.</p>
<h2><a href="http://tobiasaigner.com/wp-content/uploads/2013/02/Merge-Sort-Process.png"><img class="size-full wp-image-126 aligncenter" title="Merge-Sort-Process" src="http://tobiasaigner.com/wp-content/uploads/2013/02/Merge-Sort-Process.png" alt="" width="581" height="281" /></a></h2>
<h2>Constructing All Permutations</h2>
<p>The problem of constructing all permutations of a string can be solved recursively. For instance, this implementation:</p>
<div class="highlight">
<pre><span class="k">def</span> <span class="nf">permutations</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="n">rest</span><span class="p">):</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">rest</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">string</span><span class="p">]</span>

    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">rest</span><span class="p">)):</span>
        <span class="n">next_rest</span> <span class="o">=</span> <span class="p">[</span><span class="n">rest</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">rest</span><span class="p">))</span> <span class="k">if</span> <span class="n">j</span> <span class="o">!=</span> <span class="n">i</span><span class="p">]</span>
        <span class="n">result</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">permutations</span><span class="p">(</span><span class="n">string</span> <span class="o">+</span> <span class="n">rest</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="s">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">next_rest</span><span class="p">)))</span>
    <span class="k">return</span> <span class="n">result</span></pre>
</div>
<p>produces the following process for &#8220;abc&#8221;.</p>
<p><a href="http://tobiasaigner.com/wp-content/uploads/2013/02/Permutations-Process.png"><img class="size-full wp-image-135 alignnone" title="Permutations-Process" src="http://tobiasaigner.com/wp-content/uploads/2013/02/Permutations-Process.png" alt="" width="721" height="337" /></a></p>
<p>Moreover, the resulting permutations of &#8220;abc&#8221; reside at the leaves of the process tree: &#8220;abc&#8221;, &#8220;acb&#8221;, &#8220;bac&#8221;, &#8220;bca&#8221;, &#8220;cab&#8221; and &#8220;cba&#8221;.</p>
<h2>Conclusion</h2>
<p>Of course, there are different strategies that help with understanding recursive processes. <span style="line-height: 1.714285714; font-size: 1rem;">I think visualizing the process of a recursive algorithm is very helpful. Especially in the beginning.</span></p>
<h2>Further Reading</h2>
<ul>
<li><a title="Structure and Interpretation of Computer Programs" href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2" target="_blank">Structure and Interpretation of Computer Programs (especially Section 1.2)</a></li>
<li><a title="The Little Schemer" href="http://www.amazon.com/gp/product/0262560992/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0262560992&amp;linkCode=as2&amp;tag=tobiasaignerc-20" target="_blank"><span style="font-size: 1rem; line-height: 1.714285714;">The Little Schemer</span></a></li>
<li><a title="The Algorithm Design Manual" href="http://www.amazon.com/gp/product/1849967202/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1849967202&amp;linkCode=as2&amp;tag=tobiasaignerc-20" target="_blank"><span style="font-size: 1rem; line-height: 1.714285714;">The Algorithm Design Manual</span></a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tobiasaigner.com/blog/2013/02/visualizing-recursion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote git Repository Over ssh</title>
		<link>http://tobiasaigner.com/blog/2013/02/remote-git-repository-over-ssh/</link>
		<comments>http://tobiasaigner.com/blog/2013/02/remote-git-repository-over-ssh/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 20:38:11 +0000</pubDate>
		<dc:creator>tobiasaigner</dc:creator>
				<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://tobiasaigner.com/?p=45</guid>
		<description><![CDATA[A feature of git I think is useful sometimes is the ability to utilize the ssh protocol. Therefore, it is possible to work with a remote repository by using an existing ssh configuration. Server-Side On the server-side a bare repository has to be created $ mkdir remote-project.git $ cd remote-project.git $ git init --bare Client-Side [...]]]></description>
			<content:encoded><![CDATA[<p>A feature of git I think is useful sometimes is the ability to utilize the ssh protocol. Therefore, it is possible to work with a remote repository by using an existing ssh configuration.</p>
<h2>Server-Side</h2>
<p>On the server-side a <a href="http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html" target="_blank">bare repository</a> has to be created</p>
<div class="highlight">
<pre>$ mkdir remote-project.git
$ cd remote-project.git
$ git init --bare</pre>
</div>
<h2>Client-Side</h2>
<p>In contrast, on the client side it is now possible to clone the remote repository</p>
<div class="highlight">
<pre>$ git clone ssh://user@server/path/to/remote-project.git</pre>
</div>
<p>Afterwards, changes can be pushed to the server</p>
<div class="highlight">
<pre>$ cd remote-project
&lt;add and commit your changes&gt;
$ git push origin master</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://tobiasaigner.com/blog/2013/02/remote-git-repository-over-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Welcome</title>
		<link>http://tobiasaigner.com/blog/2012/12/welcome/</link>
		<comments>http://tobiasaigner.com/blog/2012/12/welcome/#comments</comments>
		<pubDate>Wed, 26 Dec 2012 19:34:39 +0000</pubDate>
		<dc:creator>tobiasaigner</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://tobiasaigner.com/?p=1</guid>
		<description><![CDATA[Welcome on my blog! This is the first post on this page. Which kind of content can you expect to find here? I am planning to write about programming, technology, ideas and things in general I am interested in. A big thanks to Olli for hosting these pages. Hopefully, you will find useful information and [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome on my blog! This is the first post on this page.</p>
<p>Which kind of content can you expect to find here? I am planning to write about programming, technology, ideas and things in general I am interested in.</p>
<p>A big thanks to <a title="Olli" href="http://www.okraits.de/" target="_blank">Olli</a> for hosting these pages.</p>
<p>Hopefully, you will find useful information and enjoy reading the articles.</p>
]]></content:encoded>
			<wfw:commentRss>http://tobiasaigner.com/blog/2012/12/welcome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
