<?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>Jan Pöschko&#039;s space &#187; Coding</title>
	<atom:link href="http://www.poeschko.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.poeschko.com</link>
	<description>Coding, Math, Photography, and Life.</description>
	<lastBuildDate>Tue, 31 Jan 2012 00:29:31 +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>Highlighting changes in LaTeX</title>
		<link>http://www.poeschko.com/2012/01/highlighting-changes-in-latex/</link>
		<comments>http://www.poeschko.com/2012/01/highlighting-changes-in-latex/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 00:19:04 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[publishing]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=1016</guid>
		<description><![CDATA[I want to shortly point out how convenient it is in LaTeX to highlight changes you made to a document, let&#8217;s say for a journal resubmission. That is, you want to show your readers which parts you have added or &#8230; <a href="http://www.poeschko.com/2012/01/highlighting-changes-in-latex/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I want to shortly point out how convenient it is in LaTeX to highlight changes you made to a document, let&#8217;s say for a journal resubmission. That is, you want to show your readers which parts you have added or deleted. In my opinion, coloring additions green, deletions red, and additionally marking edits with bars in the page margin is a good way of doing that.</p>
<p><img src="http://www.poeschko.com/wp-content/uploads/2012/01/highlighting.png" alt="" title="highlighting" width="723" height="26" class="alignnone size-full wp-image-1021" /></p>
<p>That can be achieved pretty easily with two packages in LaTeX: <a href="http://www.ctan.org/pkg/xcolor">xcolor</a> and <a href="http://ctan.org/pkg/changebar">changebar</a>.</p>
<pre class="brush: latex; title: ; notranslate">
\usepackage{xcolor}
\usepackage{changebar}
</pre>
<p>Using these, we can define the following commands to mark up additions and deletions:</p>
<pre class="brush: latex; title: ; notranslate">
\newcommand{\removed}[1]{\cbstart\removedfragile{#1}\cbend{}}
\newcommand{\removedfragile}[1]{{\color{red}{#1}}{}}
\newcommand{\added}[1]{\cbstart\addedfragile{#1}\cbend{}}
\newcommand{\addedfragile}[1]{{\color{green!50!black}{#1}}{}}
\newcommand{\changed}[2]{\added{#1}\removed{#2}}
</pre>
<p>At least from my experience, change bars don&#8217;t work in &#8220;fragile&#8221; environments such as float captions, that&#8217;s why there are versions of the commands that only color the edit. With this, we could already do</p>
<pre class="brush: latex; title: ; notranslate">
This \changed{new replacement}{text} is replaced.
</pre>
<p>to produce the above image. However, what if we want to see the final version only, without the change markup? Let&#8217;s define a new <code>if</code></p>
<pre class="brush: latex; title: ; notranslate">
\newif\ifdiff
\difffalse
</pre>
<p>and then conditionally define our markup functions:</p>
<pre class="brush: latex; title: ; notranslate">
\ifdiff
  % the above definitions of removed* and added*
\else
  \newcommand{\removed}[1]{} % non-markup version
  \newcommand{\removedfragile}[1]{}
  \newcommand{\added}[1]{#1}
  \newcommand{\addedfragile}[1]{#1}
\fi
</pre>
<p>Now we can select whether we want to display the edits by setting <code>diff</code> to <code>true</code> or <code>false</code>. You and your reviewers will like it.</p>
<p>You can download the <a href="/wp-content/uploads/2012/01/highlightingchanges.tex" rel="" class="mtli_attachment mtli_tex">full source code of a sample page</a>, the corresponding <a href="/wp-content/uploads/2012/01/highlightingchanges.pdf" rel="" class="mtli_attachment mtli_pdf">output with differences shown</a> and <a href="/wp-content/uploads/2012/01/highlightingchanges_final.pdf" rel="" class="mtli_attachment mtli_pdf">without markup</a>.</p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=1016&amp;md5=437738f6166be0e8e5bf3b6687828b79" title="Flattr" target="_blank"><img src="http://www.poeschko.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.poeschko.com/2012/01/highlighting-changes-in-latex/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Opinionated Type</title>
		<link>http://www.poeschko.com/2012/01/opinionated-type/</link>
		<comments>http://www.poeschko.com/2012/01/opinionated-type/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 18:08:17 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[typography]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=932</guid>
		<description><![CDATA[Beautiful typography: Opinionated Type.]]></description>
			<content:encoded><![CDATA[<p>Beautiful typography: <a href='http://opinionatedtype.wordpress.com/'>Opinionated Type</a>.</p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=932&amp;md5=ada438b2432f4e7f1ad1c48f842e5299" title="Flattr" target="_blank"><img src="http://www.poeschko.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.poeschko.com/2012/01/opinionated-type/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extreme Geeky Tidying Up: Sorting image colors with Python and Hilbert curves</title>
		<link>http://www.poeschko.com/2011/09/extreme-geeky-tidying-up/</link>
		<comments>http://www.poeschko.com/2011/09/extreme-geeky-tidying-up/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 07:42:31 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[colors]]></category>
		<category><![CDATA[geeky]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=802</guid>
		<description><![CDATA[There are levels of tidiness. Tidy. Very Tidy. Totally Deranged Tidy. Geeky Tidy. After sharing these awesome pictures by the Swiss &#8220;artist&#8221; Ursus Wehrli with the world, Martin N. pointed out that there is still a severe issue with the &#8230; <a href="http://www.poeschko.com/2011/09/extreme-geeky-tidying-up/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>There are levels of tidiness.</p>
<p>Tidy.<br />
Very Tidy.<br />
Totally Deranged Tidy.</p></blockquote>
<p>Geeky Tidy.</p>
<p>After sharing <a href="http://www.npr.org/blogs/krulwich/2011/09/12/140394807/extreme-tidying-up">these awesome pictures by the Swiss &#8220;artist&#8221; Ursus Wehrli</a> with <a href="http://www.facebook.com">the world</a>, Martin N. pointed out that there is still a severe issue with the Badewiese: People are not even sorted by the colors of their swimsuits! Adding to that, trees are placed in total chaos, not to speak of their leaves; clearly, there are tiny waves on the water; and one can almost see blades of grass not being sorted by size. Obviously, this picture needed further tidying up.</p>
<p><a href="http://www.poeschko.com/2011/09/extreme-geeky-tidying-up/park-2/" rel="attachment wp-att-809"><img src="http://www.poeschko.com/wp-content/uploads/2011/09/tidy.jpg" alt="" title="park-2" width="462" height="395" class="alignnone size-full wp-image-809" /></a><br />
<small>&copy; Ursus Wehrli</small></p>
<p>Python to the rescue! 5 minutes, 10 lines, and half a beer later I had a program that would load the image, re-arrange its pixels, and save it again:</p>
<pre class="brush: python; title: ; wrap-lines: true; notranslate">
from PIL import Image

old = Image.open(&quot;tidy.jpg&quot;)
colors = old.getcolors(old.size[0] * old.size[1])
data = []
for count, color in colors:
    data.extend(count * [color])
data.sort()
new = Image.new('RGB', old.size)
new.putdata(data)
new.save(&quot;naive_tidy.png&quot;)
</pre>
<p>This yields the following picture:<br />
<a href="http://www.poeschko.com/2011/09/extreme-geeky-tidying-up/naive_tidy/" rel="attachment wp-att-808"><img src="http://www.poeschko.com/wp-content/uploads/2011/09/naive_tidy.png" alt="" title="naive_tidy" width="462" height="395" class="alignnone size-full wp-image-808" /></a></p>
<p>So how was this &#8220;re-arrangement&#8221; performed? In a naïve approach, I just sorted the RGB values of the pixels, which is why there are many consecutive lines (of equal reds) with abrupt changes. Ordered, but far from being tidy.</p>
<p>Let&#8217;s try another color space and sort by <a href="http://en.wikipedia.org/wiki/HSL_and_HSV">HSV</a> values—a smooth hue should look better, after all. So by adding</p>
<pre class="brush: python; title: ; notranslate">
import colorsys
</pre>
<p>and changing one line to</p>
<pre class="brush: python; title: ; notranslate">
data.sort(key=lambda rgb: colorsys.rgb_to_hsv(*rgb))
</pre>
<p>we get the following image:<br />
<a href="http://www.poeschko.com/2011/09/extreme-geeky-tidying-up/hsv_tidy/" rel="attachment wp-att-814"><img src="http://www.poeschko.com/wp-content/uploads/2011/09/hsv_tidy.png" alt="" title="hsv_tidy" width="462" height="395" class="alignnone size-full wp-image-814" /></a></p>
<p>More beautiful, but the red and white noise in the end doesn&#8217;t look tidy at all. We want a smooth transition through all given colors. <a href="http://en.wikipedia.org/wiki/Hilbert_curve">Hilbert curves</a> to the rescue! Found a ready-to-be-used <a href="http://www.tiac.net/~sw/2008/10/Hilbert/hilbert.py">Hilbert walk implementation</a>, added</p>
<pre class="brush: python; title: ; notranslate">
import hilbert
</pre>
<p>and changed the sorting once again to</p>
<pre class="brush: python; title: ; notranslate">
data.sort(key=hilbert.Hilbert_to_int)
</pre>
<p>to get this image:<br />
<a href="http://www.poeschko.com/2011/09/extreme-geeky-tidying-up/geeky_tidy/" rel="attachment wp-att-821"><img src="http://www.poeschko.com/wp-content/uploads/2011/09/geeky_tidy.png" alt="" title="geeky_tidy" width="462" height="395" class="alignnone size-full wp-image-821" /></a></p>
<p>Mathematical computer science just made the world a little tidier.</p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=802&amp;md5=2e08a912f5f97dd17a066fcae81a4397" title="Flattr" target="_blank"><img src="http://www.poeschko.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.poeschko.com/2011/09/extreme-geeky-tidying-up/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Death and reincarnation of some bitten fruit</title>
		<link>http://www.poeschko.com/2011/08/death-and-reincarnation/</link>
		<comments>http://www.poeschko.com/2011/08/death-and-reincarnation/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 06:51:29 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[stanford]]></category>
		<category><![CDATA[steak]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=667</guid>
		<description><![CDATA[Usually, when I turn on my computer, I don&#8217;t spend a second thinking about whether it will actually turn on. From now on I probably will. I just wanted to resume from sleep (which is the usual mode of non-operation &#8230; <a href="http://www.poeschko.com/2011/08/death-and-reincarnation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Usually, when I turn on my computer, I don&#8217;t spend a second thinking about whether it will actually turn on. From now on I probably will.</p>
<p>I just wanted to resume from sleep (which is the usual mode of non-operation for it), but the screen remained black and nothing happened. That&#8217;s not totally unusual, as sometimes something in the computer decides it doesn&#8217;t want to wake up, in which case you have to <a href="http://www.youtube.com/watch?v=nn2FB1P_Mn8">turn it off and on again</a>. That&#8217;s what I did, but in this unique case, it still remained black. The front light was on and their was some noise from the fan, but nothing more. No <a href="http://www.youtube.com/watch?v=i9qOJqNjalE">Mac startup sound</a>, which I never particularly liked, but in this case would have loved to hear.</p>
<p>Letting it rest for a while, removing the battery, <a href="http://support.apple.com/kb/ht1379">resetting the PRAM</a>, switching RAM modules, nothing helped. Finally, I made an appointment with the <a href="http://www.apple.com/retail/geniusbar/">Apple Genius Bar</a>, conveniently located a few blocks away in the Stanford Shopping Center.</p>
<p>After a few experiments by my nice &#8220;genius,&#8221; he told me it would be $310 to have my notebook (a mid-2008 15&#8243; MacBook Pro 2.4 GHz Intel Core 2 Duo with 4 GB RAM running Leopard, by the way) repaired. Not too cheap, but I would have paid anything to be able to work on my stuff again. Luckily though, the guy continued his research and finally told me the repair would be free—even though warranty had expired about two years ago!</p>
<p>Apparently, it was another case of this <a href="http://support.apple.com/kb/TS2377">well-known graphics issue</a>. Actually, I had occasionally noticed some of the described symptoms and was aware of this issue, I just had not thought that it could also cause the computer not to start up at all.</p>
<p>Even better, the guy told me I could probably get my computer back in one or two days—which would have been a Sunday, amazingly enough. And I would not have to worry about my data, the hard drive was safe.</p>
<p>As if that had not been good enough, they called me on the same day at 6.30 pm that my computer was ready for pickup! (I had been in the store at 10.45 am before.) I got there at around 8 pm (yes, my Austrian friends, they&#8217;re still open at that time, usually even on Sundays!) and got back my ready-to-rock shiny-new MacBook again. Apparently, they had even polished it.</p>
<p>One could argue that this problem shouldn&#8217;t have occurred in the first place, but still, well done, Apple, awesome support! Even if I had concerns about Apple&#8217;s <a href="http://derstandard.at/1311803099280/Apple-laesst-Vertrieb-von-Galaxy-Tab-101-in-Europa-stoppen">policy</a> recently (and <a href="http://derstandard.at/1303291562055/Ortsdaten-Apple-Betreiben-kein-iPhone-Tracking-Fehler-passiert">not only recently</a>), right now, I love you again.</p>
<p>Had some good steaks to celebrate this quick reincarnation.</p>
<p><a href="http://www.poeschko.com/2011/08/death-and-reincarnation/steak-3/" rel="attachment wp-att-685"><img src="http://www.poeschko.com/wp-content/uploads/2011/08/Steak1.jpg" alt="" title="Steak" width="1024" height="683" class="alignnone size-full wp-image-685" /></a></p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=667&amp;md5=8d67a1fb723fa8868ad002b3ae7327f3" title="Flattr" target="_blank"><img src="http://www.poeschko.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.poeschko.com/2011/08/death-and-reincarnation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working and networking</title>
		<link>http://www.poeschko.com/2011/07/working-and-networking/</link>
		<comments>http://www.poeschko.com/2011/07/working-and-networking/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 09:01:16 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[stanford]]></category>
		<category><![CDATA[twex]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=591</guid>
		<description><![CDATA[With the slowly-becoming-usual delay, here&#8217;s what happened last week: On Monday, I was invited to the Innovation Ecosystems Summit by Martha Russell. Have a look at the authors of Semantic Analysis of Energy-Related Conversations in Social Media: A Twitter Case &#8230; <a href="http://www.poeschko.com/2011/07/working-and-networking/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>With the slowly-becoming-usual delay, here&#8217;s what happened last week: On Monday, I was invited to the <a href="http://mediax.stanford.edu/summit2011.html">Innovation Ecosystems Summit</a> by <a href="http://mediax.stanford.edu/martha_russell.html">Martha Russell</a>. Have a look at the authors of <a href="http://www.innovation-ecosystems.org/2011/05/02/semantic-analysis-of-energy-related-conversations-in-social-media-a-twitter-case-study/">Semantic Analysis of Energy-Related Conversations in Social Media: A Twitter Case Study</a> and you&#8217;ll know why I was invited. <img src='http://www.poeschko.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>As expected, the conference was targeted more towards economics, which is of course not my primary scientific field of interest, but nevertheless it was very interesting. Listening to people like the director of an IBM research center at the world-wide hub of high-tech innovation feels just right. I particularly liked the session about data mining and visualization, starring charismatic Sean Gourley from <a href="http://www.quid.com/">Quid</a> (a nice combination of data mining and visualization to locate innovative startups) and Mathieu Bastian from LinkedIn (who&#8217;s working on the awesome graph exploration tool <a href="http://gephi.org/">Gephi</a>). The food was pretty good as well. <img src='http://www.poeschko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>On Tuesday, I continued working on stuff we (Mark, Tania, Markus, me) would discuss in our meeting on Wednesday. Basically, my work here aims at two things:</p>
<ol>
<li>understanding the collaboration of experts in the development of <a href="http://www.who.int/classifications/icd/revision/en/index.html">ICD-11</a>, for instance by finding models to predict which concepts are likely to be changed (thereby measuring their &#8220;maturity&#8221;), and
<li>creating tools to examine and ideally improve collaboration.
</ol>
<p>While the first part naturally involves all sorts of statistics and machine learning stuff, the second part is rather of an engineering type. Interestingly enough, my <a href="http://twex.poeschko.com">TwitterExplorer</a> (&#8220;twex&#8221;) comes into play again here, as it already provides the basics for browsing the ontology of diseases, which basically is a huge graph of diseases and categories they are in. People seem to like it.</p>
<p>I kept talking about it on Thursday, when I attended a presentation at the <a href="http://www.triplehelixconference.org/">Triple Helix Conference</a> by <a href="http://www.triplehelixconference.org/paper-presenters-gallery/camilla-yu.html">Camilla Yu</a>, who used twex to analyze &#8220;branding and reputation of innovation hubs&#8221;. Moreover, I had a nice conversation with <a href="http://www.triplehelixconference.org/keynote-speakers/jukka-huhtamaki.html">Jukka Huhtamäki</a> from Finland about the potential future of a general interactive, Web-based network explorer. I&#8217;m really excited about working on it—as soon as I have time.</p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=591&amp;md5=af573328dbc568e1eac3267ff31aca03" title="Flattr" target="_blank"><img src="http://www.poeschko.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.poeschko.com/2011/07/working-and-networking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Batch-converting CSV to Google Maps KML to illustrate Slovenian name signs in Carinthia</title>
		<link>http://www.poeschko.com/2011/04/csv2kml/</link>
		<comments>http://www.poeschko.com/2011/04/csv2kml/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 11:45:36 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[geeky]]></category>
		<category><![CDATA[Kärnten]]></category>
		<category><![CDATA[kml]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[Ortstafeln]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=285</guid>
		<description><![CDATA[Inspired by a tweet by DaddyD (which is totally true: the &#8220;graphic&#8221; by Kleine Zeitung is just a failed table), I figured there should be an easy way of generating maps from a set of places. In this case, to &#8230; <a href="http://www.poeschko.com/2011/04/csv2kml/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Inspired by <a href="http://twitter.com/#!/DaddyD/status/62750388553662464">a tweet by DaddyD</a> (which is totally true: the <a href="http://www.kleinezeitung.at/system/galleries/upload/2/6/5/2717365/grafik_neu.pdf" rel="" class="mtli_attachment mtli_pdf">&#8220;graphic&#8221; by Kleine Zeitung</a> is just a failed table), I figured there should be an easy way of generating maps from a set of places. In this case, to illustrate the places in Carinthia affected by the new agreements concerning Slovenian name signs. Google Maps to the rescue! It allows you to create custom maps with markers (and lines, polygons, etc.) at arbitrary positions—the problem is just that it&#8217;s pretty complicated to do that by hand for a bunch of places.</p>
<p>Being a geek, I wanted to automate that, of course. The workflow would be as follows:</p>
<ol>
<li>create a spreadsheet with columns for the place name, additional text (in this case, the Slovenian place name), additional information for the Google geocoder (region etc.), and the desired marker color, using OpenOffice or whatever,
<li>export that spreadsheet to CSV,
<li>have a Python script batch-geocode all the places and put corresponding markers in a <a href="http://code.google.com/apis/kml/documentation/">KML</a> file,
<li>import the KML file to Google Maps.
</ol>
<p>You can download the UTF-8-encoded <a href="http://www.poeschko.com/media/csv2kml/data.csv">CSV file for the Slovenian place names</a>.<br />
However, the interesting part is the Python script, of course:</p>
<pre class="brush: python; title: ; wrap-lines: true; notranslate">
from geopy import geocoders
import csv

geocoder = geocoders.Google()
data = csv.reader(open('data.csv', 'r'), delimiter='\t', quotechar='&quot;')
kml = []
print &quot;Geocoding places&quot;
for line in data:
	place, place_extra, sub_region, region, country, color = [value.decode('utf-8') for value in line]
	if not color:
		color = 'blue'
	query = place
	if sub_region: query += u&quot;, &quot; + sub_region
	if region: query += u&quot;, &quot; + region
	if country: query += u&quot;, &quot; + country
	try:
		name, (lat, lng) = geocoder.geocode(query.encode('utf-8'), exactly_one=True)
		kml.append((u&quot;&lt;Placemark&gt;&lt;name&gt;%s/%s&lt;/name&gt;&quot; + \
			u&quot;&lt;Style&gt;&lt;IconStyle&gt;&lt;Icon&gt;&lt;href&gt;http://www.google.com/intl/en_us/mapfiles/ms/icons/%s-dot.png&lt;/href&gt;&lt;/Icon&gt;&lt;/IconStyle&gt;&lt;/Style&gt;&quot; + \
			u&quot;&lt;Point&gt;&lt;coordinates&gt;%s,%s&lt;/coordinates&gt;&lt;/Point&gt;&lt;/Placemark&gt;&quot;) % \
			(place, place_extra, color, lng, lat))
	except ValueError:
		print u&quot;Place not found: %s/%s&quot; % (place, place_extra)
print &quot;Writing data.kml&quot;
kml = u&quot;\n&quot;.join(kml)
kml = u&quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;kml xmlns=&quot;http://www.opengis.net/kml/2.2&quot;&gt;
&lt;Document&gt;
&lt;name&gt;Exported KML data&lt;/name&gt;
%s
&lt;/Document&gt;
&lt;/kml&gt;
&quot;&quot;&quot; % kml
out = open('data.kml', 'w')
out.write(kml.encode('utf-8'))
out.close()
print &quot;Done&quot;
</pre>
<p>You can also <a href="http://www.poeschko.com/media/csv2kml/csv2kml.py">download the whole Python script</a>. Given the file <code>data.csv</code>, it looks up all the place names using the <a href="http://code.google.com/p/geopy/">geopy Google geocoder</a> and exports the places to a KML file <code>data.kml</code>. You can download the <a href="http://www.poeschko.com/media/csv2kml/data.kml">resulting KML file</a>.</p>
<p>The KML file can then be easily imported into a custom Google Maps map, which results in this <a href="http://maps.google.at/maps/ms?ie=UTF8&#038;hl=de&#038;t=h&#038;msa=0&#038;msid=216032231777378797586.0004a1ce9da3246840e73&#038;z=8">map</a>:<br />
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.at/maps/ms?ie=UTF8&amp;hl=de&amp;t=h&amp;msa=0&amp;msid=216032231777378797586.0004a1ce9da3246840e73&amp;ll=46.551946,13.987835&amp;spn=0.228871,1.81685&amp;output=embed"></iframe><br /><small><a href="http://maps.google.at/maps/ms?ie=UTF8&amp;hl=de&amp;t=h&amp;msa=0&amp;msid=216032231777378797586.0004a1ce9da3246840e73&amp;ll=46.551946,13.987835&amp;spn=0.228871,1.81685&amp;source=embed" style="color:#0000FF;text-align:left">Kärntner Ortstafeln</a> auf einer größeren Karte anzeigen</small></p>
<p>Blue markers denote places with Slovenian names according to the old regulation and new VfGH decisions since 2001; red markers represent places with a Slovenian population of more than 17.5%; and yellow markers are considered &#8220;room for negotation&#8221;. </p>
<p>The general CSV-to-KML converter could be used for many more beautiful maps, of course.</p>
<p>UPDATE: Made some manual corrections to the markers, thanks to comments on <a href="http://twitter.com/#!/georgholzer/status/62851444277121024">Twitter</a> and <a href="http://derstandard.at/1303291368271/Ortstafelstreit-Heute-wieder-in-der-Zielgeraden">derStandard.at</a>.</p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=285&amp;md5=4c85a6e416198a23bcec729849f3cced" title="Flattr" target="_blank"><img src="http://www.poeschko.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.poeschko.com/2011/04/csv2kml/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Mathics goes open source</title>
		<link>http://www.poeschko.com/2011/03/mathics-goes-open-source/</link>
		<comments>http://www.poeschko.com/2011/03/mathics-goes-open-source/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 16:08:47 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[mathematica]]></category>
		<category><![CDATA[mathics]]></category>
		<category><![CDATA[sage]]></category>
		<category><![CDATA[sympy]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=271</guid>
		<description><![CDATA[I&#8217;ve been working a lot on Mathics again during the last weeks. All towards the goal that I&#8217;ve had in mind for a long time: to release it as open source. After all, that&#8217;s the only thing that could set &#8230; <a href="http://www.poeschko.com/2011/03/mathics-goes-open-source/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working a lot on Mathics again during the last weeks. All towards the goal that I&#8217;ve had in mind for a long time: to release it as open source. After all, that&#8217;s the only thing that could set Mathics apart from <a href="http://www.wolfram.com/mathematica/">Mathematica</a>—the only thing that&#8217;s not so good about Mathematica is that it&#8217;s not free, neither as in freedom nor as in free beer.</p>
<p>If you wonder what Mathics is: it&#8217;s a general-purpose computer algebra system implementing the awesome Mathematica mathematics/programming language. Some of its most important features are </p>
<ul>
<li>a powerful functional programming language,
<li>a system driven by pattern matching and rules application,
<li>rationals, complex numbers, and arbitrary-precision arithmetic,
<li>lots of list and structure manipulation routines,
<li>an interactive graphical user interface right in the Web browser using  MathML (apart from a command line interface),
<li>creation of graphics (e.g. plots) and display in the browser using SVG,
<li>an online version at <a href="http://www.mathics.net">www.mathics.net</a> for instant access,
<li>export of results to LaTeX (using Asymptote for graphics),
<li>a very easy way of deﬁning new functions in Python,
<li>an integrated documentation and testing system.
</ul>
<p>Read the <a href="http://www.mathics.org/doc/mathics.pdf" rel="" class="mtli_attachment mtli_pdf">manual</a> to learn more about the over 350 built-in functions and symbols in Mathics.</p>
<p>The actual heavy math stuff (like integration) is mostly done by the Python package <a href="http://code.google.com/p/sympy/">SymPy</a>. There is optional support for functions depending on <a href="http://www.sagemath.org/">Sage</a> as well. Despite &#8220;out-sourcing&#8221; most mathematical functions, Mathics has more than 20,000 lines of Python code already, dealing with much non-trivial stuff such as parsing Mathematica input, pattern matching, graphics generation, etc.</p>
<p>Unfortunately, <a href="http://www.getfirefox.com">Firefox</a> is the only browser supported so far, because no other browser supports MathML yet. However, this is expected to change pretty soon when Webkit (used by Safari and Chrome) adds MathML support. I wonder whether Internet Explorer will ever get that far.</p>
<p>I set up a project homepage at <a href="http://www.mathics.org">www.mathics.org</a> for organizational stuff, while <a href="http://www.mathics.net">www.mathics.ne</a>t is still the place for the online interface of Mathics. The source code is hosted at <a href="https://github.com/poeschko/mathics">github</a>.</p>
<p>I hope that one day there will be developers joining me. Contact me if you want to get involved!</p>
<p><a href="http://www.poeschko.com/wp-content/uploads//Mathics_flower1.png"><img src="http://www.poeschko.com/wp-content/uploads//Mathics_flower1.png" alt="" title="Mathics_flower" width="762" height="493" class="alignnone size-full wp-image-277" /></a><br />
<a href="http://www.poeschko.com/wp-content/uploads//Mathics_plot.png"><img src="http://www.poeschko.com/wp-content/uploads//Mathics_plot.png" alt="" title="Mathics_plot" width="762" height="493" class="alignnone size-full wp-image-278" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poeschko.com/2011/03/mathics-goes-open-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TwitterExplorer</title>
		<link>http://www.poeschko.com/2011/01/twitterexplorer/</link>
		<comments>http://www.poeschko.com/2011/01/twitterexplorer/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 09:29:12 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webscience]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=170</guid>
		<description><![CDATA[Finished my work on TwitterExplorer (as far as work can ever be finished). It now features a huge, interactive clustered network of Twitter #hashtags. There are detailed statistics, timelines, and a classification (attempt) for each hashtag, plus a separate clustered &#8230; <a href="http://www.poeschko.com/2011/01/twitterexplorer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Finished my work on <a href="http://twex.poeschko.com">TwitterExplorer</a> (as far as work can ever be finished). It now features a huge, interactive clustered network of Twitter #hashtags. There are detailed statistics, timelines, and a classification (attempt) for each hashtag, plus a separate clustered network of the 3-hop network around it.</p>
<p>This is one more Python/<a href="http://www.djangoproject.org">Django</a> application (for details, see the <a href="http://twex.poeschko.com/about/">about page</a>). Especially the interactive graph involved a lot of JavaScript tweaks with the <a href="http://thejit.org">JavaScript InfoVis Toolkit</a>, although I&#8217;m not really sure whether it was really worth using it—in the end, I might have needed less code by starting from scratch, using just <a href="http://jquery.com/">jQuery</a> and and the HTML5 canvas element.</p>
<p>This is also the first time I placed a <a href="http://www.flattr.com">flattr</a> button <a href="http://twex.poeschko.com/about/">somewhere</a>. Let&#8217;s see how much it generates—I don&#8217;t have any expectations.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poeschko.com/2011/01/twitterexplorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone SDK for MacOS X 10.5 Leopard</title>
		<link>http://www.poeschko.com/2010/12/iphone-sdk-for-macos-x-10-5-leopard/</link>
		<comments>http://www.poeschko.com/2010/12/iphone-sdk-for-macos-x-10-5-leopard/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 18:04:54 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=159</guid>
		<description><![CDATA[Thanks to Drop The Nerd, found a way of installing a version of the iPhone SDK (3.1.3) that still supports Leopard: Download from apple.com. Maybe I should&#8217;ve already switched to Snow Leopard, but actually I&#8217;m not missing much in Leopard &#8230; <a href="http://www.poeschko.com/2010/12/iphone-sdk-for-macos-x-10-5-leopard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://www.dropthenerd.com/iphone-sdk-3-1-3-download-for-leopard-if-you-dont-have-snow-leopard/">Drop The Nerd</a>, found a way of installing a version of the iPhone SDK (3.1.3) that still supports Leopard: <a href="http://developer.apple.com/ios/download.action?path=%2Fiphone%2Fiphone_sdk_3.1.3__final%2Fiphone_sdk_3.1.3_with_xcode_3.1.4__leopard__9m2809a.dmg">Download from apple.com</a>. Maybe I should&#8217;ve already switched to Snow Leopard, but actually I&#8217;m not missing much in Leopard (at least not much that Snow Leopard provides, I think), so I feel like I can still wait for &#8220;Lion&#8221;.</p>
<p>Now I will first create a GUI mockup for our software engineering project (&#8220;car sharing application&#8221;), and then, some day, there might be a <a href="http://www.tripedia.org/">tripedia</a> iPhone app&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poeschko.com/2010/12/iphone-sdk-for-macos-x-10-5-leopard/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code line count</title>
		<link>http://www.poeschko.com/2010/11/code-line-count/</link>
		<comments>http://www.poeschko.com/2010/11/code-line-count/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 22:37:56 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=152</guid>
		<description><![CDATA[I just asked myself the question, how much code have I written so far in my life? I wanted to break it down into individual projects and programming languages. A shell script using wc -l could have done it, but &#8230; <a href="http://www.poeschko.com/2010/11/code-line-count/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just asked myself the question, how much code have I written so far in my life? I wanted to break it down into individual projects and programming languages. A shell script using <code>wc -l</code> could have done it, but I decided to write a short script in my “mother tongue” Python.</p>
<p>To setup projects and programming languages, the following variables are used:</p>
<pre class="brush: python; title: ; wrap-lines: true; notranslate">
PROJECTS = {
	'tripedia.org': '/Users/Jan/Projekte/tripedia.org/tripedia',
	'-BatchWorks': ['/Users/Jan/Projekte/BatchWorks/Src', '/Users/Jan/Projekte/BatchWorks/Components'],
	'-Mathador': '/Users/Jan/Projekte/Mathador',
}

EXCLUDE_DIRS = set(['_Kopien_', 'prototype', 'scriptaculous', 'innerdom', 'livepipe', 'gmapsutil', 'TBP', ])
EXCLUDE_FILES = set(['prototype.js', 'carousel.js', 'printf.js'])

TYPES = {
	'Pascal': 'pas',
	'C/C++': ['h', 'hpp', 'cpp', 'c'],
	'HTML': ['html', 'htm', 'xhtml', 'xhtm'],
	'CSS': 'css',
	'Python': 'py',
	'Java': 'java',
	'JavaScript': 'js',
	'PHP': 'php',
}
</pre>
<p>A minus at the beginning of a project name indicates that this is an old, discontinued project. An inverse dictionary of file types to programming languages is built using the following code:</p>
<pre class="brush: python; title: ; notranslate">
def flatten(seq):
	&quot;&quot;&quot; flattens lists and sequences to one dimension &quot;&quot;&quot;

	if isinstance(seq, (list, types.GeneratorType)):
		for item in seq:
			for sub_item in flatten(item):
				yield sub_item
	else:
		yield seq

TYPES_INV = dict(flatten(((ext, type) for ext in ([exts] if isinstance(exts, basestring) else exts)) for type, exts in TYPES.iteritems()))
</pre>
<p>The core of the script is the following loop over projects, directories, and files:</p>
<pre class="brush: python; title: ; notranslate">
result = {}
for project, dirs in PROJECTS.iteritems():
	if isinstance(dirs, basestring):
		dirs = [dirs]
	lines = {}
	for dir in dirs:
		for dirpath, dirnames, filenames in os.walk(dir):
			for exclude in EXCLUDE_DIRS:
				try:
					dirnames.remove(exclude)
				except ValueError:
					pass
			for filename in filenames:
				if filename not in EXCLUDE_FILES:
					basename, ext = os.path.splitext(filename)
					ext = ext[1:]	# remove leading '.'
					type = TYPES_INV.get(ext)
					if type is not None:
						lc = linecount(os.path.join(dirpath, filename))
						inc_dict(lines, type, lc)
result[project] = lines
</pre>
<p>The actual line counting for a single file is done by the following very simple function:</p>
<pre class="brush: python; title: ; notranslate">
def linecount(filename):
	&quot;&quot;&quot; determine the number of lines in a file &quot;&quot;&quot;

	return sum(1 for line in open(filename, 'r'))
</pre>
<p>There are probably faster methods, but this is just very easy and “pythonic”, I think. The function <code>inc_dict</code> simply increments a dictionary entry:</p>
<pre class="brush: python; title: ; notranslate">
def inc_dict(d, k, i):
	&quot;&quot;&quot; increment the dictionary entry d[k] by i, or set it to i if not present already &quot;&quot;&quot;

	try:
		d[k] += i
	except KeyError:
		d[k] = i
</pre>
<p>Finally, a table with all the line counts is produced:</p>
<pre class="brush: python; title: ; notranslate">
types_total = dict((type, sum(lines.get(type, 0) for project, lines in result.iteritems())) for type in TYPES)
types = sorted(type for type, count in types_total.iteritems() if count &gt; 0)
table = []
table.append([&quot;Project&quot;] + types + [&quot;Total&quot;])
for project, lines in sorted(result.iteritems(), key=lambda (p, l): project_key(p)):
	table.append([project.lstrip('-')] + [lines.get(type, &quot;&quot;) for type in types] + [sum(lines.values())])
table.append([&quot;Total&quot;] + [types_total[type] for type in types] + [sum(types_total.values())])
print html_table(table)
print text_table(table)
</pre>
<p>The functions for outputting the table in HTML and text format are also pretty simple:</p>
<pre class="brush: python; title: ; notranslate">

def html_table(table):
	html = [&quot;&lt;table&gt;&quot;]
	html.append(&quot;&lt;thead&gt;&lt;tr&gt;&quot; + &quot;&quot;.join((&quot;&lt;th&gt;%s&lt;/th&gt;&quot; % cell) for cell in table[0]) + &quot;&lt;/tr&gt;&lt;/thead&gt;&quot;)
	html.append(&quot;&lt;tbody&gt;&quot;)
	for row in table[1:]:
		html.append(&quot;&lt;tr&gt;&lt;th&gt;%s&lt;/th&gt;&quot; % row[0] + &quot;&quot;.join((&quot;&lt;td&gt;%s&lt;/td&gt;&quot; % cell) for cell in row[1:]) + &quot;&lt;/tr&gt;&quot;)
	html.append(&quot;&lt;/tbody&gt;&quot;)
	html.append(&quot;&lt;/table&gt;&quot;)
	return &quot;\n&quot;.join(html)

def text_table(table):
	row_widths = []
	for row in table:
		for index, cell in enumerate(row):
			if len(row_widths) &lt;= index:
				row_widths += [0] * (index + 1 - len(row_widths))
			row_widths[index] = max(row_widths[index], len(unicode(cell)))
	text = []
	for row in table:
		text.append(' '.join((('%' + str(row_widths[index]) + 's') % cell) for index, cell in enumerate(row)))
	return &quot;\n&quot;.join(text)
</pre>
<p>You can also <a href="/files/linecounter.py">download the whole Python script</a>.</p>
<p>Finally, here is my result:<br />
<small><br />
<table>
<thead>
<tr>
<th>Project</th>
<th>C/C++</th>
<th>CSS</th>
<th>HTML</th>
<th>JavaScript</th>
<th>PHP</th>
<th>Pascal</th>
<th>Python</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<th>Auro Kubelka</th>
<td></td>
<td>599</td>
<td></td>
<td>19</td>
<td>13350</td>
<td></td>
<td></td>
<td>13968</td>
</tr>
<tr>
<th>Exkursionsbauernhoefe</th>
<td></td>
<td>192</td>
<td></td>
<td></td>
<td>3357</td>
<td></td>
<td></td>
<td>3549</td>
</tr>
<tr>
<th>Mathics</th>
<td></td>
<td>827</td>
<td>489</td>
<td>1971</td>
<td></td>
<td></td>
<td>24215</td>
<td>27502</td>
</tr>
<tr>
<th>oekosozialmarkt.com</th>
<td></td>
<td>3019</td>
<td>9201</td>
<td>2685</td>
<td></td>
<td></td>
<td>24443</td>
<td>39348</td>
</tr>
<tr>
<th>Rindfleischfest</th>
<td></td>
<td>240</td>
<td></td>
<td></td>
<td>966</td>
<td></td>
<td></td>
<td>1206</td>
</tr>
<tr>
<th>Stanzoptimierung</th>
<td>7976</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>7976</td>
</tr>
<tr>
<th>tripedia.org</th>
<td></td>
<td>1881</td>
<td>7542</td>
<td>4117</td>
<td></td>
<td></td>
<td>17590</td>
<td>31130</td>
</tr>
<tr>
<th>BatchWorks</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>8325</td>
<td></td>
<td>8325</td>
</tr>
<tr>
<th>livelynet.net</th>
<td></td>
<td>296</td>
<td>3379</td>
<td>357</td>
<td></td>
<td></td>
<td>8409</td>
<td>12441</td>
</tr>
<tr>
<th>Mathador</th>
<td>8857</td>
<td></td>
<td>343</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>9200</td>
</tr>
<tr>
<th>Preisdetektiv</th>
<td></td>
<td>119</td>
<td>277</td>
<td>728</td>
<td></td>
<td></td>
<td>952</td>
<td>2076</td>
</tr>
<tr>
<th>RLS-Info</th>
<td></td>
<td>362</td>
<td>23098</td>
<td>325</td>
<td></td>
<td></td>
<td></td>
<td>23785</td>
</tr>
<tr>
<th>Total</th>
<td>16833</td>
<td>7535</td>
<td>44329</td>
<td>10202</td>
<td>17673</td>
<td>8325</td>
<td>75609</td>
<td>180506</td>
</tr>
</tbody>
</table>
<p></small><br />
Over 180,000 lines of code written so far! And that includes only most of my major projects. Smaller stuff written for university assignments (especially much Mathematica code), small tools and tests are not included in this statistic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poeschko.com/2010/11/code-line-count/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

