<?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>Peter Krantz</title>
	<atom:link href="http://www.peterkrantz.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peterkrantz.com</link>
	<description>A blog about technology, visualization, music and unmanned vehicle experiments</description>
	<lastBuildDate>Sun, 28 Feb 2010 09:46:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Joining the Swedish eGovernment Delegation</title>
		<link>http://www.peterkrantz.com/2009/joining-the-swedish-egovernment-delegation/</link>
		<comments>http://www.peterkrantz.com/2009/joining-the-swedish-egovernment-delegation/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 11:14:43 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/2009/joining-the-swedish-egovernment-delegation/</guid>
		<description><![CDATA[A while ago I was offered a position with the Swedish eGovernment Delegation. 
I will be working with IT standardisation issues and the next revision of guidelines for public websites.
]]></description>
			<content:encoded><![CDATA[<p>A while ago I was offered a position with the <a href="http://en.edelegationen.se/">Swedish eGovernment Delegation</a>. </p>
<p>I will be working with IT standardisation issues and the next revision of guidelines for public websites.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2009/joining-the-swedish-egovernment-delegation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dear DHL (and all other logistics companies)</title>
		<link>http://www.peterkrantz.com/2009/open-letter-to-dhl/</link>
		<comments>http://www.peterkrantz.com/2009/open-letter-to-dhl/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 16:25:51 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Trends]]></category>
		<category><![CDATA[delivery]]></category>
		<category><![CDATA[Deutsche Post]]></category>
		<category><![CDATA[DHL]]></category>
		<category><![CDATA[logistics]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[shipping]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/?p=299</guid>
		<description><![CDATA[Dear <a href="http://www.dp-dhl.com/en">DHL</a> (and other logistics companies because you tend to behave exactly the same). How is it that you are able to move my package from the UK to Sweden fast as hell but spend several days trying to move it from your terminal to my home address in the same city?]]></description>
			<content:encoded><![CDATA[<p>Dear <a href="http://www.dp-dhl.com/en">DHL</a> (and other logistics companies because you tend to behave exactly the same). How is it that you are able to move my package from the UK to Sweden fast as hell but spend several days trying to move it from your terminal to my home address in the same city?</p>
<p><iframe width="540" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?ie=UTF8&amp;msa=0&amp;msid=111980647133829499758.0004770108ab25a4d5791&amp;ll=55.478853,8.876953&amp;spn=14.988694,47.460938&amp;z=4&amp;output=embed"></iframe><br /><small>Visa <a href="http://maps.google.com/maps/ms?ie=UTF8&amp;msa=0&amp;msid=111980647133829499758.0004770108ab25a4d5791&amp;ll=55.478853,8.876953&amp;spn=14.988694,47.460938&amp;z=4&amp;source=embed" style="color:#0000FF;text-align:left">DHL delivery</a> på en större karta</small></p>
<p>Like most people living in Stockholm (and other cities I guess) I live in an apartment building to which you have no access. Also, like most people, I work during the day. Nothing special, just normal office hours, about the same hours when your drivers drive around the city trying to deliver stuff to the empty homes of people who are at work.</p>
<p>Knowing that you will fail to enter the building where I live (it doesn&#8217;t really matter since I&#8217;m not at home anyway), I have tried to contact you to see if I can do a part of your work by going to your terminal myself to pick up my package.</p>
<p>For some unknown reason you can&#8217;t refrain from trying to deliver it my empty home. Maybe it is in he nature of logistics people inherited in genes from loyal post office workers of the good old days? </p>
<p>Anyway, this means I have to wait for you to fail delivery and take the package back to your terminal and then send me a message (through regular mail) that you failed. A process that takes several days.</p>
<p>When I walk home from work I pass a 7-eleven with a sign that says &#8220;DHL Servicepoint&#8221;. It is bright and yellow and only about 150 yards from my home (I can almost see it if I lean out through my living room window). Intrigued by the words &#8220;service&#8221; and &#8220;point&#8221; I inquired, though your eminent call center, if it was possible to have the package delivered there instead? I was hoping I could save both you and me some work (and time).  For unknown reasons you are not allowed to deliver my package to your own servicepoint. Words fail me.</p>
<p>My second suggestion was to change the address so that you may deliver it to my workplace instead. It is a bit of a gamble since I am in meetings throughout the day and may not be around at the exact random time your delivery guy tends to show up. This was possible, your friendly call center employee told me, <strong>but we have to try to deliver the package to your empty home first</strong>.</p>
<p>How hard can it be? I had a crazy idea. What if logistics was all about making use of information to optimize flows of goods? </p>
<p><iframe width="540" height="360" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?ie=UTF8&amp;msa=0&amp;msid=111980647133829499758.0004770108ab25a4d5791&amp;ll=59.452056,17.948914&amp;spn=0.251276,0.741577&amp;z=10&amp;output=embed"></iframe><br /><small>Visa <a href="http://maps.google.com/maps/ms?ie=UTF8&amp;msa=0&amp;msid=111980647133829499758.0004770108ab25a4d5791&amp;ll=59.452056,17.948914&amp;spn=0.251276,0.741577&amp;z=10&amp;source=embed" style="color:#0000FF;text-align:left">DHL delivery</a> på en större karta</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2009/open-letter-to-dhl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The case for uninterrupted work</title>
		<link>http://www.peterkrantz.com/2009/the-case-for-uninterrupted-work/</link>
		<comments>http://www.peterkrantz.com/2009/the-case-for-uninterrupted-work/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 08:23:53 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Methodology]]></category>
		<category><![CDATA[cognition]]></category>
		<category><![CDATA[interruptions]]></category>
		<category><![CDATA[office work]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[worklife]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/?p=296</guid>
		<description><![CDATA[The myth of multitasking:
&#8230; [a] research study, funded by Hewlett-Packard and conducted by the Institute of Psychiatry at the University of London, that found, “Workers distracted by e-mail and phone calls suffer a fall in IQ more than twice that found in marijuana smokers.”
Stanford study: Cognitive control in media multitaskers:
Results showed that heavy media multitaskers [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.thenewatlantis.com/publications/the-myth-of-multitasking">The myth of multitasking</a>:</p>
<blockquote><p>&#8230; [a] research study, funded by Hewlett-Packard and conducted by the Institute of Psychiatry at the University of London, that found, “Workers distracted by e-mail and phone calls suffer a fall in IQ more than twice that found in marijuana smokers.”</p></blockquote>
<p>Stanford study: <a href="http://www.pnas.org/content/early/2009/08/21/0903620106.abstract">Cognitive control in media multitaskers</a>:</p>
<blockquote><p>Results showed that heavy media multitaskers are more susceptible to interference from irrelevant environmental stimuli and from irrelevant representations in memory. This led to the surprising result that <strong>heavy media multitaskers performed worse on a test of task-switching ability</strong>, likely due to reduced ability to filter out interference from the irrelevant task set.</p></blockquote>
<p><a href="http://clair.si.umich.edu/~radev/ilist/0580.html">Meet the Life Hackers</a> &#8211; New York Times Magazine (10/16/05) (based on research by <a href="http://www.ics.uci.edu/~gmark/">Gloria Mark, University of California</a>)</p>
<blockquote><p>Research shows that 40 percent of the time, workers ramble along a different tangent when an interruption ends because their short-term memory has been disrupted. </p></blockquote>
<p>Ho do you manage <em>your</em> interruptions?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2009/the-case-for-uninterrupted-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Opengov.se launched</title>
		<link>http://www.peterkrantz.com/2009/opengovse-launched/</link>
		<comments>http://www.peterkrantz.com/2009/opengovse-launched/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 08:21:27 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[e-Gov]]></category>
		<category><![CDATA[egov]]></category>
		<category><![CDATA[government]]></category>
		<category><![CDATA[open government]]></category>
		<category><![CDATA[public sector]]></category>
		<category><![CDATA[transparency]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/?p=292</guid>
		<description><![CDATA[Says the Open Government Working Group:
The Internet is the public space of the modern world, and through it governments now have the opportunity to better understand the needs of their citizens and citizens may participate more fully in their government. Information becomes more valuable as it is shared, less valuable as it is hoarded. Open [...]]]></description>
			<content:encoded><![CDATA[<p>Says the Open Government Working Group:</p>
<blockquote><p>The Internet is the public space of the modern world, and through it governments now have the opportunity to better understand the needs of their citizens and citizens may participate more fully in their government. Information becomes more valuable as it is shared, less valuable as it is hoarded. Open data promotes increased civil discourse, improved public welfare, and a more efficient use of public resources.</p></blockquote>
<p>&#8230;and this is why I have launched <a href="http://www.opengov.se/">opengov.se</a> &#8211; an initiative to bring swedish public sector data online in open formats. Initially the website contains a catalog of public data sources and information about licensing and formats used.</p>
<p>You can help out by <a href="http://www.opengov.se/data/suggest/">suggesting datasets</a> form the swedish public sector.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2009/opengovse-launched/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Rails vs Grails vs Django models</title>
		<link>http://www.peterkrantz.com/2009/rails-grails-django-models/</link>
		<comments>http://www.peterkrantz.com/2009/rails-grails-django-models/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 16:58:47 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[domain modeling]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/?p=281</guid>
		<description><![CDATA[Coming back to Rails after being away from some time in Django land I discovered a huge difference in how Rails and Django treats your models...]]></description>
			<content:encoded><![CDATA[<p>Coming back to Rails after being away from some time in Django land I discovered a huge difference in how Rails, Grails and Django treats your models. In Django and Grails you can look at a model class and see all the properties it has:</p>
<p>class Organization(models.Model):<br />
&nbsp;&nbsp;name = models.CharField(max_length=255)<br />
&nbsp;&nbsp;url = models.URLField(verify_exists=False)<br />
&nbsp;&nbsp;orgtype = models.ForeignKey(OrgType)</p>
<p>The same model class in Rails typically looks like this:</p>
<p>class Organization &lt; ActiveRecord::Base<br />
&nbsp;&nbsp;belongs_to :OrgType<br />
end</p>
<p>&#8230;and in Grails it is more specific like Django:</p>
<pre>
<pre class="brush: plain;">DQpjbGFzcyBPcmdhbml6YXRpb24gew0KICBTdHJpbmcgbmFtZQ0KICBTdHJpbmcgdXJsDQogIHN0YXRpYyBiZWxvbmdzVG8gPSBPcmdUeXBlDQogIE9yZ1R5cGUgb3JndHlwZQ0KfQ0K</pre>
</pre>
<p>It took me a while to remember that in Rails, parts of the model design is actually stored in the database schema instead of in the Ruby code. Peculiar don&#8217;t you think, given that everything else in a Rails app is nicely declared in Ruby code? There are of course benefits to both approaches, but I have started adding comments in the Rails model classes to be able to remember what properties they have without peeking in the Db. Typically I have a number of half-baked projects on my laptop and from time to time I forget what they do and these comments help me remember.</p>
<p>Check out more examples here:</p>
<ul>
<li><a href="http://docs.djangoproject.com/en/dev/topics/db/models/#topics-db-models">Django models</a></li>
<li><a href="http://www.tutorialspoint.com/ruby-on-rails/rails-models.htm">Rails models</a></li>
<li><a href="https://www.ibm.com/developerworks/java/library/j-grails02128/">Grails models</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2009/rails-grails-django-models/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Remixing Youtube</title>
		<link>http://www.peterkrantz.com/2009/remixing-youtube/</link>
		<comments>http://www.peterkrantz.com/2009/remixing-youtube/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 19:07:38 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Trends]]></category>
		<category><![CDATA[copyright]]></category>
		<category><![CDATA[remix]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/?p=274</guid>
		<description><![CDATA[An interesting approach to chains of copyright but these are really interesting. None of the participants were involved in making these songs. At the same time all of them were. A guess is that remixes like these will become more and more popular. Where can I buy these songs? Who will get paid? More information [...]]]></description>
			<content:encoded><![CDATA[<p>An interesting approach to chains of copyright but these are really interesting. None of the participants were involved in making these songs. At the same time all of them were. A guess is that remixes like these will become more and more popular. Where can I buy these songs? Who will get paid? More information at <a href="http://thru-you.com/">http://thru-you.com/</a></p>
<p><object width="480" height="385" data="http://www.youtube.com/v/EsBfj6khrG4&amp;hl=sv&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/EsBfj6khrG4&amp;hl=sv&amp;fs=1&amp;rel=0" /><param name="allowfullscreen" value="true" /></object></p>
<p><object width="480" height="385" data="http://www.youtube.com/v/vch-Z9ccHTk&amp;hl=sv&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/vch-Z9ccHTk&amp;hl=sv&amp;fs=1&amp;rel=0" /><param name="allowfullscreen" value="true" /></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2009/remixing-youtube/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solving Project Euler Problems With Ioke</title>
		<link>http://www.peterkrantz.com/2009/project-euler-in-ioke/</link>
		<comments>http://www.peterkrantz.com/2009/project-euler-in-ioke/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 18:26:10 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Ioke]]></category>
		<category><![CDATA[euler]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/?p=256</guid>
		<description><![CDATA[For those of you that have been following Ola Bini's work on <a href="http://ioke.org/">Ioke</a>, the dynamic language for the JVM, I am happy to report that the current release 0.1.1 is usable enough to solve <a href="http://projecteuler.net/">Project Euler</a> problems with. I wanted to learn more about Ioke and the best way to learn a new language is to use it on your own. So, here is some example Ioke code for some of the simpler Project Euler problems.]]></description>
			<content:encoded><![CDATA[<p>For those of you that have been following Ola Bini&#8217;s work on <a href="http://ioke.org/">Ioke</a>, the dynamic language for the JVM, I am happy to report that the current release 0.1.1 is usable enough to solve <a href="http://projecteuler.net/">Project Euler</a> problems with. I wanted to learn more about Ioke and the best way to learn a new language is to use it on your own. So, here is some example Ioke code for some of the simpler Project Euler problems.</p>
<h2>Problem 1</h2>
<p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.</p>
<p>Brute force version below.</p>
<pre class="brush: jscript;">
n = 1
sum = 0
while(n &lt; 1000,
      if(n % 3 == 0 or n % 5 == 0, sum += n)
      n++
)
sum println
</pre>
<p>Or, as a one-liner after a suggestion from Ola:</p>
<p>(1..999) select(n, n % 3 == 0 or n % 5 == 0) fold(+) println </p>
<h2>Problem 2</h2>
<p>Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, &#8230; Find the sum of all the even-valued terms in the sequence which do not exceed four million.</p>
<pre class="brush: plain;">
sum = 0
fibs = [0, 1]
current_fib = 0
while(current_fib &lt; 4000000,
    current_fib = fibs[0] + fibs[1]
    if(current_fib % 2 == 0, sum += current_fib)
    fibs[0] = fibs[1]
    fibs[1] = current_fib
)
sum println
</pre>
<h2>Problem 3</h2>
<p>The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143?</p>
<p>Using brute force for this one. Faster and more elegant would have been the Rho algorithm.</p>
<pre class="brush: jscript;">
start = 600851475143
num = start
factor = 2

while(factor * factor &lt;= num,
    if(num % factor == 0,
        factor println
        num = num / factor,
        factor++
    )
)

if(num != 1, num println)
</pre>
<h2>Problem 5</h2>
<p>2520 is the smallest number that can be divided by each of the numbers  from 1 to 10 without any remainder. What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?</p>
<p>First, as the numbers 1 to 10 are factors in the numbers 11 to 20 we only need to check divisibility for the the latter. Starting of by setting up methods for greatest common divisor and least common multiple. Brute forcing this by looping over an incremented number will not work in the current version of Ioke (takes a couple of hours). Brute forcing it in Ruby took a couple of seconds.</p>
<pre class="brush: jscript;">
gcd = method(a, b,
    if(b == 0, a,
        gcd(b, a % b)
    )
)

lcm = method(a, b,
    (a / gcd(a, b)) * b
)

(11..20) inject(number, n, lcm(number, n)) println
</pre>
<h2>Problem 18</h2>
<p>Find the maximum total from top to bottom of the triangle below. This solution also works for problem 67 (a much bigger triangle).</p>
<p>By moving from bottom to top, calculating each cell&#8217;s maximum sum and replacing the value with it we&#8217;ll end up with the total in the first cell in the triangle.</p>
<pre class="brush: jscript;">
triangle = [
[75],
[95, 64],
[17, 47, 82],
[18, 35, 87, 10],
[20, 04, 82, 47, 65],
[19, 01, 23, 75, 03, 34],
[88, 02, 77, 73, 07, 63, 67],
[99, 65, 04, 28, 06, 16, 70, 92],
[41, 41, 26, 56, 83, 40, 80, 70, 33],
[41, 48, 72, 33, 47, 32, 37, 16, 94, 29],
[53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14],
[70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57],
[91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48],
[63, 66, 04, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31],
[04, 62, 98, 27, 23, 09, 70, 98, 73, 93, 38, 53, 60, 04, 23],
]

;; We replace cells from the bottom up by finding the max sum for each
;; position in the triangle.

current_row = triangle length - 2

while(current_row &gt; -1,
    pos = 0
    while(pos &lt; triangle[current_row] length,
        triangle[current_row][pos] = triangle[current_row][pos] + \
        ([triangle[current_row + 1][pos], triangle[current_row + 1][pos + 1]] sort)[1]
        pos++
    )

    current_row = current_row - 1
)

triangle[0][0] println
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2009/project-euler-in-ioke/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Integrating Yahoo Search in a Django site in 5 easy steps</title>
		<link>http://www.peterkrantz.com/2008/yahoo-search-in-django/</link>
		<comments>http://www.peterkrantz.com/2008/yahoo-search-in-django/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 12:38:17 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[boss]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[yahoo boss]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/?p=247</guid>
		<description><![CDATA[I have been experimenting with various search options for the eutveckling.se site for a while. Google Custom Search is nice and very fast, but the number of ads appearing in the search result page makes it difficult for users to separate result items from ads. (Update: I am sticking with Google Custom Search until I [...]]]></description>
			<content:encoded><![CDATA[<p>I have been experimenting with various search options for the <a href="http://www.eutveckling.se/">eutveckling.se</a> site for a while. Google Custom Search is nice and very fast, but the number of ads appearing in the search result page makes it difficult for users to separate result items from ads. (Update: I am sticking with Google Custom Search until I figure out how to get Yahoo search to present proper excerpts).</p>
<p>I am a fast reader which comes with the tradeoff of missing important information sometimes. Skimming through the terms for using the API I was a bit disappointed at first. That was because I was only reading the first column in the table that lists the <strong>previous </strong>terms of use. Oh well. The second column that lists the current restrictions (or rather lack of restrictions) makes it clear that Yahoo search is very easy to get started with. It is almost so that you start wondering where Yahoo will make money from providing a service like that.</p>
<p>Anyway, here are the five simple steps to get Yahoo search integrated in your Django site:</p>
<h2>1. Get an API Key</h2>
<p>&#8230;or &#8220;application ID&#8221; as Yahoo calls it. Visit <a href="http://developer.yahoo.com/wsregapp/">this page to sign up for an API key</a>.</p>
<h2>2. Install the pYsearch library</h2>
<p>Download <a href="http://pysearch.sourceforge.net/">pYsearch</a> from Sourceforge to your computer (here is the <a href="http://garr.dl.sourceforge.net/sourceforge/pysearch/pYsearch-3.1.tar.gz">direct link to the package</a>), and:</p>
<p><kbd>tar xvf pYsearch-3.1.tar.gz</kbd></p>
<p><kbd>cd pYsearch</kbd></p>
<p><kbd>sudo python setup.py build</kbd></p>
<p><kbd>sudo python setup.py install</kbd></p>
<p>This should install pYsearch somewhere on your Python path.</p>
<h2>3. Set up URL-pattern and view method</h2>
<p>In your urls.py add a URL-pattern to pick up search requests. We&#8217;ll use queries like /search/?q=myquery:</p>
<pre>url(r'^search/$', 'myapp.views.search', name='site_search'),</pre>
<p>Set up the view method in your application&#8217;s views.py (make sure the search query is encoded to utf-8 to enable characters outside ISO-8859-1 in the query parameter):</p>
<pre>from yahoo.search.web import WebSearch

def search(request):
	query = request.GET.get("q", "").encode("utf-8")

	if len(query) &gt; 0:

		#Call yahoo!
		api_key = "[your api key]"
		srch = WebSearch(api_key)
		srch.site = "www.example.com" #restrict to your own site
		srch.query = query
		srch.results = 50
		result = srch.parse_results() #puts all result items into a dict

	return render_to_response('search/search.html', locals())</pre>
<h2>4. And now the search form and result template</h2>
<p>Add the search field and form somewhere on your site:</p>
<pre>&lt;form action="/search/" method="GET"&gt;
	&lt;div&gt;
	&lt;label for="q""&gt;Find:&lt;/label&gt;
	&lt;input type="text" name="q" accesskey="4" size="30" id="q" value="{{query}}"&gt;
	&lt;input type="submit" value="Search"&gt;
	&lt;/div&gt;
&lt;/form&gt;</pre>
<p>The base.html sets up the basic web page. This template lives in myapp/templates/search/search.html</p>
<pre>{% extends 'base.html' %}
{% block content %}
	{% if result.results %}
        &lt;ul class="searchresult"&gt;
	{% for item in result %}
	&lt;li&gt;
           &lt;h2&gt;&lt;a href="{{item.Url}}"&gt;{{item.Title}}&lt;/a&gt;&lt;/h2&gt;
           &lt;p&gt;{{item.Summary|cut:" ..."}}...&lt;/p&gt;
        &lt;/li&gt;
        {% endfor %}
        &lt;/ul&gt;
{% else %}
Suggestion:
&lt;ul&gt;
	&lt;li&gt;Check your spelling.&lt;/li&gt;
	&lt;li&gt;Try similar words.&lt;/li&gt;
&lt;/ul&gt;
{% endif %}
{% endblock %}</pre>
<h2>5. There is no step 5!</h2>
<p>That&#8217;s it! Your site should now have a nice search engine. Some issues you may encounter:</p>
<ol>
<li>Yahoo does not seem to have indexed all of <a href="http://www.eutveckling.se">eutveckling.se</a> yet. This means that the result set will be limited. No PDF documents seem to have been included (<a href="http://www.eutveckling.se/sok/?q=V%C3%A4gledningen+24-timmarswebben">searching for &#8220;Vägledningen 24-timmarswebben&#8221;</a> does not return <a href="http://www.eutveckling.se/sok/?q=V%C3%A4gledningen+24-timmarswebben">the PDF document</a> even though it has many links on the site). It would be nice to be able to see how much of the site that the search engine knows about.</li>
<li>The summary text for each page seems to be the same (including hidden skiplink text). This may be my fault as I haven&#8217;t provided meta description elements yet. I have added som CSS classnames (robots-nocontent) to navigation elements to help the search engine decide on what should be included and what should be skipped. I had expected that the summary would contain a phrase close to the query term instead of text from the top of the page.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2008/yahoo-search-in-django/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Twitter synchronicity</title>
		<link>http://www.peterkrantz.com/2008/twitter-synchronicity/</link>
		<comments>http://www.peterkrantz.com/2008/twitter-synchronicity/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 09:15:32 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Trends]]></category>
		<category><![CDATA[synchronicity]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/?p=244</guid>
		<description><![CDATA[Everyone is celebrating this friday in a different way, apparently:

]]></description>
			<content:encoded><![CDATA[<p>Everyone is celebrating this friday in a different way, apparently:</p>
<p><img class="alignnone size-full wp-image-245" title="twitter synchronicity" src="http://www.peterkrantz.com/wp-content/uploads/2008/11/twitter-synchronicity.gif" alt="Tweets from different people about how they spend their friday. Schyffel is celebrating buy nothing day, Johan lind is ordering books and Isac is hung over." /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2008/twitter-synchronicity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Sun Should Do</title>
		<link>http://www.peterkrantz.com/2008/what-sun-should-do/</link>
		<comments>http://www.peterkrantz.com/2008/what-sun-should-do/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 09:35:49 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Trends]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[marketing]]></category>
		<category><![CDATA[sun]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/?p=242</guid>
		<description><![CDATA[Tim Bray has an interesting post titled What Sun Should Do where he lists some suggestions. I have been thinking about Sun for a while and how my own image of the company has changed over the years. A long time ago I was working for Cambridge Technology Partners (later acquired by Novell). We did [...]]]></description>
			<content:encoded><![CDATA[<p>Tim Bray has an interesting post titled <a href="http://www.tbray.org/ongoing/When/200x/2008/11/24/What-Sun-Should-Do">What Sun Should Do</a> where he lists some suggestions. I have been thinking about Sun for a while and how my own image of the company has changed over the years. A long time ago I was working for Cambridge Technology Partners (later acquired by Novell). We did a lot of interesting projects, some of which were deployed on Sun hardware. At that time (around &#8216;97-&#8217;98) my image of Sun was that it was a huge company selling huge hardware at huge prices.</p>
<p>That image stuck with me (and a lot of other people I guess). But interesting things have happened over the years that changed how I think about Sun:</p>
<ol>
<li>Bad: At one point I got the impression that Sun wanted Java on pretty much any platform you could think of. We were supposed to have java on the desktop, server, mobile phone, client, backend, both <a href="https://www.sun.com/accessibility/docs/java_basics.jsp">country</a> and <a href="http://www.microsoft.com/mscorp/java/default.mspx">western</a> as Mark Pilgrim would have put it. The Swing based GUIs really didn&#8217;t help the user experience in the early days.</li>
<li>Good: Someone sent me an email sometime in 2005 saying that Sun was going to let people <a href="http://blogs.sun.com/jonathan/date/20051218">borrow a T2000 server</a> for free. I checked prices and even though it was expensive compared to a grey box it was a major dent in the Sun-is-expensive image I had had previously. I know other people were talking about this as well even though we mainly did business consulting at the time. Must have been a marketing genious that came up with that plan. I didn&#8217;t even work with hardware and I still remember the campaign!</li>
<li>Good: Sun open sourced Solaris. This was a major one. I downloaded the DVD image files as soon as they became available. I know a lof of other people who did this as well. Never used it since even though I have looked for it.</li>
<li>Good: Zones. At one point I believe everyone I knew wanted to set up their own hosting business selling zones to Rails and PHP developers. Noone did. I don&#8217;t know why, but Linux virtualization was beginning to increase market share. Having tried both Xen and Zones, Zones felt a lot better. But everyone is <a href="http://www.comparevps.com/">selling Linux-based virtualization with Linux-based OSs anyhow</a> (try filtering for Solaris in the list). Why?</li>
<li>Good: And now the <a href="http://blogs.sun.com/mws/entry/introducing_the_sun_storage_7000">storage thing</a>. Having seen the bill from a government agency for their current storage solution I am beginning to think that Sun storage will have a huge impact.</li>
<li>Good: Glassfish. I know a lof of people doing Rails development and many are starting deployment on a tiny Linux VPS and then move it to a Glassfish instance once income is increasing.</li>
</ol>
<p>So, in the end I guess Sun isn&#8217;t that enormous massively over priced giant anymore. But why aren&#8217;t people running their web apps on Sun hardware or on Solaris? I guess one of the reasons is about scaling down. There are many Linux-based VPS providers out there running on cheap hardware. The cost/Mb RAM for a VPS is tiny these days and maybe it is too costly to get even a small Sun server up and running you want to resell capacity.</p>
<p>So, why aren&#8217;t everyone using Open Solaris on beige boxes? Beats me. The community seems helpful. Maybe there just isn&#8217;t enough tutorials/blog articles about getting Rails, Django and Drupal installed and configured. Maybe it needs a better package system and/or setup tool for the command line?</p>
<p>What do you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2008/what-sun-should-do/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
