<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">
 <title>trepca's notes</title>
 
 <link href="http://trepca.si/" />
 <updated>2011-08-20T00:54:14-07:00</updated>
 <id>http://trepca.si/</id>
 <author>
   <name>Sebastjan Trepca</name>
   <email>trepca@gmail.com</email>
 </author>
 
 <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/trepca" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="trepca" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
   <title>Sharded counters for Django</title>
   <link href="http://trepca.si/2011/05/21/sharded-counters-for-django.html" />
   <updated>2011-05-21T00:00:00-07:00</updated>
   <id>http://trepca.si/2011/05/21/sharded-counters-for-django</id>
   <content type="html">&lt;h1 id='sharded_counters_for_django'&gt;Sharded counters for Django&lt;/h1&gt;
&lt;script src='https://gist.github.com/984892.js'&gt; &lt;/script&gt;
&lt;p&gt;Comments?&lt;/p&gt;</content>
   <author>
     <name>Sebastjan Trepca</name>
     <uri>http://trepca.si/about.html</uri>
   </author>
 </entry>
 
 <entry>
   <title>Bad Error Messages</title>
   <link href="http://trepca.si/2011/01/16/bad-error-messages.html" />
   <updated>2011-01-16T00:00:00-08:00</updated>
   <id>http://trepca.si/2011/01/16/bad-error-messages</id>
   <content type="html">&lt;h1 id='bad_error_messages'&gt;Bad Error Messages&lt;/h1&gt;

&lt;p&gt;I&amp;#8217;m surprised programmers don&amp;#8217;t talk more about error messages. We encounter them every day, yet you rarely see any constructive discussion about them, maybe&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/noerror.jpg' alt='error: no error' /&gt;&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s take Python for example:&lt;/p&gt;

&lt;h3 id='indexerror_and_valueerror'&gt;IndexError and ValueError&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;index = 10
empty_list = [1,2,3,4,5,6,7,8,9]
for x in range(1000):
     empty_list[index + x]

Traceback (most recent call last):
    File &amp;quot;&amp;lt;stdin&amp;gt;&amp;quot;, line 1, in &amp;lt;module&amp;gt;
IndexError: list index out of range

empty_list.index(&amp;#39;hehe&amp;#39;)

Traceback (most recent call last):
    File &amp;quot;&amp;lt;stdin&amp;gt;&amp;quot;, line 1, in &amp;lt;module&amp;gt;
ValueError: list.index(x): x not in list&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;Printing out &lt;em&gt;which&lt;/em&gt; index was out of range would definitely save me a minute or more, not to mention how annoying this is for newbies.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ValueError: 10 not in list [1,2,3,4 ...]&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;h3 id='paranthesis_of_hell'&gt;Paranthesis of hell&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; if 1:
    ...     test = ((1,2, 3)
    ...     test2 = None
File &amp;quot;&amp;lt;stdin&amp;gt;&amp;quot;, line 3
    test2 = None
         ^
SyntaxError: invalid syntax&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;Python forums are full of these questions. Would it be so hard to add (&amp;#8220;Maybe you&amp;#8217;re missing an end parathesis?&amp;#8221;)&lt;/p&gt;

&lt;p&gt;In general, I try to &lt;strong&gt;suggest solutions&lt;/strong&gt; and provide some &lt;strong&gt;context&lt;/strong&gt; to the error, that way it&amp;#8217;s much easier for other people to debug.&lt;/p&gt;</content>
   <author>
     <name>Sebastjan Trepca</name>
     <uri>http://trepca.si/about.html</uri>
   </author>
 </entry>
 
 <entry>
   <title>Complex data migrations with South</title>
   <link href="http://trepca.si/2010/10/23/complex-data-migrations-with-south.html" />
   <updated>2010-10-23T00:00:00-07:00</updated>
   <id>http://trepca.si/2010/10/23/complex-data-migrations-with-south</id>
   <content type="html">&lt;h1 id='complex_data_migrations_with_south'&gt;Complex data migrations with South&lt;/h1&gt;

&lt;p&gt;You&amp;#8217;re in the middle of a project when you realise that your database model needs a refactoring to support latest changes. What to do? Meet South, a migration tool for Django applications. It will track changes in your models and help you migrate as your project develops. Most changes can be detected automatically, like adding and removing fields. Once you start renaming things and moving them it can get tricky.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WARNING: always make backups before doing any migrations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s say we have a Todo application with these models:&lt;/p&gt;
&lt;script src='http://gist.github.com/585637.js'&gt; &lt;/script&gt;
&lt;p&gt;But you later on figure out that it would actually be much better if you&amp;#8217;d refactor to this:&lt;/p&gt;
&lt;script src='http://gist.github.com/585617.js'&gt; &lt;/script&gt;
&lt;p&gt;Now, if you just change the models to this and run auto migration, South will remove all your data and create new models. Not really what you expected.&lt;/p&gt;

&lt;p&gt;As South can only detect simple changes, we need to be smart, so what to do?&lt;/p&gt;

&lt;p&gt;Lets first generate new models by appending them in our models.py, so we can use south normally.&lt;/p&gt;
&lt;script src='http://gist.github.com/642632.js'&gt; &lt;/script&gt;
&lt;p&gt;This will detect new models and generate them. Sweet, but what about data? Meet data migrations.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;./manage.py datamigration todolist move_to_submodels&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create an empty &lt;code&gt;00NN_move_to_submodels.py&lt;/code&gt; file, ready to be used for data migration. Lets say that Todo instances with location or all_day field set are Events otherwise it&amp;#8217;s a Task.&lt;/p&gt;

&lt;p&gt;We add this code:&lt;/p&gt;
&lt;script src='http://gist.github.com/642623.js'&gt; &lt;/script&gt;
&lt;p&gt;We now migrate again and check if data was migrated correctly. Once you&amp;#8217;re sure everything is ok, you can delete Todo model from models.py and migrate to delete the table forever.&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s it.&lt;/p&gt;</content>
   <author>
     <name>Sebastjan Trepca</name>
     <uri>http://trepca.si/about.html</uri>
   </author>
 </entry>
 
 <entry>
   <title>Quicksilver plugin for org-mode</title>
   <link href="http://trepca.si/2010/09/19/quicksilver-plugin-for-orgmode.html" />
   <updated>2010-09-19T00:00:00-07:00</updated>
   <id>http://trepca.si/2010/09/19/quicksilver-plugin-for-orgmode</id>
   <content type="html">&lt;h1 id='quicksilver_plugin_for_orgmode'&gt;Quicksilver plugin for org-mode&lt;/h1&gt;

&lt;p&gt;Add this script:&lt;/p&gt;
&lt;script src='http://gist.github.com/585898.js'&gt; &lt;/script&gt;
&lt;p&gt;to&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;~/Library/Application Support/Quicksilver/Actions/&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;Set your org-mode capture templates like this (lines 9-10):&lt;/p&gt;
&lt;script src='http://gist.github.com/585901.js'&gt; &lt;/script&gt;
&lt;p&gt;Restart Quicksilver, write some text and then search for &amp;#8220;Task&amp;#8221; in second step. Press Enter and it should be in your orgmode inbox. Yay!&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/quicksilver-orgmode.jpg' alt='orgmode plugin for quicksilver in action' /&gt;&lt;/p&gt;</content>
   <author>
     <name>Sebastjan Trepca</name>
     <uri>http://trepca.si/about.html</uri>
   </author>
 </entry>
 
 <entry>
   <title>How to read Twitter effectively</title>
   <link href="http://trepca.si/2010/06/23/reading-twitter-effectively.html" />
   <updated>2010-06-23T00:00:00-07:00</updated>
   <id>http://trepca.si/2010/06/23/reading-twitter-effectively</id>
   <content type="html">&lt;h1 id='how_to_read_twitter_effectively'&gt;How to read Twitter effectively&lt;/h1&gt;

&lt;p&gt;I was really happy when Twitter lists came out. Before, you&amp;#8217;d have to go through almost every update, to see if any of your favorites published something. You&amp;#8217;re left with either spending a lot of time, reading your timeline or being really careful who you follow. None of them being the right solution. With lists, you just need a multi-view Twitter client like Tweetdeck or Seesmic and setup a few lists by topic and priority. In my case, I have personal, business, tech-news, fun, developers, london, slovenia and news. Ordered by priority. Now, whenever I&amp;#8217;m in a hurry, I just check the first column to check for important updates. When I have more time, I check other ones. It&amp;#8217;s just super easy and effective.&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/tweetdeck.jpg' alt='a great overview of your twitter streams' /&gt;&lt;/p&gt;

&lt;p&gt;I know it&amp;#8217;s a pain to categorise all your friends, but it&amp;#8217;s really worth it and transforms how you consume Twitter.&lt;/p&gt;</content>
   <author>
     <name>Sebastjan Trepca</name>
     <uri>http://trepca.si/about.html</uri>
   </author>
 </entry>
 
</feed>

