<?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</title>
	<atom:link href="http://www.poeschko.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.poeschko.com</link>
	<description>Coding, Math, Photography, and Life.</description>
	<lastBuildDate>Mon, 10 Dec 2012 06:01:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>New challenges</title>
		<link>http://www.poeschko.com/2012/12/new-challenges/</link>
		<comments>http://www.poeschko.com/2012/12/new-challenges/#comments</comments>
		<pubDate>Mon, 10 Dec 2012 06:01:16 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Meta]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[mathics]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=1218</guid>
		<description><![CDATA[Life has been pretty busy recently. I worked on my Google Summer of Code project implementing lattices in Sage; I continued working on several optimization projects, mostly dealing with the charging of multiple electric vehicles (in cooperation with FH Joanneum &#8230; <a href="http://www.poeschko.com/2012/12/new-challenges/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Life has been pretty busy recently. I worked on my <a href="http://gsoc-sage-lattices.blogspot.com/">Google Summer of Code project</a> implementing lattices in <a href="http://www.sagemath.org/">Sage</a>; I continued working on several optimization projects, mostly dealing with the charging of multiple electric vehicles (in cooperation with FH Joanneum Kapfenberg and other companies); I took my last exams and finished my master&#8217;s thesis (&#8220;Optimization of a Purlin Punching Process&#8221;). I&#8217;m glad (and a little proud) that all of this worked out so well.</p>
<p>Adding to that, I organized my move to the U.S., where I finally landed and already began working for <a href="http://wolfram.com/">Wolfram Research</a>. I am working as a Kernel Developer on <em>Mathematica</em> Online (or whatever it will be called once it gets released to the public). This is quite related to my previous work on <a href="http://mathics.org/">Mathics</a>.</p>
<p>Now, the sad news is that I have to stop actively coding on Mathics as a consequence. However, I see it in really good hands with <a href="https://github.com/sn6uv">Angus</a> having already taken the lead recently, and he will certainly continue to keep Mathics flourish. Others are jumping in as well, so Mathics will not disappear, but grow further. Of course, I will still be there when assistance is needed, to merge in pull requests, and to keep the server running.</p>
<p>I&#8217;m really excited about the new challenges. I&#8217;ll share some of my experience on a special (rather personal) blog <a href="http://gowestyoungjan.poeschko.com/">Go West, Young Jan</a>. It&#8217;s in German so I don&#8217;t forget my mother&#8217;s tongue completely.</p>
<p>Let the adventure begin.</p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=1218&amp;md5=8d5aec2737a43627e5d9c8e4465e24cd" 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/12/new-challenges/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mathics: Django in Sage-Python on nginx and gunicorn</title>
		<link>http://www.poeschko.com/2012/06/mathics-django-in-sage-python-on-nginx-and-gunicorn/</link>
		<comments>http://www.poeschko.com/2012/06/mathics-django-in-sage-python-on-nginx-and-gunicorn/#comments</comments>
		<pubDate>Mon, 18 Jun 2012 15:31:27 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[circus]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[gunicorn]]></category>
		<category><![CDATA[mathics]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[sage]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=1202</guid>
		<description><![CDATA[I recently moved Mathics from my &#8220;general&#8221; web server that is also running tripedia.org, fairteiler.com, this site, and lots of other stuff, to its own virtual machine (a KVM). Mathics uses a lot of special stuff (e.g., not the regular &#8230; <a href="http://www.poeschko.com/2012/06/mathics-django-in-sage-python-on-nginx-and-gunicorn/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently moved <a href="http://www.mathics.net">Mathics</a> from my &#8220;general&#8221; web server that is also running <a href="http://www.tripedia.org">tripedia.org</a>, <a href="http://fairteiler.com">fairteiler.com</a>, this site, and lots of other stuff, to its own virtual machine (a <a href="http://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine">KVM</a>). Mathics uses a lot of special stuff (e.g., not the regular Python, but <a href="http://sagemath.org/">Sage</a>) and occasionally tends to freeze the whole machine, so it makes sense to separate it from the rest.</p>
<p>In the light of things to come (thinking of &#8220;live&#8221; collaboration and long polling) I thought Mathics should &#8220;go green&#8221; with the potential to serve it asynchronously. The Python WSGI HTTP server <a href="http://gunicorn.org/">gunicorn</a> seems like an obvious choice to serve Django applications this way, and it plays together nicely with the HTTP proxy server <a href="http://nginx.org/">nginx</a>. Everything runs on Debian Linux.</p>
<p>In addition, I installed Sage 5.0 (this is as simple as extracting the files to an arbitrary location, running make and waiting for a couple of hours). Because Sage&#8217;s version of Python (<code>sage -python</code>) will be used to run Django and gmail is used via SSL to send emails (registration/password and Django&#8217;s error emails, in particular), Sage has to be rebuilt with SSL support:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
apt-get install libssl-dev
sage -f python
</pre>
<p>nginx is configured by adding a file to <code>/etc/nginx/site-enabled</code> containing something like this:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
  upstream app_server {
    server unix:/tmp/gunicorn.sock fail_timeout=0;
  }

  server {
    listen 80 default;
    client_max_body_size 4G;
    server_name _;
    keepalive_timeout 5;

    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_buffering off;
      proxy_pass http://app_server;
      break;
    }

    location /media/ {
      root /home/jan/static;
    }
  }
</pre>
<p>This will serve everything under <code>/media/</code> from <code>/home/jan/static</code> (a symbolic link pointing to <code>mathics/web/media</code>), while all other URLs are passed to the app server which communicates with gunicorn via Unix sockets.</p>
<p>One way to <a href="http://gunicorn.org/deploy.html">deploy gunicorn</a> is <a href="http://circus.readthedocs.org/en/latest/index.html">Circus</a>, a process watcher and runner. It can be configured like the following:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
[watcher:mathics]
cmd = sudo -u jan /home/jan/sage/sage -python /home/jan/sage/local/bin/gunicorn_django --bind unix:/tmp/gunicorn.sock --workers 4 /home/jan/mathics
working_dir = /home/jan/mathics
send_hup = true
</pre>
<p>This will execute <code>gunicorn_django</code> in the Mathics directory and listen to the corresponding Unix socket at startup. gunicorn will in turn fire up four workers.</p>
<p>I couldn&#8217;t figure out how to conveniently restart these Django worker processes. However, after simply killing them using</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
kill `ps -ef | grep &quot;python /home/jan/sage/local/bin/gunicorn_django&quot; | grep -v grep | awk '{print $2}'`
</pre>
<p>they will be restarted automatically, thereby loading any changes made to the Mathics source code.</p>
<p>Please let me know if you have any suggestions.</p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=1202&amp;md5=833d872d0454ab1ffca77f8b77f55e0e" 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/06/mathics-django-in-sage-python-on-nginx-and-gunicorn/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lago Maggiore</title>
		<link>http://www.poeschko.com/2012/04/lago-maggiore/</link>
		<comments>http://www.poeschko.com/2012/04/lago-maggiore/#comments</comments>
		<pubDate>Sat, 21 Apr 2012 17:52:47 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Photography]]></category>
		<category><![CDATA[italy]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[stresa]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=1163</guid>
		<description><![CDATA[Some pictures from my trips to Stresa, Italy, and the places around Lago Maggiore.]]></description>
			<content:encoded><![CDATA[<p>Some pictures from my trips to Stresa, Italy, and the places around Lago Maggiore.</p>

<a href='http://www.poeschko.com/2012/04/lago-maggiore/tree-at-lago-maggiore-2/' title='Tree at Lago Maggiore'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Tree-at-Lago-Maggiore1-150x150.jpg" class="attachment-thumbnail" alt="Tree at Lago Maggiore" title="Tree at Lago Maggiore" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/sky-over-lago-maggiore-2/' title='Sky over Lago Maggiore'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Sky-over-Lago-Maggiore1-150x150.jpg" class="attachment-thumbnail" alt="Sky over Lago Maggiore" title="Sky over Lago Maggiore" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/at-lago-dorta-2/' title='At Lago d&#039;Orta'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/At-Lago-dOrta1-150x150.jpg" class="attachment-thumbnail" alt="At Lago d&#039;Orta" title="At Lago d&#039;Orta" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/lago-dorta-2/' title='Lago d&#039;Orta'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Lago-dOrta1-150x150.jpg" class="attachment-thumbnail" alt="Lago d&#039;Orta" title="Lago d&#039;Orta" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/orta-street/' title='Orta street'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Orta-street-150x150.jpg" class="attachment-thumbnail" alt="Orta street" title="Orta street" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/orta-2/' title='Orta'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Orta1-150x150.jpg" class="attachment-thumbnail" alt="Orta" title="Orta" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/san-bernardino-2/' title='San Bernardino'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/San-Bernardino1-150x150.jpg" class="attachment-thumbnail" alt="San Bernardino" title="San Bernardino" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/funny-funicular-at-laveno-2/' title='Funny funicular at Laveno'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Funny-funicular-at-Laveno1-150x150.jpg" class="attachment-thumbnail" alt="Funny funicular at Laveno" title="Funny funicular at Laveno" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/funicular-2/' title='Funicular'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Funicular1-150x150.jpg" class="attachment-thumbnail" alt="Funicular" title="Funicular" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/view-over-lago-maggiore-2/' title='View over Lago Maggiore'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/View-over-Lago-Maggiore1-150x150.jpg" class="attachment-thumbnail" alt="View over Lago Maggiore" title="View over Lago Maggiore" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/spring-is-coming-2/' title='Spring is coming'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Spring-is-coming1-150x150.jpg" class="attachment-thumbnail" alt="Spring is coming" title="Spring is coming" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/metal-2/' title='Metal'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Metal1-150x150.jpg" class="attachment-thumbnail" alt="Metal" title="Metal" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/laveno-2/' title='Laveno'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Laveno1-150x150.jpg" class="attachment-thumbnail" alt="Laveno" title="Laveno" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/santa-caterina-del-sasso-2/' title='Santa Caterina del Sasso'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Santa-Caterina-del-Sasso1-150x150.jpg" class="attachment-thumbnail" alt="Santa Caterina del Sasso" title="Santa Caterina del Sasso" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/sacro-monte-della-ss-trinita-di-ghiffa-2/' title='Sacro Monte della SS. Trinità di Ghiffa'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Sacro-Monte-della-SS.-Trinità-di-Ghiffa1-150x150.jpg" class="attachment-thumbnail" alt="Sacro Monte della SS. Trinità di Ghiffa" title="Sacro Monte della SS. Trinità di Ghiffa" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/church-at-sacro-monte-della-ss-trinita-di-ghiffa/' title='Church at Sacro Monte della SS. Trinità di Ghiffa'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Church-at-Sacro-Monte-della-SS.-Trinità-di-Ghiffa-150x150.jpg" class="attachment-thumbnail" alt="Church at Sacro Monte della SS. Trinità di Ghiffa" title="Church at Sacro Monte della SS. Trinità di Ghiffa" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/view-with-a-bench-2/' title='View with a bench'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/View-with-a-bench1-150x150.jpg" class="attachment-thumbnail" alt="View with a bench" title="View with a bench" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/bar-2/' title='BAR'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/BAR1-150x150.jpg" class="attachment-thumbnail" alt="BAR" title="BAR" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/mergozzo-2/' title='Mergozzo'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Mergozzo1-150x150.jpg" class="attachment-thumbnail" alt="Mergozzo" title="Mergozzo" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/duomo-di-milano-2/' title='Duomo di Milano'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Duomo-di-Milano1-150x150.jpg" class="attachment-thumbnail" alt="Duomo di Milano" title="Duomo di Milano" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/lake-2/' title='Lake'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Lake1-150x150.jpg" class="attachment-thumbnail" alt="Lake" title="Lake" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/market-2/' title='Market'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Market1-150x150.jpg" class="attachment-thumbnail" alt="Market" title="Market" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/view-2/' title='View'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/View1-150x150.jpg" class="attachment-thumbnail" alt="View" title="View" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/italian-snack-2/' title='Italian Snack'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Italian-Snack1-150x150.jpg" class="attachment-thumbnail" alt="Italian Snack" title="Italian Snack" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/cannobio-2/' title='Cannobio'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Cannobio1-150x150.jpg" class="attachment-thumbnail" alt="Cannobio" title="Cannobio" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/wall-3/' title='Wall'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Wall1-150x150.jpg" class="attachment-thumbnail" alt="Wall" title="Wall" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/re-2/' title='Re'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Re1-150x150.jpg" class="attachment-thumbnail" alt="Re" title="Re" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/light-in-duomo-2/' title='Light in Duomo'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Light-in-Duomo1-150x150.jpg" class="attachment-thumbnail" alt="Light in Duomo" title="Light in Duomo" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/light-between-duomo-seats/' title='Light between Duomo seats'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Light-between-Duomo-seats-150x150.jpg" class="attachment-thumbnail" alt="Light between Duomo seats" title="Light between Duomo seats" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/lake-and-mountains-2/' title='Lake and Mountains'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Lake-and-Mountains1-150x150.jpg" class="attachment-thumbnail" alt="Lake and Mountains" title="Lake and Mountains" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/lago-maggiore-2/' title='Lago Maggiore'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Lago-Maggiore1-150x150.jpg" class="attachment-thumbnail" alt="Lago Maggiore" title="Lago Maggiore" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/isola-madre-2/' title='Isola Madre'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Isola-Madre1-150x150.jpg" class="attachment-thumbnail" alt="Isola Madre" title="Isola Madre" /></a>
<a href='http://www.poeschko.com/2012/04/lago-maggiore/abandoned-villa-in-stresa-2/' title='Abandoned villa in Stresa'><img width="150" height="150" src="http://www.poeschko.com/wp-content/uploads/2012/04/Abandoned-villa-in-Stresa1-150x150.jpg" class="attachment-thumbnail" alt="Abandoned villa in Stresa" title="Abandoned villa in Stresa" /></a>

 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=1163&amp;md5=9f272cbd418858629f797992f430cd6c" 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/04/lago-maggiore/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Alpha Maps: a mashup of Wolfram&#124;Alpha and Google Maps</title>
		<link>http://www.poeschko.com/2012/04/alpha-maps-a-mashup-of-wolframalpha-and-google-maps/</link>
		<comments>http://www.poeschko.com/2012/04/alpha-maps-a-mashup-of-wolframalpha-and-google-maps/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 19:07:16 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wolfram alpha]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=1113</guid>
		<description><![CDATA[Hands down, Wolfram is awesome. Mathematica has been my favorite computer algebra system* from the start (okay, there were some wrong ways towards Maple in the very beginning, but hey, everybody makes mistakes); and Wolfram&#124;Alpha is a big step (and &#8230; <a href="http://www.poeschko.com/2012/04/alpha-maps-a-mashup-of-wolframalpha-and-google-maps/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hands down, <a href="http://wolfram.com/">Wolfram</a> is awesome. <a href="http://www.wolfram.com/mathematica/">Mathematica</a> has been my favorite computer algebra system* from the start (okay, there <em>were</em> some wrong ways towards Maple in the very beginning, but hey, everybody makes mistakes); and <a href="http://www.wolframalpha.com/">Wolfram|Alpha</a> is a big step (and still stepping) towards a huge semantic web.</p>
<p>Now I just came across the pretty new <a href="http://products.wolframalpha.com/api/">Wolfram|Alpha API</a> and thought I had to do something with it. Having been a maps guy since the <a href="http://www.tripedia.org">tripedia</a> days, I had the idea of mashing up W|A with <a href="https://developers.google.com/maps/documentation/javascript/">Google Maps</a>.</p>
<p>A user can enter an arbitrary Wolfram|Alpha query (usually a city), the query is sent to W|A and the result is parsed on the client side. All items in the result that refer to geolocations are queried also to get a set of markers on the map. With nice info windows showing the data that W|A returned for them.</p>
<p>W|A sends quite a lot of information, but for now I was only interested in plain facts. These can be accessed using the <a href="http://products.wolframalpha.com/api/documentation.html#8"><code>plaintext</code></a> field for every so-called &#8220;subpod&#8221;. Each of these plaintexts actually represents a table encoded by newlines and <code>|</code> separators. One could argue about the elegance of this representation in the API, but whatever.</p>
<p>The W|A API is a server-side-only API, as it doesn&#8217;t set the <a href="https://developer.mozilla.org/en/http_access_control"><code>Access-Control-Allow-Origin</code></a> HTTP header to <code>*</code>, so accessing it directly from any modern browser will violate the same-origin policy and thus fail. Therefore, a thin PHP wrapper on a server is needed. The good thing is that this wrapper can also cache queries to avoid reaching the free API limit of 2000 monthly calls too soon.</p>
<p>I don&#8217;t want to go into the details of the implementation here—it&#8217;s basically a bit of JavaScript using <a href="http://jquery.com/">jQuery</a>. If you&#8217;re interested, the <a href="https://github.com/poeschko/AlphaMaps">code is online at github</a>, and the resulting site is <a href="http://poeschko.com/alphamaps/">Alpha Maps</a>.</p>
<p>It&#8217;s been a nice day of hacking. Any thoughts on how to turn this into something (even more) useful?</p>
<p>* I also like <a href="http://www.sagemath.org">Sage</a>, of course, and—surprise!—<a href="http://www.mathics.net">Mathics</a>.</p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=1113&amp;md5=0d06722b863fd3a183d04d7686b1abf5" 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/04/alpha-maps-a-mashup-of-wolframalpha-and-google-maps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting text files to UTF-8</title>
		<link>http://www.poeschko.com/2012/04/converting-text-files-to-utf-8/</link>
		<comments>http://www.poeschko.com/2012/04/converting-text-files-to-utf-8/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 10:35:27 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=1093</guid>
		<description><![CDATA[In a rather old project I&#8217;m working on again now, there used to be a lot of Latin-1-encoded files. Yuck! I don&#8217;t even want to know why anybody ever created or used a character encoding other than UTF-8. So I &#8230; <a href="http://www.poeschko.com/2012/04/converting-text-files-to-utf-8/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://www.auro-kubelka.at">rather old project</a> I&#8217;m working on again now, there used to be a lot of <a href="http://en.wikipedia.org/wiki/ISO/IEC_8859-1">Latin-1</a>-encoded files. Yuck! I don&#8217;t even want to know why anybody ever created or used a character encoding other than <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a>. So I thought, let&#8217;s get these old-school files a decent encoding.</p>
<p><a href="http://www.manpagez.com/man/1/iconv/">iconv</a> can do the job:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
iconv -f L1 -t UTF-8 filename &gt;filename.converted
</pre>
<p>This will convert the file <code>filename</code> from Latin-1 to UTF-8 and save it as <code>filename.converted</code>.</p>
<p>To find all relevant files in the project directory, we use <a href="http://www.manpagez.com/man/1/find/">find</a>, of course. The only issue with this is that a simple <code>for x in `find ...`</code> loop will not handle filenames containing spaces correctly, so we apply <code>while read</code> to it, as in:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
find . -name '*.php' | while read x; #...
</pre>
<p>This will execute the rest with a variable <code>x</code> being assigned every PHP filename in the current directory. (There are <a href="http://stackoverflow.com/questions/301039/how-can-i-escape-white-space-in-a-bash-loop-list">other approaches</a> to this as well, of course.)</p>
<p>Now there&#8217;s only one problem left to deal with: Some files in the directory are already UTF-8-encoded. Of course, we don&#8217;t want to re-encode them again. (Decoding from Latin-1 and encoding to UTF-8 is not <a href="http://en.wikipedia.org/wiki/Idempotence">idempotent</a> for characters beyond ASCII.) There might be other solutions, but I decided to use Python and the <a href="http://pypi.python.org/pypi/chardet">chardet</a> package to determine whether a file is already UTF-8-encoded:</p>
<pre class="brush: python; light: true; title: ; notranslate">
import chardet
if chardet.detect(str)['encoding'].lower() == 'utf-8':
    print ('UTF-8')
else:
    print ('L1')
</pre>
<p>This will print <code>UTF-8</code> if the string <code>str</code> is encoded in UTF-8 and <code>L1</code> otherwise.</p>
<p>Adding some code to output the current file and to remove the original file and replace it by the converted one, we get the following script:</p>
<pre class="brush: bash; title: ; notranslate">
find . -name '*.php' | while read x; do
    e=$(python -c &quot;import chardet; print ('UTF-8' if chardet.detect(file('$x').read())['encoding'].lower() == 'utf-8' else 'L1')&quot;)
    echo &quot;converting $x: $e&quot;
    iconv -f $e -t UTF-8 &quot;$x&quot; &gt; &quot;$x.utf8&quot;
    rm &quot;$x&quot;
    mv &quot;$x.utf8&quot; &quot;$x&quot;
done
</pre>
<p>We can also assemble this into a bash one-liner if we prefer:</p>
<pre class="brush: bash; light: true; title: ; wrap-lines: true; notranslate">
find . -name '*.php' | while read x; do e=$(python -c &quot;import chardet; print ('UTF-8' if chardet.detect(file('$x').read())['encoding'].lower() == 'utf-8' else 'L1')&quot;); echo &quot;converting $x: $e&quot;; iconv -f $e -t UTF-8 &quot;$x&quot; &gt; &quot;$x.utf8&quot;; rm &quot;$x&quot;; mv &quot;$x.utf8&quot; &quot;$x&quot;; done
</pre>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=1093&amp;md5=e0e4cb82dd6ced409db37fd455f89c7f" 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/04/converting-text-files-to-utf-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shortest unused Twitter #hashtag</title>
		<link>http://www.poeschko.com/2012/02/shortest-unused-twitter-hashtag/</link>
		<comments>http://www.poeschko.com/2012/02/shortest-unused-twitter-hashtag/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 13:20:18 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[hashtags]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=1082</guid>
		<description><![CDATA[What is the shortest Twitter #hashtag that has never been used? As an additional constraint, let&#8217;s focus on the lexicographically first hashtag composed of ASCII letters only of that kind. Let&#8217;s skip dessert and use Python and the Twitter Search &#8230; <a href="http://www.poeschko.com/2012/02/shortest-unused-twitter-hashtag/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>What is the shortest <a href="http://twitter.com">Twitter</a> #hashtag that has never been used? As an additional constraint, let&#8217;s focus on the lexicographically first hashtag composed of ASCII letters only of that kind. Let&#8217;s skip dessert and use Python and the <a href="https://dev.twitter.com/docs/using-search">Twitter Search API</a> to find out:</p>
<pre class="brush: python; title: ; notranslate">
import urllib
import json
import itertools
import string
import time

k, max_k = 1, 10
while k &lt; max_k:
    for tag in itertools.product(string.ascii_lowercase, repeat=k):
        tag = ''.join(tag)
        print &quot;Searching for #%s&quot; % tag
        search_url = 'https://search.twitter.com/search.json?q=%%23%s' % tag
        while True:
            search_result = json.loads(urllib.urlopen(search_url).read())
            if 'results' in search_result:
                break
            print &quot;Wait a few seconds because of Twitter Search API limit&quot;
            time.sleep(5)
        search_result = search_result['results']
        if not search_result:
            print &quot;Unused hashtag: #%s&quot; % tag
            k = max_k
            break
    k += 1
</pre>
<p>After a few minutes, the result: #agy. What could we use that one for?</p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=1082&amp;md5=66c6738526c50f3c058ace6b67e334d1" 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/02/shortest-unused-twitter-hashtag/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Memory-efficient Django queries</title>
		<link>http://www.poeschko.com/2012/02/memory-efficient-django-queries/</link>
		<comments>http://www.poeschko.com/2012/02/memory-efficient-django-queries/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 17:17:20 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=1062</guid>
		<description><![CDATA[When doing heavy computations involving the Django Object-Relational Mapper to access your database, you might notice Python consuming lots of memory. This will probably not happen during production web server mode, because dealing with lots of data to serve a &#8230; <a href="http://www.poeschko.com/2012/02/memory-efficient-django-queries/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When doing heavy computations involving the Django Object-Relational Mapper to access your database, you might notice Python consuming lots of memory. This will probably not happen during production web server mode, because dealing with lots of data to serve a single request already indicates that something is wrong and at least some preprocessing should be done. So that&#8217;s probably why Django isn&#8217;t tailored towards such needs, rather favoring speed (both at execution and coding time) at the cost of memory. But at least when you&#8217;re in that preprocessing phase or you&#8217;re just using the Django ORM for some scientific computation, you don&#8217;t want to consume more memory than absolutely necessary.</p>
<p>The first issue to watch out for is <a href="https://docs.djangoproject.com/en/dev/ref/settings/#debug">debug mode</a>. From the docs:</p>
<blockquote><p>It is also important to remember that when running with DEBUG turned on, Django will remember every SQL query it executes. This is useful when you are debugging, but on a production server, it will rapidly consume memory.</p></blockquote>
<p>&#8220;Remembering&#8221; means that Django stores all SQL queries and their execution times in a list <code>django.db.connection.queries</code> of the form <code>[{'sql': 'SELECT ...', 'time': '0.01'}, ]</code>. This is useful when you want to profile your queries (see <a href="https://docs.djangoproject.com/en/1.3/faq/models/#how-can-i-see-the-raw-sql-queries-django-is-running">the docs</a>), but needless overhead when you&#8217;re just doing heavy-database-access computations. So either set <code>DEBUG</code> to <code>False</code> or clear this list regularly in that case.</p>
<p>Moreover, it is important to understand <a href="https://docs.djangoproject.com/en/1.3/topics/db/queries/#caching-and-querysets">how Django holds data in memory</a>. Although the resulting objects are constructed &#8220;lazily&#8221; on the fly, the resulting rows of querysets are kept in memory by default so that multiple iterations on the result can use these cached versions. This can be avoided by using <code><a href="https://docs.djangoproject.com/en/1.3/ref/models/querysets/#iterator">queryset.iterator()</a></code>. So while</p>
<pre class="brush: python; title: ; notranslate">
entries = Entry.objects.all()
for entry in entries:
    print entry
for entry in entries:
    print entry
</pre>
<p>will receive all entries from the database <em>once</em> and keep them in memory,</p>
<pre class="brush: python; title: ; notranslate">
for entry in entries.iterator():
    print entry
for entry in entries.iterator():
    print entry
</pre>
<p>will execute the query twice but save memory.</p>
<p>However, even using <code>iterator()</code> can still lead to a heavy memory footprint, not directly on Django&#8217;s side, but from the database interface (e.g. the Python MySQLdb module). It will receive and store <em>all</em> the resulting data from the database server before even handing bits over to Django. So the only way to avoid this is to use queries that don&#8217;t produce too much data at once. <a href="http://djangosnippets.org/snippets/1949/">This snippet</a> does exactly that:</p>
<pre class="brush: python; title: ; notranslate">
def queryset_iterator(queryset, chunksize=1000):
    pk = 0
    last_pk = queryset.order_by('-pk')[0].pk
    queryset = queryset.order_by('pk')
    while pk &lt; last_pk:
        for row in queryset.filter(pk__gt=pk)[:chunksize]:
            pk = row.pk
            yield row
</pre>
<p>It basically receives slices (default size 1000) of the queryset ordered by the primary key. As a consequence, any ordering previously applied to the queryset is lost. The reason for this behavior is, of course, that ordering (and especially slicing) by primary key is fast. You can use the function like this:</p>
<pre class="brush: python; title: ; notranslate">
for entry in queryset_iterator(Entry.objects):
    print entry
</pre>
<p>Apart from not being able to order the queryset, this approach does not handle concurrent modification of the data well: When rows are inserted or deleted while iterating over the dataset with <code>queryset_iterator</code>, rows might be reported several times or never. That should not be a big problem when preprocessing data though.</p>
<p>I modified <code>queryset_iterator</code> slightly to save the initial primary key query and to allow for non-numerical primary keys and also reverse ordering of primary keys:</p>
<pre class="brush: python; title: ; notranslate">
def queryset_iterator(queryset, chunksize=1000, reverse=False):
    ordering = '-' if reverse else ''
    queryset = queryset.order_by(ordering + 'pk')
    last_pk = None
    new_items = True
    while new_items:
        new_items = False
        chunk = queryset
        if last_pk is not None:
            func = 'lt' if reverse else 'gt'
            chunk = chunk.filter(**{'pk__' + func: last_pk})
        chunk = chunk[:chunksize]
        row = None
        for row in chunk:
            yield row
        if row is not None:
            last_pk = row.pk
            new_items = True
</pre>
<p>To sum things up:</p>
<ul>
<li>Set <code>DEBUG = False</code> when doing lots of database operations.
<li>Use <code>queryset_iterator</code> when you deal with millions of rows and don&#8217;t care about ordering.
<li>Still enjoy the convenience of Django!
</ul>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=1062&amp;md5=e433f584f1404bcec2d788bad111c7fa" 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/02/memory-efficient-django-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Homepage updated</title>
		<link>http://www.poeschko.com/2012/01/homepage-updated/</link>
		<comments>http://www.poeschko.com/2012/01/homepage-updated/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 21:06:29 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.poeschko.com/?p=991</guid>
		<description><![CDATA[I just updated this homepage to the beautiful WordPress theme Twenty Eleven and re-structured everything completely. Now there&#8217;s a &#8220;welcome page&#8221; separate from the actual blog, and I also summed up all the projects I&#8217;ve been working on on one &#8230; <a href="http://www.poeschko.com/2012/01/homepage-updated/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just updated this homepage to the beautiful WordPress theme <a href="http://wordpress.org/extend/themes/twentyeleven" title="Twenty Eleven">Twenty Eleven</a> and re-structured everything completely. Now there&#8217;s a &#8220;welcome page&#8221; separate from the actual blog, and I also summed up all the projects I&#8217;ve been working on on one single page. Hope you like it.</p>
 <p><a href="http://www.poeschko.com/?flattrss_redirect&amp;id=991&amp;md5=fe8ede9c208fdb5958c16614d9904556" 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/homepage-updated/feed/</wfw:commentRss>
		<slash:comments>0</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>
	</channel>
</rss>
