<?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>Ben Jao Ming</title>
	<atom:link href="http://overtag.dk/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://overtag.dk/wordpress</link>
	<description>101% objective... always</description>
	<lastBuildDate>Fri, 02 Apr 2010 23:50:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9-rare</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Changing the Django Admin site title</title>
		<link>http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/</link>
		<comments>http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 23:45:52 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[django-admin]]></category>
		<category><![CDATA[translation]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=191</guid>
		<description><![CDATA[Often the Django Admin should look a little different for the sake of your users or for the sake of yourself (running multiple django sites with identical looks and titles can be such a pain). Often users don&#8217;t know what Django is, and it takes ages to explain, and even after that they have no [...]]]></description>
			<content:encoded><![CDATA[<p>Often the Django Admin should look a little different for the sake of your users or for the sake of yourself (running multiple django sites with identical looks and titles can be such a pain). Often users don&#8217;t know what Django is, and it takes ages to explain, and even after that they have no clue. Also, often my administration has nothing to do with a website, so I don&#8217;t want the text &#8220;Site administration&#8221;.</p>
<p>First of all, you wanna add <strong>templates/admin/base_site.html</strong> to your project. This file can safely be overwritten, since it&#8217;s a file that the django devs have intended for the exact purpose of customizing your admin site a bit. Here&#8217;s an example of what to put in the file:</p>

<div class="wp_syntax"><div class="code"><pre>{% extends &quot;admin/base.html&quot; %}
{% load i18n %}
&nbsp;
{% block title %}{{ title }} <PIPE> {% trans 'Some Organisation' %}{% endblock %}
&nbsp;
{% block branding %}
&lt;style type=&quot;text/css&quot;&gt;
  #header
  {
    /* your style here */
  }
&lt;/style&gt;
&lt;h1 id=&quot;site-name&quot;&gt;{% trans 'Organisation Website' %}&lt;/h1&gt;
{% endblock %}
&nbsp;
{% block nav-global %}{% endblock %}</pre></div></div>

<p>This is common practice. But I noticed after this that I was still left with an annoying &#8220;Site Administration&#8221; on the main admin index page. And this string was not inside any of the template, but rather set inside the admin view. Luckily it&#8217;s quite easy to change. Assuming your language is set to English, run the following commands from your project directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> locale
$ .<span style="color: #000000; font-weight: bold;">/</span>manage.py makemessages -l en</pre></div></div>

<p>Now open up the file <strong>locale/en/LC_MESSAGES/django.po</strong> and add two lines after the header information (the last two lines of this example)</p>

<div class="wp_syntax"><div class="code"><pre class="gettext"><span style="color: #ff0000;">&quot;Project-Id-Version: PACKAGE VERSION<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Report-Msgid-Bugs-To: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;POT-Creation-Date: 2010-04-03 03:25+0200<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Last-Translator: FULL NAME &lt;EMAIL@ADDRESS&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Language-Team: LANGUAGE &lt;LL@li.org&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;MIME-Version: 1.0<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Content-Type: text/plain; charset=UTF-8<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Content-Transfer-Encoding: 8bit<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">msgid</span> <span style="color: #ff0000;">&quot;Site administration&quot;</span>
<span style="color: #000000; font-weight: bold;">msgstr</span> <span style="color: #ff0000;">&quot;Main administration index&quot;</span></pre></div></div>

<p>After this, remember to run this and reload your project&#8217;s server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ .<span style="color: #000000; font-weight: bold;">/</span>manage.py compilemessages</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django tip: Automatic logins</title>
		<link>http://overtag.dk/wordpress/2010/02/django-tip-automatic-logins/</link>
		<comments>http://overtag.dk/wordpress/2010/02/django-tip-automatic-logins/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 13:21:56 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[authenticate]]></category>
		<category><![CDATA[login]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=182</guid>
		<description><![CDATA[In the Django documentation we see the following:
When you&#8217;re manually logging a user in, you must call authenticate() before you call login().
That&#8217;s all really nice, because it makes sure that all your authentication backends are tried out; but if you want a really quick remedy for getting the job done, then you&#8217;ll need to set [...]]]></description>
			<content:encoded><![CDATA[<p>In the Django documentation we see the following:</p>
<blockquote><p>When you&#8217;re manually logging a user in, you must call <strong>authenticate()</strong> before you call<strong> login()</strong>.</p></blockquote>
<p>That&#8217;s all really nice, because it makes sure that all your authentication backends are tried out; but if you want a really quick remedy for getting the job done, then you&#8217;ll need to set the <em>user.backend</em> property to the specific backend that authenticated the user. Beware that the Django developers can change these requirements. I wanted this to avoid writing my own backend, so I did this to log users in via a special view accepting a hash from the URL (from an e-mail that had a link that&#8217;d automatically log a user in). This could also become useful if you want to <em>become</em> a different user.</p>

<div class="wp_syntax"><div class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">def</span> get_hash<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">import</span> hashlib
    m = hashlib.<span style="color: #dc143c;">md5</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    m.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span> + settings.<span style="color: black;">LOGIN_SECRET</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>m.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> auto_login<span style="color: black;">&#40;</span>request, user_id, secret<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #dc143c;">user</span> = get_object_or_404<span style="color: black;">&#40;</span>User, <span style="color: #008000;">id</span>=user_id<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> secret == get_hash<span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>user_id<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> Http404<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #dc143c;">user</span>.<span style="color: black;">backend</span> = <span style="color: #483d8b;">&quot;django.contrib.auth.backends.ModelBackend&quot;</span>
    login<span style="color: black;">&#40;</span>request, <span style="color: #dc143c;">user</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> HttpResponseRedirect<span style="color: black;">&#40;</span>reverse<span style="color: black;">&#40;</span><span style="color: #483d8b;">'frontpage'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p><strong>BEWARE!</strong><br />
I strongly suggest that you don&#8217;t log any superusers in this way. You could add a conditional statement <em>not user.is_superuser</em> or similar.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2010/02/django-tip-automatic-logins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uservoice feedback widget: Changing its style</title>
		<link>http://overtag.dk/wordpress/2009/09/uservoice-feedback-widget-changing-its-style/</link>
		<comments>http://overtag.dk/wordpress/2009/09/uservoice-feedback-widget-changing-its-style/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 09:19:49 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[feedback]]></category>
		<category><![CDATA[tab]]></category>
		<category><![CDATA[uservoice]]></category>
		<category><![CDATA[vertical]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=173</guid>
		<description><![CDATA[I have a feedback tab that&#8217;s blocking vital content on a website. Here&#8217;s how to alter the style of the Uservoice Feedback Tab &#8212; for instance the vertical offset: You have to insert this AFTER your widget js code, so that it will effectively overwrite the CSS declarations generated by Uservoice. Also it&#8217;s pretty annoying [...]]]></description>
			<content:encoded><![CDATA[<p>I have a feedback tab that&#8217;s blocking vital content on a website. Here&#8217;s how to alter the style of the Uservoice Feedback Tab &#8212; for instance the vertical offset: You have to insert this AFTER your widget js code, so that it will effectively overwrite the CSS declarations generated by Uservoice. Also it&#8217;s pretty annoying that it shows up on printed media, so the last style block is to remove it from print.</p>

<div class="wp_syntax"><div class="code"><pre class="css">&lt;style type=<span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;
  body a<span style="color: #cc00cc;">#uservoice-feedback-tab</span>,
  body a<span style="color: #cc00cc;">#uservoice-feedback-tab</span><span style="color: #3333ff;">:link</span>
  <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #66cc66;">:</span> <span style="color: #933;">10px</span> !important<span style="color: #66cc66;">;</span>
  <span style="color: #66cc66;">&#125;</span>
&lt;/style&gt;
&lt;style rel=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> type=<span style="color: #ff0000;">&quot;text/css&quot;</span> media=<span style="color: #ff0000;">&quot;print&quot;</span>&gt;
  body a<span style="color: #cc00cc;">#uservoice-feedback-tab</span>,
  body a<span style="color: #cc00cc;">#uservoice-feedback-tab</span><span style="color: #3333ff;">:link</span>
  <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #66cc66;">:</span> <span style="color: #993333;">none</span> !important<span style="color: #66cc66;">;</span>
  <span style="color: #66cc66;">&#125;</span>
&lt;/style&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/09/uservoice-feedback-widget-changing-its-style/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MarkItUp Markdown footnote button</title>
		<link>http://overtag.dk/wordpress/2009/09/markitup-markdown-footnote-button/</link>
		<comments>http://overtag.dk/wordpress/2009/09/markitup-markdown-footnote-button/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 11:51:05 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[markdown]]></category>
		<category><![CDATA[markitup]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=164</guid>
		<description><![CDATA[Here&#8217;s a simple addition to markItUp, that will prompt the user for a footnote number, a footnote text and then insert the number after the selection and the footnote text at the end of the full text. As handy extra feature, the plugin will save the previous entered footnote and not ask for further numbers [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple addition to markItUp, that will prompt the user for a footnote number, a footnote text and then insert the number after the selection and the footnote text at the end of the full text. As handy extra feature, the plugin will save the previous entered footnote and not ask for further numbers during the session, but instead increment the number each time the button is pressed.</p>
<p>Add this to your code to <strong>set.js</strong> inside your settings object:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'Insert footnote'</span><span style="color: #339933;">,</span>
	beforeInsert<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>h<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		instructions <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Type in the number of the footnote:)&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>h.<span style="color: #006600;">last_footnote</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			h.<span style="color: #006600;">last_footnote</span> <span style="color: #339933;">=</span> <span style="color: #000066;">prompt</span><span style="color: #009900;">&#40;</span>instructions<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isNaN<span style="color: #009900;">&#40;</span>h.<span style="color: #006600;">last_footnote</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				h.<span style="color: #006600;">last_footnote</span> <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>h.<span style="color: #006600;">last_footnote</span><span style="color: #009900;">&#41;</span> <span style="color: #CC0000;">+1</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">else</span>
				h.<span style="color: #006600;">last_footnote</span> <span style="color: #339933;">=</span> <span style="color: #000066;">prompt</span><span style="color: #009900;">&#40;</span>instructions<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		h.<span style="color: #006600;">footnote_content</span> <span style="color: #339933;">=</span> <span style="color: #000066;">prompt</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Type in the text of the footnote:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	closeWith<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>h<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'[^'</span> <span style="color: #339933;">+</span> h.<span style="color: #006600;">last_footnote</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">']'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	afterInsert<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>h<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		h.<span style="color: #006600;">textarea</span>.<span style="color: #006600;">value</span> <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'[^'</span> <span style="color: #339933;">+</span> h.<span style="color: #006600;">last_footnote</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">']: '</span> <span style="color: #339933;">+</span>
			h.<span style="color: #006600;">footnote_content</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></div></div>

<p>And put this icon in the set&#8217;s <strong>images</strong> folder: <a href="http://overtag.dk/wordpress/wp-content/uploads/footnote.png"><img src="http://overtag.dk/wordpress/wp-content/uploads/footnote.png" alt="footnote" title="footnote" width="16" height="16" class="alignnone size-full wp-image-167" /></a></p>
<p>After that be sure to modify style.css so it says something like (if 14 was the placement of the footnote button):</p>

<div class="wp_syntax"><div class="code"><pre class="css"><span style="color: #6666ff;">.markItUp</span> <span style="color: #6666ff;">.markItUpButton14</span> a	<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #3333ff;">:url</span><span style="color: #66cc66;">&#40;</span>images/footnote<span style="color: #6666ff;">.png</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/09/markitup-markdown-footnote-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django localized date template filter</title>
		<link>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/</link>
		<comments>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 22:24:13 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[template filter]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=155</guid>
		<description><![CDATA[UPDATE! This is going to be redundant in Django 1.2, in which you can add DATE_FORMAT to your django.po files.
I&#8217;ve often been frustrated that using settings.DATE_FORMAT does not give a localized date. Granted that the name of a month may be localized, but the format string does not change. So let&#8217;s start out by modifying [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE!</strong> This is going to be redundant in Django 1.2, in which you can add DATE_FORMAT to your django.po files.</p>
<p>I&#8217;ve often been frustrated that using <strong>settings.DATE_FORMAT</strong> does not give a localized date. Granted that the name of a month may be localized, but the format string does not change. So let&#8217;s start out by modifying <strong>settings.py</strong>. We wrap our default date format in a <b>ugettext</b> so the makemessages command will detect it, and we need to make it a dummy function, because the i18n library cannot be imported in settings.py due to circularity (it depends on settings.py).</p>

<div class="wp_syntax"><div class="code"><pre class="python">ugettext = <span style="color: #ff7700;font-weight:bold;">lambda</span> s: s
DATE_FORMAT = ugettext<span style="color: black;">&#40;</span><span style="color: #483d8b;">'N j, Y'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Run compilemessages and type in your localized date formats. Now we need a template filter that uses a localized format for calling the Django date format function. This is really simple:</p>

<div class="wp_syntax"><div class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span>.<span style="color: black;">defaultfilters</span> <span style="color: #ff7700;font-weight:bold;">import</span> stringfilter
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span> <span style="color: #ff7700;font-weight:bold;">import</span> dateformat
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span>.<span style="color: black;">translation</span> <span style="color: #ff7700;font-weight:bold;">import</span> ugettext
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span> <span style="color: #ff7700;font-weight:bold;">import</span> settings
&nbsp;
@register.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> localdate<span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;Format date with localized date format&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
    format = ugettext<span style="color: black;">&#40;</span>settings.<span style="color: black;">DATE_FORMAT</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> dateformat.<span style="color: black;">format</span><span style="color: black;">&#40;</span>value, format<span style="color: black;">&#41;</span></pre></div></div>

<p>And done. Using the filter is straight forward:</p>
<p><code><br />
Date: {{ my_date|localdate }}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presenting: django-simple-wiki</title>
		<link>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/</link>
		<comments>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 23:52:57 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[django application]]></category>
		<category><![CDATA[django-simple-wiki]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=142</guid>
		<description><![CDATA[It was bothering me that all the wikis I tried, all had either errors, feature lacks, too many dependencies or were simply unmaintained. So I decided to create yet another one. Curiously, the third hit when googling &#8216;django wiki&#8217; is Create a wiki in 20 minutes. Luckily that&#8217;s not really true, so all the PHP [...]]]></description>
			<content:encoded><![CDATA[<p>It was bothering me that all the wikis I tried, all had either errors, feature lacks, too many dependencies or were simply unmaintained. So I decided to create yet another one. Curiously, the third hit when googling &#8216;django wiki&#8217; is <a href="http://showmedo.com/videotutorials/video?name=1100000">Create a wiki in 20 minutes</a>. Luckily that&#8217;s not really true, so all the PHP guys and MediaWiki can continue breathing. This took me several days.</p>
<blockquote style="font-size: 150%;"><p><strong><a href="http://code.google.com/p/django-simple-wiki/">Google Code project page</a></strong></p></blockquote>
<blockquote style="font-size: 150%;"><p><strong><a href="http://wikidemo.overtag.dk/">Demo website</a></strong></p></blockquote>
<p><strong>Hierarchy and relations</strong><br />
First of all, as in the Trac wiki system, I chose to create a system for hierarchy, meaning that it&#8217;s possible to create an article and then create sub-articles. The hierarchy does not support multiple inheritance, because it needs to be basis for the permission system. That&#8217;s where the relation system comes in place: All articles can contain symmetrical relations to any other articles in the hierarchy.</p>
<p><strong>Parsing</strong><br />
Python and Django supports Markdown pretty much out of the box, so it&#8217;s an obvious choice to use this for parsing. The HTML features of normal Markdown have been removed, so all HTML is escaped in django-simple-wiki. And parsing is static, so every time a revision is created, the contents are passed and stored. This means that the contents of the article itself are not supposed to be dynamic. On the other hand, it is desirable to avoid parsing contents for every page hit. The parsing area of the application is only a few lines of code, and can be expanded if further parsing needs to be done, or someone wants to replace Markdown completely. For instance, if no parsing is done and HTML escaping is disabled, the wiki becomes a very simple CMS.</p>
<p><strong>Curious issues</strong><br />
There are a few out standing problems:</p>
<ul>
<li>Permission system is related to User entries in the Django auth system. But maybe this is too much of an annoyance, if the project already has groups setup in the existing auth system. On the other hand, other users would be bothered to setup both wiki groups and user groups, if the permission system was linked to user groups. And directly linking articles to user groups would require wiki-related groups to be created directly in the auth system.</li>
<li>Since relations are symmetrical, what should happen if one article is locked, but a user modifies it&#8217;s relations by deleting them from related articles?</li>
<li>Title editing: The title can only be created once, since it is coupled to the &#8217;slug&#8217; of the article. A user can deliberately create a completely different title, which is fine, but should subsequent editing be allowed, which would add complexity to the revision system?</li>
<li>Article deletion: When an article is deleted from the backend it shouldn&#8217;t worry anyone. But if the feature is added to the frontend, we would want to handle maliciousness etc. But should we really store all these files and revisions? Should we alert admins, so they can do the final cleanup?</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with Data Parallel Haskell</title>
		<link>http://overtag.dk/wordpress/2009/04/data-parallel-haskell/</link>
		<comments>http://overtag.dk/wordpress/2009/04/data-parallel-haskell/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 16:59:44 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[dph]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=122</guid>
		<description><![CDATA[DPH is a work-in-progress, and not everything is yet easy to realize. But you should still prepare yourself as a Haskell programmer, because this is really where Haskell can set off into uncharted areas of popularity and innovation.
As an exercise for a programming course, I developed a spell checker, that runs in parallel and was [...]]]></description>
			<content:encoded><![CDATA[<p>DPH is a <a href="http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell">work-in-progress</a>, and not everything is yet easy to realize. But you should still prepare yourself as a Haskell programmer, because this is really where Haskell can set off into uncharted areas of popularity and innovation.</p>
<p>As an exercise for a programming course, I developed a spell checker, that runs in parallel and was motivated to write this short howto on getting to grips with DPH. First of all, DPH comes as a builtin library with GHC 6.10.1+, so it&#8217;s easy to get started. This howto is compatible with 6.10.1. But the DPH team has, as of March 2009, warned that significant fixes are added in the GHC trunk, and you should run the following command before installing (ie. recompiling GHC), so I advice you to do so for your own benefit.</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ .<span style="color: #000000; font-weight: bold;">/</span>darcs-all --dph get</pre></div></div>

<p>Now, what you need to know is: DPH consists of two things, a compiler module that transforms your code for parallelism (&#8217;vectorization&#8217;) and some special libraries that you should use in your code, as they are compatible with the vectorizer.</p>
<p>DPH can help you achieve two kinds of parallelism: Normal (unlifted) <a href="http://en.wikipedia.org/wiki/Data_parallelism">data parallelism</a> and nested data parallelism. What the vectorizer works on is the latter, and for simple one-dimentional parallelism, you don&#8217;t need to know much, so let&#8217;s just get that done in a few lines:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell"><span style="color: #06c; font-weight: bold;">module</span> SpellCheckUnlifted <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Types
<span style="color: #06c; font-weight: bold;">import</span> Trie
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>Array<span style="color: #339933; font-weight: bold;">.</span>Parallel<span style="color: #339933; font-weight: bold;">.</span>Unlifted
<span style="color: #06c; font-weight: bold;">import</span> GHC<span style="color: #339933; font-weight: bold;">.</span>PArr
&nbsp;
<span style="color: #06c; font-weight: bold;">type</span> DocumentU <span style="color: #339933; font-weight: bold;">=</span> Array Word
&nbsp;
spellCheck <span style="color: #339933; font-weight: bold;">::</span> Dictionary <span style="color: #339933; font-weight: bold;">-&gt;</span> Word <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Bool</span>
spellCheck dic w <span style="color: #339933; font-weight: bold;">=</span> lookupTrie dic w
&nbsp;
spellCheckU <span style="color: #339933; font-weight: bold;">::</span> Dictionary <span style="color: #339933; font-weight: bold;">-&gt;</span> Document <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>Word<span style="color: green;">&#93;</span>
spellCheckU dic doc <span style="color: #339933; font-weight: bold;">=</span> 
  fromP <span style="color: green;">&#40;</span> filterP <span style="color: green;">&#40;</span>\s <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">not</span> <span style="color: green;">&#40;</span>spellCheck dic s<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>toP doc<span style="color: green;">&#41;</span> <span style="color: green;">&#41;</span></pre></div></div>

<p>As you can see, it&#8217;s fairly simple: Import <a href="http://www.haskell.org/ghc/docs/latest/html/libraries/dph-prim-par/Data-Array-Parallel-Unlifted-Parallel.html">Data.Array.Parallel.Unlifted</a> and <a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/GHC-PArr.html">GHC.PArr</a>. Then use functions <strong>toP</strong> and <strong>fromP</strong> to transform a list into a parallel array and back. The <strong>filterP</strong> function will execute functions in parallel on your array.</p>
<p><a href="http://overtag.dk/wordpress/wp-content/uploads/spellcheckertar.gz">Download all source code</a> of spell checker example.</p>
<p><strong>Nested parallel example</strong></p>
<p>The strong feature of DPH is nested parallelism, and you should think your problem through before engaging in this. In my approach, I start out with a non-parallel problem, and I think this is probably the classic example; we model our problems non-parallel and then consider how to transform them. My example is not suitable for nested parallelism, as it obviously has too little complexity and too much overhead for parallelism, but nonetheless there&#8217;s some interesting points to be gained:</p>
<ul>
<li>The problem set (a list of words) is easily transformed</li>
<li>The sub-problems (looking up in a Trie data structure) is nested</li>
<li>The data types are non-trivial and need some convertion</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="haskell"><span style="color: #5d478b; font-style: italic;">{-# LANGUAGE PArr #-}</span>
<span style="color: #5d478b; font-style: italic;">{-# OPTIONS -fvectorise #-}</span>
<span style="color: #06c; font-weight: bold;">module</span> SpellCheckDPH <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> <span style="color: #06c; font-weight: bold;">qualified</span> <span style="color: #06c; font-weight: bold;">Prelude</span>
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>Array<span style="color: #339933; font-weight: bold;">.</span>Parallel<span style="color: #339933; font-weight: bold;">.</span><span style="color: #06c; font-weight: bold;">Prelude</span>
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>Array<span style="color: #339933; font-weight: bold;">.</span>Parallel<span style="color: #339933; font-weight: bold;">.</span><span style="color: #06c; font-weight: bold;">Prelude</span><span style="color: #339933; font-weight: bold;">.</span>Word8
<span style="color: #06c; font-weight: bold;">import</span> <span style="color: #06c; font-weight: bold;">qualified</span> Data<span style="color: #339933; font-weight: bold;">.</span>Array<span style="color: #339933; font-weight: bold;">.</span>Parallel<span style="color: #339933; font-weight: bold;">.</span><span style="color: #06c; font-weight: bold;">Prelude</span><span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Int</span> <span style="color: #06c; font-weight: bold;">as</span> I
&nbsp;
<span style="color: #06c; font-weight: bold;">type</span> WordP <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span>:Word8:<span style="color: green;">&#93;</span>
<span style="color: #06c; font-weight: bold;">type</span> DocumentP <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span>:WordP:<span style="color: green;">&#93;</span>
<span style="color: #06c; font-weight: bold;">type</span> DictionaryP <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span>:TrieP:<span style="color: green;">&#93;</span>
<span style="color: #06c; font-weight: bold;">data</span> TrieP <span style="color: #339933; font-weight: bold;">=</span> NodeP Word8 DictionaryP <span style="color: #339933; font-weight: bold;">|</span> LeafP Word8
&nbsp;
isNode <span style="color: #339933; font-weight: bold;">::</span> Word8 <span style="color: #339933; font-weight: bold;">-&gt;</span> TrieP <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Bool</span>
isNode w t <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> t <span style="color: #06c; font-weight: bold;">of</span>
  <span style="color: green;">&#40;</span>NodeP w' dic<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> w <span style="color: #339933; font-weight: bold;">==</span> w'
  <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> False
&nbsp;
isLeaf <span style="color: #339933; font-weight: bold;">::</span> Word8 <span style="color: #339933; font-weight: bold;">-&gt;</span> TrieP <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Bool</span>
isLeaf w t <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> t <span style="color: #06c; font-weight: bold;">of</span>
  <span style="color: green;">&#40;</span>LeafP w'<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> w <span style="color: #339933; font-weight: bold;">==</span> w'
  <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> False
&nbsp;
lookupTrieP <span style="color: #339933; font-weight: bold;">::</span> DictionaryP <span style="color: #339933; font-weight: bold;">-&gt;</span> I<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Int</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> WordP <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Bool</span>
lookupTrieP dic i w <span style="color: #339933; font-weight: bold;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> len <span style="color: #339933; font-weight: bold;">=</span> lengthP w
        <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">if</span> <span style="color: green;">&#40;</span>I<span style="color: #339933; font-weight: bold;">.&lt;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>I<span style="color: #339933; font-weight: bold;">.+</span><span style="color: green;">&#41;</span> i <span style="color: red;">1</span><span style="color: green;">&#41;</span> len
              <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">let</span> node <span style="color: #339933; font-weight: bold;">=</span> filterP <span style="color: green;">&#40;</span>isNode <span style="color: green;">&#40;</span>w<span style="color: #339933; font-weight: bold;">!</span>:i<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> dic
                       <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">if</span> <span style="color: green;">&#40;</span>I<span style="color: #339933; font-weight: bold;">.==</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>lengthP node<span style="color: green;">&#41;</span> <span style="color: red;">0</span>
                             <span style="color: #06c; font-weight: bold;">then</span> False
                             <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">case</span> node<span style="color: #339933; font-weight: bold;">!</span>:<span style="color: red;">0</span> <span style="color: #06c; font-weight: bold;">of</span>
                                    <span style="color: green;">&#40;</span>NodeP <span style="color: #339933; font-weight: bold;">_</span> d<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> lookupTrieP d <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>I<span style="color: #339933; font-weight: bold;">.+</span><span style="color: green;">&#41;</span> i <span style="color: red;">1</span><span style="color: green;">&#41;</span> w
                                    <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> False
              <span style="color: #06c; font-weight: bold;">else</span> <span style="color: green;">&#40;</span>I<span style="color: #339933; font-weight: bold;">.==</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>lengthP <span style="color: green;">&#40;</span>filterP <span style="color: green;">&#40;</span>isLeaf <span style="color: green;">&#40;</span>w<span style="color: #339933; font-weight: bold;">!</span>:i<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> dic<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: red;">1</span>
&nbsp;
spellCheckP <span style="color: #339933; font-weight: bold;">::</span> DictionaryP <span style="color: #339933; font-weight: bold;">-&gt;</span> DocumentP <span style="color: #339933; font-weight: bold;">-&gt;</span> DocumentP
spellCheckP dic doc <span style="color: #339933; font-weight: bold;">=</span> filterP <span style="color: green;">&#40;</span>\s <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">not</span> <span style="color: green;">&#40;</span>lookupTrieP dic <span style="color: red;">0</span> s<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> doc</pre></div></div>

<p>Notice the first two lines. These tell GHC to add some syntax to handle the parallel arrays ([:a:]) and to let the vectorizer handle the code. Secondly, we import the DPH prelude and hide the normal Prelude. <em>You should keep normal GHC library functions separate from DPH!</em> <strong>spellCheckP</strong> does not convert a normal datatype into a parallel array, because we don&#8217;t want anything that cannot be vectorized in this module.</p>
<p><strong>lookupTrieP</strong> is not a pretty function, but it has to work with arrays and a limited number of utility functions in the DPH Prelude. <strong>And BEWARE!</strong> Not all functions in GHC.Parr have been implemented in the DPH Prelude, which is because they simply don&#8217;t work with nested parallel arrays, yet, so you simly shouldn&#8217;t import this module.</p>
<p>You&#8217;ll also notice how I avoided polymorphism. Since DPH only supports Ints, Doubles and Word8 (unsigned 8-bit int), it isn&#8217;t of any use. When you transform your datatypes into nested parallel types, you will loose generality. But you can still use data types with different constructors etc. And that&#8217;s the power of DPH!</p>
<p>Now we only have to transform our nested data structure and problem into parallel arrays. This is done in a seperate module (SpellCheck.hs in the example).</p>

<div class="wp_syntax"><div class="code"><pre class="haskell">c2w <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Char</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> W<span style="color: #339933; font-weight: bold;">.</span>Word8
c2w c <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">fromIntegral</span> <span style="color: green;">&#40;</span>ord c<span style="color: green;">&#41;</span>
w2c <span style="color: #339933; font-weight: bold;">::</span> W<span style="color: #339933; font-weight: bold;">.</span>Word8 <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Char</span>
w2c w <span style="color: #339933; font-weight: bold;">=</span> chr <span style="color: green;">&#40;</span><span style="font-weight: bold;">fromIntegral</span> w<span style="color: green;">&#41;</span>
wArr2Str <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span>W<span style="color: #339933; font-weight: bold;">.</span>Word8<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">String</span>
wArr2Str wArr <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">map</span> w2c wArr
&nbsp;
t2P <span style="color: #339933; font-weight: bold;">::</span> Trie <span style="color: #cccc00; font-weight: bold;">Char</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> TrieP
t2P <span style="color: green;">&#40;</span>Leaf c<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> LeafP <span style="color: green;">&#40;</span>c2w c<span style="color: green;">&#41;</span>
t2P <span style="color: green;">&#40;</span>Node c d<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> NodeP <span style="color: green;">&#40;</span>c2w c<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>dic2P d<span style="color: green;">&#41;</span>
&nbsp;
dic2P <span style="color: #339933; font-weight: bold;">::</span> Dictionary <span style="color: #339933; font-weight: bold;">-&gt;</span> DictionaryP
dic2P ds <span style="color: #339933; font-weight: bold;">=</span> toP <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">map</span> t2P ds
&nbsp;
doc2P <span style="color: #339933; font-weight: bold;">::</span> Document <span style="color: #339933; font-weight: bold;">-&gt;</span> DocumentP
doc2P doc <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span> doc' <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">filter</span> <span style="color: green;">&#40;</span>\s <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">not</span> <span style="color: #339933; font-weight: bold;">$</span> s<span style="color: #339933; font-weight: bold;">==</span><span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: green;">&#41;</span> doc
              <span style="color: #06c; font-weight: bold;">in</span> toP <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>toP<span style="color: #339933; font-weight: bold;">.</span><span style="color: green;">&#40;</span>\s <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">map</span> c2w s<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> doc'</pre></div></div>

<p><a href="http://overtag.dk/wordpress/wp-content/uploads/spellcheckertar.gz">Download all source code</a> of spell checker example.</p>
<p><strong>Compiling and testing</strong></p>
<p>When you compile, you have to use &#8216;-fdph-par&#8217; for parallel libraries and &#8216;-fpar-seq&#8217; for a similar, but sequential library. Also, you have to add &#8216;-Odph&#8217; to instruct GHC to use the parallel compiler module, &#8216;-threaded&#8217; because we&#8217;re using threads and &#8216;-fcpr-off&#8217; to turn off the CPR optimizer (a trade-off, but I don&#8217;t know how severe).</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ ghc --make -fdph-par -Odph -threaded SpellCheck</pre></div></div>

<p>Now, let&#8217;s test it and see the results. To run with to cores, we add &#8216;+RTS -N2 -RTS&#8217;, and to get some diagnostic output, we add &#8216;+RTS -N2 -sstderr -RTS&#8217;. My results are not very good, because I only have one core <img src='http://overtag.dk/wordpress/wp-includes/images/smilies/face-smile.png' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ .<span style="color: #000000; font-weight: bold;">/</span>SpellCheck +RTS -N2 -sstderr -RTS <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>dict<span style="color: #000000; font-weight: bold;">/</span>words document.txt <span style="color: #000000;">1</span></pre></div></div>

<pre>   1,024,145,348 bytes allocated in the heap
     580,407,632 bytes copied during GC
      33,537,816 bytes maximum residency (16 sample(s))
      15,817,400 bytes maximum slop
              97 MB total memory in use (1 MB lost due to fragmentation)

  Generation 0:  1945 collections,    25 parallel,  3.92s,  4.47s elapsed
  Generation 1:    16 collections,    13 parallel,  1.98s,  2.38s elapsed

  Parallel GC work balance: 1.57 (79357576 / 50670026, ideal 2)

  Task  0 (worker) :  MUT time:   7.88s  (  2.43s elapsed)
                      GC  time:   0.00s  (  0.00s elapsed)

  Task  1 (worker) :  MUT time:   7.88s  (  2.47s elapsed)
                      GC  time:   0.00s  (  0.00s elapsed)

  Task  2 (worker) :  MUT time:   1.99s  (  2.47s elapsed)
                      GC  time:   5.90s  (  6.85s elapsed)

  Task  3 (worker) :  MUT time:   7.88s  (  2.47s elapsed)
                      GC  time:   0.00s  (  0.00s elapsed)

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    1.99s  (  2.47s elapsed)
  GC    time    5.90s  (  6.85s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    7.88s  (  9.32s elapsed)

  %GC time      74.8%  (73.5% elapsed)

  Alloc rate    515,130,747 bytes per MUT second

  Productivity  25.2% of total user, 21.3% of total elapsed</pre>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/04/data-parallel-haskell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GTK and scrolling without scrollbars</title>
		<link>http://overtag.dk/wordpress/2009/01/gtk-and-scrolling-without-scrollbars/</link>
		<comments>http://overtag.dk/wordpress/2009/01/gtk-and-scrolling-without-scrollbars/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 19:09:39 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[full screen]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[gtk.Layout]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rhythmbox]]></category>
		<category><![CDATA[scrolling]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=114</guid>
		<description><![CDATA[There&#8217;s still some work to do on the full screen plugin for Rhythmbox, but the current version is very usable indeed. The latest addition is scrolling by hovering the track list.
I changed the display from a normal fixed table with 3 tracks to a gtk.Layout with a gtk.VBox containing n tracks. In a Layout widget [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s still some work to do on the full screen plugin for Rhythmbox, but the current version is very usable indeed. The latest addition is scrolling by hovering the track list.</p>
<p>I changed the display from a normal fixed table with 3 tracks to a <strong>gtk.Layout</strong> with a <strong>gtk.VBox</strong> containing <em>n</em> tracks. In a Layout widget it&#8217;s possible to freely place and move child widgets, so by detecting motion events on the edges of the Layout you can emulate scrolling by moving a child widget accordingly with <strong>Layout.move(widget, x, y)</strong>. Unfortunately I get a rather nasty blinking effect when scrolling too fast, and I don&#8217;t have an explanation for this, so I&#8217;d be glad to hear from anyone who can help.</p>

<div class="wp_syntax"><div class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">def</span> track_layout_scroll<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, widget, event<span style="color: black;">&#41;</span>:
    time_step = <span style="color: #ff4500;">10</span> <span style="color: #808080; font-style: italic;">#msecs</span>
    ycoord = event.<span style="color: black;">y</span>
    accel_factor = <span style="color: #ff4500;">10</span> <span style="color: #808080; font-style: italic;">#how many pixels to scroll at the edge</span>
    edge_distance = <span style="color: #ff4500;">100.0</span> <span style="color: #808080; font-style: italic;">#pixels</span>
    layout_size = widget.<span style="color: black;">get_size</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    top_dist = edge_distance - ycoord
    bot_dist = edge_distance - layout_size<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + ycoord
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> top_dist <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
        accel = <span style="color: #ff4500;">-1</span> - <span style="color: black;">&#40;</span>top_dist / edge_distance<span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> accel_factor
    <span style="color: #ff7700;font-weight:bold;">elif</span> bot_dist <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
        accel =  <span style="color: #ff4500;">1</span> + <span style="color: black;">&#40;</span>bot_dist / edge_distance<span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> accel_factor
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        accel = <span style="color: #ff4500;">0.0</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">scroll_event_id</span>:
        gobject.<span style="color: black;">source_remove</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">scroll_event_id</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> accel == <span style="color: #ff4500;">0.0</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">scroll_event_id</span> = gobject.<span style="color: black;">timeout_add</span><span style="color: black;">&#40;</span>time_step, <span style="color: #008000;">self</span>.<span style="color: black;">do_scrolling</span>, accel, widget<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> do_scrolling<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, accel, layout_widget<span style="color: black;">&#41;</span>:
    step = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">*</span>accel<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> step == <span style="color: #ff4500;">0</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span>
    vbox_size = <span style="color: #008000;">self</span>.<span style="color: black;">vbox</span>.<span style="color: black;">size_request</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    layout_size = layout_widget.<span style="color: black;">get_size</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    scroll_height = vbox_size<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>-layout_size<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> + step <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">0</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> = <span style="color: #ff4500;">0</span>
    <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> + step <span style="color: #66cc66;">&gt;</span> scroll_height:
        <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> = scroll_height
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> += step
&nbsp;
    <span style="color: #008000;">self</span>.<span style="color: black;">track_layout</span>.<span style="color: black;">move</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">vbox</span>, <span style="color: #ff4500;">0</span>, -<span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> <span style="color: #66cc66;">&lt;</span> scroll_height</pre></div></div>

<p>The code is related to my Rhythmbox plugin, but I&#8217;m sure you get the idea. Also please note, that track_layout_scroll has to receive notify_motion_event from the Layout widget, and that you have to set a size for the Layout widget with set_size().</p>
<p><strong>Update:</strong> By playing around with time_step (lowering it to be more exact) and slowing down the acceleration, I managed to almost make the white flashes disappear.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/01/gtk-and-scrolling-without-scrollbars/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nullable Object must have a value</title>
		<link>http://overtag.dk/wordpress/2008/08/nullable-object-must-have-a-value/</link>
		<comments>http://overtag.dk/wordpress/2008/08/nullable-object-must-have-a-value/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 22:21:57 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Debate]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=69</guid>
		<description><![CDATA[I&#8217;ve been coding a lot of ASP.NET lately using the whole Microsoft portfolio of dev tools, and I&#8217;m in total shock. I had expected to hate it, but not from rational reasoning, but rather because they made it. I thought it was sleek enterprise level stuff. But I was wrong&#8230; here are some obvious rational [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been coding a lot of ASP.NET lately using the whole Microsoft portfolio of dev tools, and I&#8217;m in total shock. I had expected to hate it, but not from rational reasoning, but rather because <i>they</i> made it. I thought it was sleek enterprise level stuff. But I was wrong&#8230; here are some obvious rational reasons to hate it:</p>
<ul>
<li>Runtime error messages are cryptic and un-helpful (see the title of this post). Often they&#8217;re just summarized into texts like &#8220;error in database constraint&#8230; could be null, foreign-key, primary key&#8230; please check all the code you&#8217;ve ever written&#8221;.</li>
<li>System.Collections don&#8217;t support basic stuff like tuples and sets.</li>
<li>DataTables can&#8217;t handle null values. I mean: They call this DRO!?</li>
<li>I tried to edit some SQL in a Table Adapter. It suddenly switched the parameters for the auto-generated method without warning me &#8211; silently breaking the application and giving me hours of debugging.</li>
<li>The design view for aspx files in Visual Studio is useless since it always requires manual editing afterwards</li>
<li>I wanted to copy a database. Since the copy-function was broken in Enterprise Manager (You get an error message and using the &#8220;copy error message&#8221; function renders an &#8220;error copying error message&#8221;) I made a backup and wanted to restore it in a new database. The dialog for this operation silently switched the target for the restore several times &#8211; even the database files: <strong>to overwrite the production database</strong>. Pretty lucky to notice this, since it was hidden in another tab.</li>
<li>Visual Sourcesafe isn&#8217;t a proper versioning system. You might as well just use a network share and depend on ntfs file locking. Where&#8217;s the collaboration!?</li>
<li>There&#8217;s only a very limited amount of free or open applications available for it. And especially Umbraco which is the flagship of .NET CMS systems is full of errors and tells you to pay up as soon as you&#8217;d like the pro stuff &#8211; like say a proper development/deployment system.</li>
<li>Umbraco crashed our IIS &#8211; all we did was use the copy-content function!? How exactly is it that a webpage is allowed to take down a whole server?</li>
</ul>
<p>I could probably ramble on about this. The bottom line is simply: I would never choose <em>their</em> technology over stuff like Subversion, Apache, Java or Python. And the whole ASP.NET framework is far from Ruby and Django &#8211; but of course it&#8217;s a lot older&#8230; it&#8217;s so 2003. I would have filed a few bug reports, but I guess these guys don&#8217;t have a bugzilla. Too bad.. I&#8217;ll just have to leave my feedback on this public blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2008/08/nullable-object-must-have-a-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django tip: Translating your application names (app_label)</title>
		<link>http://overtag.dk/wordpress/2008/07/django-tip-translating-your-application-names-app_label/</link>
		<comments>http://overtag.dk/wordpress/2008/07/django-tip-translating-your-application-names-app_label/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 21:03:57 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[makemessages]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=61</guid>
		<description><![CDATA[This MUST be a common issue for international developers: We use some geeky English name for our application and afterwards find that the translated admin index looks a little silly in the eyes of our native speaking users. Apparently a patch has been accepted in the Django dev version, but it&#8217;s not yet in the [...]]]></description>
			<content:encoded><![CDATA[<p>This MUST be a common issue for international developers: We use some geeky English name for our application and afterwards find that the translated admin index looks a little silly in the eyes of our native speaking users. Apparently <a href="http://code.djangoproject.com/ticket/1668">a patch</a> has been accepted in the Django dev version, but it&#8217;s not yet in the trunk. Here&#8217;s what to do: In your applications&#8217; <em>__init__.py</em> files put:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span>.<span style="color: black;">translation</span> <span style="color: #ff7700;font-weight:bold;">import</span> gettext_noop
gettext_noop<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;AppName&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>When your run <strong>manage.py makemessages -a</strong> there will be entries for these. Make sure to remove lines saying <em>#, fuzzy</em>. Now all you have to do is to customize the default admin template called <em>index.html</em> so it will actually do the translation of the application names.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>18
</pre></td><td class="code"><pre>        &lt;caption&gt;{% trans app.name %}&lt;/caption&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2008/07/django-tip-translating-your-application-names-app_label/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
