<?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>seeking immortality &#187; code</title>
	<atom:link href="http://blag.sebacean.net/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blag.sebacean.net</link>
	<description>where are we going, and why am i in this handbasket</description>
	<lastBuildDate>Tue, 22 Dec 2009 23:26:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>o2 Germany billparser (zählt Minuten und SMS)</title>
		<link>http://blag.sebacean.net/2009/03/o2-germany-billparser-zahlt-minuten-und-sms/</link>
		<comments>http://blag.sebacean.net/2009/03/o2-germany-billparser-zahlt-minuten-und-sms/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 17:19:53 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[german]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[money]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blag.sebacean.net/?p=95</guid>
		<description><![CDATA[Nach den angekündigten Preiserhöhungen bei o2 (Golem) habe ich meinen (im Sommer auslaufenden) Vertrag mit einem entsprechend erbostem Schreiben gekündigt. Um nun einen guten neuen Vertrag zu finden wollte ich genauer wissen wieviel Minuten/SMS ich denn so brauche&#8230; Da ich schon seit Langem immer fleißig die .csv files zu den Rechnungen herunterladen hab ich schnell]]></description>
			<content:encoded><![CDATA[<p>Nach den angekündigten Preiserhöhungen bei o2 (<a href="http://www.golem.de/0903/65649.html">Golem</a>) habe ich meinen (im Sommer auslaufenden) Vertrag mit einem entsprechend erbostem Schreiben gekündigt. Um nun einen guten neuen Vertrag zu finden wollte ich genauer wissen wieviel Minuten/SMS ich denn so brauche&#8230;</p>
<p>Da ich schon seit Langem immer fleißig die .csv files zu den Rechnungen herunterladen hab ich schnell folgendes Python Script geschrieben das mir die Zählarbeit erleichtert (und Schreikrämpfe in Excel verhindert).</p>
<p>Als kleinen Bonus zählt es auch (etwas inexakt fürchte ich) die Homezone Minuten, daraus kann man ablesen was das Verlieren von Genion für Auswirkungen hat.</p>
<pre class="brush: python">
# parses .csv files from o2 germany billing
# counts talked minutes (&#039;sprache&#039; in &#039;ART&#039;) and sms sent (&#039;sms&#039; in &#039;TARIFGRUPPE&#039;)
# ignores international minutes/sms
import csv
import glob
import string

# &lt;config&gt;
mypath = &#039;*.csv&#039; # e.g. &#039;./mybills/*.csv&#039;
mydelimiter = &#039;|&#039; # &#039;|&#039; aka &quot;pipe&quot; is default with o2
# &lt;/config&gt;

if __name__ == &quot;__main__&quot;:
files = glob.glob(mypath)
assert len(files) &gt; 0, &quot;Error! No Files found (check path)&quot;

totalminutes = 0
totalsms = 0
totalhomezone = 0
for file in files:
csvfile = open(file)
reader = csv.DictReader(csvfile,delimiter=mydelimiter)
smscount = 0
timecount = dict(hours=0,minutes=0,seconds=0)
homezonecount = 0
for row in reader:
if &#039;sprache&#039; in string.lower(row[&#039;ART&#039;]):
(h,m,s) = string.split(row[&#039;DAUER&#039;], &#039;:&#039;)
timecount[&#039;hours&#039;] += int(h)
timecount[&#039;minutes&#039;] += int(m)
timecount[&#039;seconds&#039;] += int(s)
if &#039;homezone&#039; in string.lower(row[&#039;TARIFGRUPPE&#039;]):
homezonecount += int(m) + (int(h)*60) + (int(s)/60)
if &#039;sms&#039; in string.lower(row[&#039;TARIFGRUPPE&#039;]):
smscount = smscount + 1
minutes = timecount[&#039;minutes&#039;] + (timecount[&#039;hours&#039;]*60) + (timecount[&#039;seconds&#039;]/60)
totalminutes += minutes
totalsms += smscount
totalhomezone += homezonecount
print(file+&#039; &#039;+str(minutes)+&#039; Minutes &#039;+str(smscount)+&#039; SMS (&#039;+str(homezonecount)+&#039; Minutes in Homezone)&#039;)
assert minutes &gt;= homezonecount, &quot;Error! More minutes in homezone than total?&quot;
# the cool .format prints only work in python 2.6 ...
#print(&#039;Total  :{0:4} Minutes and {1:4} SMS in {2} Months ({3:4} Minutes in Homezone)&#039;.format(totalminutes,totalsms,len(files),totalhomezone))
#print(&#039;Average:{0:4} Minutes and {1:4} SMS per Month&#039;.format(totalminutes/len(files),totalsms/len(files)))
# ... and since that isn&#039;t in debian stable yet... i added &quot;old&quot; prints
print(&#039;Total   &#039;+str(totalminutes)+&#039; Minutes &#039;+str(totalsms)+&#039; SMS in &#039;+str(len(files))+&#039; Months (&#039;+str(totalhomezone)+&#039; Minutes in Homezone)&#039;)
print(&#039;Average &#039;+str(totalminutes/len(files))+&#039; Minutes &#039;+str(totalsms/len(files))+&#039; SMS per Month&#039;)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blag.sebacean.net/2009/03/o2-germany-billparser-zahlt-minuten-und-sms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>xslt sample: factorial (named template)</title>
		<link>http://blag.sebacean.net/2009/01/xslt-sample-factorial-named-template/</link>
		<comments>http://blag.sebacean.net/2009/01/xslt-sample-factorial-named-template/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 21:36:22 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://blag.sebacean.net/?p=75</guid>
		<description><![CDATA[Currently learning for an exam and freshing up my XSLT knowledge &#8230; &#60;?xml version=&#34;1.0&#34;?&#62; &#60;xsl:stylesheet version=&#34;1.0&#34; xmlns:xsl=&#34;http://www.w3.org/1999/XSL/Transform&#34;&#62; &#60;!-- ! Small XSLT prog that calculates the faculty of one or more ! numbers by recursively calling a named template ! numbers are expected to be in a tree: ! &#60;nums&#62;&#60;num&#62;1&#60;/num&#62;&#60;num&#62;2&#60;/num&#62;...&#60;/nums&#62; --&#62; &#60;xsl:output method=&#34;text&#34;/&#62; &#60;xsl:template match=&#34;num&#34;&#62; &#60;xsl:text&#62;fak(&#60;/xsl:text&#62;]]></description>
			<content:encoded><![CDATA[<p>Currently learning for an exam and freshing up my XSLT knowledge &#8230; <img src='http://blag.sebacean.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre class="brush: xslt">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot;
  xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
  &lt;!--
    ! Small XSLT prog that calculates the faculty of one or more
    ! numbers by recursively calling a named template
    ! numbers are expected to be in a tree:
    ! &lt;nums&gt;&lt;num&gt;1&lt;/num&gt;&lt;num&gt;2&lt;/num&gt;...&lt;/nums&gt;
   --&gt;

  &lt;xsl:output method=&quot;text&quot;/&gt;

  &lt;xsl:template match=&quot;num&quot;&gt;
      &lt;xsl:text&gt;fak(&lt;/xsl:text&gt;
      &lt;xsl:value-of select=&quot;.&quot;/&gt;
      &lt;xsl:text&gt;) is &lt;/xsl:text&gt;
      &lt;xsl:call-template name=&quot;fak&quot;&gt;
          &lt;xsl:with-param name=&quot;number&quot; select=&quot;.&quot;/&gt;
      &lt;/xsl:call-template&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template name=&quot;fak&quot;&gt;
      &lt;xsl:param name=&quot;number&quot;/&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test=&quot;$number = 1&quot;&gt;
              &lt;xsl:value-of select=&quot;$number&quot;/&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
              &lt;xsl:variable name=&quot;recursefak&quot;&gt;
                  &lt;xsl:call-template name=&quot;fak&quot;&gt;
                      &lt;xsl:with-param name=&quot;number&quot; select=&quot;$number - 1&quot;/&gt;
                  &lt;/xsl:call-template&gt;
              &lt;/xsl:variable&gt;
              &lt;xsl:value-of select=&quot;$number * $recursefak&quot;/&gt;
          &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>
<p>Expected XML looks like this (with DTD even! ;P):</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; ?&gt;
&lt;!DOCTYPE numbers [
  &lt;!ELEMENT nums (num+)&gt;
  &lt;!ELEMENT num (#PCDATA)&gt;
]&gt;
&lt;nums&gt;
  &lt;num&gt;3&lt;/num&gt;
  &lt;num&gt;12&lt;/num&gt;
&lt;/nums&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blag.sebacean.net/2009/01/xslt-sample-factorial-named-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP DateTime bugs:  i hate i18n</title>
		<link>http://blag.sebacean.net/2008/03/php-datetime-bugs-i-hate-i18n/</link>
		<comments>http://blag.sebacean.net/2008/03/php-datetime-bugs-i-hate-i18n/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 18:36:58 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blag.sebacean.net/2008/03/11/php-datetime-bugs-i-hate-i18n/</guid>
		<description><![CDATA[Handling different dates and timezones in an application is &#8211; like most aspects of i18n &#8211; very annoying (to put it mildly)&#8230; Recently we discovered the following behaviour at work&#8230; If you create a DateTime object like this (in the current stable version of php, 5.2.3): &#60;?php $oDateTest = new DateTime("@0", new DateTimeZone(date_default_timezone_get())); echo "tz:]]></description>
			<content:encoded><![CDATA[<p>Handling different dates and timezones in an application is &#8211; like most aspects of i18n &#8211; very annoying (to put it mildly)&#8230; Recently we discovered the following behaviour at work&#8230;</p>
<p>If you create a DateTime object like this (in the current stable version of php, 5.2.3):</p>
<pre name="code" class="php:nogutter">&lt;?php
$oDateTest = new DateTime("@0", new DateTimeZone(date_default_timezone_get()));
echo "tz: ".$oDateTest-&gt;getTimezone()-&gt;getName()."\n";
echo "date: ". $oDateTest-&gt;format("Y-m-d H:i:s")."\n";
?&gt;</pre>
<p>It will be in the default timezone (&#8216;Europe/Berlin&#8217; in my case) but say the date is 1970-01-01 00:00. This is wrong. The Unix timestamp &#8220;0&#8243; stands for that exact date, but in another timezone: UTC. It should be 01:00 in Berlin.</p>
<p>This bug was reported multiple times, but with sometimes confusing bug reports. But someone had managed to submit a clear bug report with code to reproduce the behaviour (<a href="http://bugs.php.net/bug.php?id=43003">PHP Bug 43003</a>) and the php developers acknowledged the bug and issued a fix that i verified to be (at least) in the following snapshots: php5.2-200803111530 and php5.3-200803111530.</p>
<p>Sadly, this fix is at best &#8220;unintuitive&#8221;, maybe it even qualifies as &#8220;still broken&#8221;. The above code gives the following output in these snapshots:</p>
<blockquote><p> tz: +00:00<br />
date: 1970-01-01 00:00:00</p></blockquote>
<p>So, the DateTime object now knows that UNIX timestamps always are given in UTC and sets it&#8217;s timezone accordingly. But is this what it should do in this case? I &#8211; the programmer &#8211; clearly stated i wanted the DateTime object to be in my default timezone! Even if i explicitly give the timezone as &#8216;Europe/Berlin&#8217; during construction, the object&#8217;s timezone still is UTC afterwards.</p>
<p>So instead of knowing that i have to manually set the DateTime to UTC, then back to my desired timezone when working with an UNIX timestamp i now have to know that a DateTime will be in UTC after setting it up with a UNIX timestamp. Personally i hate having to know things, IMHO it&#8217;s a sign of weak design. The API has to be clear, i don&#8217;t give a rat&#8217;s backside about the inner workings and struggles of the objects i use.</p>
<p>We went from this:</p>
<pre name="code" class="php:nogutter">// FIXME: DateTime issue... needs the conversion to and from UTC...
$oDateTest = new DateTime("@0", new DateTimeZone('UTC'));
$oDateTest-&gt;setTimezone(new DateTimeZone("Europe/Berlin"));
</pre>
<p>To this:</p>
<pre name="code" class="php:nogutter">// FIXME: DateTime issue... will always be UTC afterwards...
$oDateTest = new DateTime("@0", new DateTimeZone('Europe/Berlin')); // or UTC, or what/ever....
$oDateTest-&gt;setTimezone(new DateTimeZone("Europe/Berlin"));
</pre>
<p>Is this better or worse?</p>
]]></content:encoded>
			<wfw:commentRss>http://blag.sebacean.net/2008/03/php-datetime-bugs-i-hate-i18n/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
