<?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>bgola &#187; hacking</title>
	<atom:link href="http://blog.brunogola.com.br/category/hacking/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.brunogola.com.br</link>
	<description>python, free software, hacking, free culture, bicycle commuting, geocaching</description>
	<lastBuildDate>Mon, 21 Jun 2010 20:14:37 +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>Django model history with django-reversion</title>
		<link>http://blog.brunogola.com.br/2009/10/django-model-history-with-django-reversion/</link>
		<comments>http://blog.brunogola.com.br/2009/10/django-model-history-with-django-reversion/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 18:06:04 +0000</pubDate>
		<dc:creator>Bruno Gola</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.brunogola.com.br/?p=110</guid>
		<description><![CDATA[I&#8217;m currently working on a django project and I needed to track all changes to a model and provide a log showing what has changed (like a wiki). I&#8217;ve found three extensions/libs that apparently could do the job for me (fullhistory, django-history and django-reversion) so I decided to test them, but because of the lack [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a <a href="http://www.djangoproject.com/">django</a> project and I needed to track all changes to a model and provide a log showing what has changed (like a wiki).</p>
<p>I&#8217;ve found three extensions/libs that apparently could do the job for me (<a href="http://code.google.com/p/fullhistory/">fullhistory</a>, <a href="http://code.google.com/p/django-history/">django-history</a> and <a href="http://code.google.com/p/django-reversion/">django-reversion</a>) so I decided to test them, but because of the lack of structure/documentation of the other two I tried just the last one. </p>
<h2>django-reversion</h2>
<p> (<a href="http://code.google.com/p/django-reversion/">http://code.google.com/p/django-reversion/</a>)</p>
<p>It has a <a href="http://code.google.com/p/django-reversion/wiki/GettingStarted">good documentation</a>, integration with the admin and the most important for me a <em><a href="http://code.google.com/p/django-reversion/wiki/LowLevelAPI">low level api</a></em>, as I am not using the admin app for this project. </p>
<p>The installation went pretty well (<em>svn co <a href="http://django-reversion.googlecode.com/svn/tags/1.1.2/src/reversion">http://django-reversion.googlecode.com/svn/tags/1.1.2/src/reversion</a></em> to your PYTHONPATH, add the <em>reversion</em> app to your INSTALLED_APPS in <em>settings.py</em> and the usual <em>python manage.py syncdb</em>).</p>
<p>To track the changes of a model you must register it with the <em>reversion</em> framework (importing <em>reversion</em> and calling <em>reversion.register(YourModel)</em>).</p>
<p><em>Reversion</em> provides some ways for creating revisions of your model and the docs recommend that you choose one of them to use in your project. I chose the MiddleWare method because it seemed the better option for our project, but you should look the <a href="http://code.google.com/p/django-reversion/wiki/LowLevelAPI">reversion documentation</a> and decide which one is the best for you.</p>
<p>After registering the model and installing the MiddleWare no more changes are needed, whenever I save a model a new revision is created on the database. Another cool feature is the <em>follow</em> argument when registering a model. That way you can specify a ForeingKey/ManyToMany field to follow. This means that when you save the model a new revision is created with all &#8220;followed&#8221; fields in its current state. It&#8217;s very useful. See the docs for an example.</p>
<p>The only thing that&#8217;s not so clear for me is: what happens if I delete a field from a model that&#8217;s registered within reversion? Can you still restore its versions?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.brunogola.com.br/2009/10/django-model-history-with-django-reversion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating a tweet gadget for Google Wave</title>
		<link>http://blog.brunogola.com.br/2009/10/creating-a-tweet-gadget-for-google-wave/</link>
		<comments>http://blog.brunogola.com.br/2009/10/creating-a-tweet-gadget-for-google-wave/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 18:56:07 +0000</pubDate>
		<dc:creator>Bruno Gola</dc:creator>
				<category><![CDATA[Hacklab]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[gadgets]]></category>
		<category><![CDATA[google gadgets]]></category>
		<category><![CDATA[google wave]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.brunogola.com.br/?p=118</guid>
		<description><![CDATA[This week bani sent me an invite for trying Google Wave. It&#8217;s a great tool and if it remains as open as Google says it will I think it can really change the way we communicate over the internets. I mean, it&#8217;s much more flexible than e-mail and it takes collaboration to another level. But, [...]]]></description>
			<content:encoded><![CDATA[<p>This week <a href="http://twitter.com/bani">bani</a> sent me an invite for trying <a href="http://wave.google.com">Google Wave</a>. It&#8217;s a great tool and if it remains as open as Google says it will I think it can really change the way we communicate over the <em>internets</em>. I mean, it&#8217;s much more flexible than e-mail and it takes collaboration to another level. But, as I said, <em>IMO</em> the &#8220;key for success&#8221; in this case is to stay open and to support the creation of other servers and implementations(as <a href="http://pygowave.net">PyGoWave</a> [which deserves a blog post]).</p>
<p>But enough of cheap talk, I&#8217;ll show you the code. </p>
<p>My first &#8220;useful&#8221; piece of code for <em>Wave</em> is a <em>Tweet Gadget</em>. It&#8217;s a simple <a href="http://code.google.com/apis/gadgets/">Google Gadget</a> that takes advantage of the <a href="http://code.google.com/apis/wave/extensions/gadgets/guide.html">Wave extensions</a> for interacting with the <em>Wave user</em>. What the gadget does is very simple, it takes a <em>tweet id</em> and using the <a href="http://apiwiki.twitter.com/">Twitter API</a> it places the tweet inside the Wave. It&#8217;s a simple way to quote a tweet.</p>
<p>I must say that the original idea is not mine, it&#8217;s <a href="http://isnomore.net">rbp</a>&#8216;s idea. We were chatting using Google Wave and he wanted to quote a tweet. That&#8217;s how we started looking ways of doing it.</p>
<h2>Stateless gadget</h2>
<p>I started writing a <a href="http://brunogola.com.br/tweet_stateless.xml">simple gadget</a> that using the <em>Google Gadgets API</em> makes a request using the Twitter API and shows the tweet in the wave. The problem of this first version was that it does not keep the state, so if you reload/rejoin the wave, you won&#8217;t see the tweet, but instead you will see the text box for entering the tweet id.</p>
<p>In this first version you can see how to make a JSON Async Request using the Google Gadgets API. It&#8217;s very simple, all you need to do is to set the parameter <em>gadgets.io.RequestParameters.CONTENT_TYPE</em> to <em>gadgets.io.ContentType.JSON</em> and then call <em>gadgets.io.makeRequest(url, callback, params)</em> where <em>callback</em> is a <em>function</em> that receives the JSON object.A very simple example:</p>
<p><code><br />
function myCallback(obj) {<br />
  jsondata = obj.data;<br />
  // access the attributes as jsondata['key']<br />
  // ...<br />
}<br />
function makesJSONRequest(url) {<br />
  params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;<br />
  gadgets.io.makeRequest(url, myCallback, params);<br />
}<br />
</code></p>
<h2>Adding state</h2>
<p>Until now the gadget is a simple <em>Google Gadget</em> as it does not use any feature of <em>Google Wave</em>. Also it&#8217;s not so useful because it can&#8217;t keep the tweet id when you leave the Wave. And worse, people will never see the tweet you quoted. One of the main differences between simple Google Gadgets and Wave Gadgets is their <a href="http://code.google.com/apis/wave/extensions/gadgets/guide.html#state">ability to keep, set and change <em>state</em></a>. By state I mean information. You can keep user preferences, a game score or a <em>tweet id</em> (or even a tweet).</p>
<p>I decided that the easiest way was to store the tweet as it will appear in the wave (with HTML entities and everything). The <a href="http://brunogola.com.br/tweet_state.xml">new version</a> will keep the tweet information when the user enters the tweet id, so everybody in the wave can see the quoted tweet. </p>
<p>You can see the <a href="http://brunogola.com.br/tweet_state.xml">Gadget code</a> to understand how state works in Google Wave, but what&#8217;s most important:</p>
<ul>
<li>use a callback (with wave.setStateCallback()) to be aware of state changes</li>
<li>wave.getState() returns an state <em>dict-like</em> object which you can set and get information from</li>
<li>use wave.getState().get(&#8216;key&#8217;) for getting an information</li>
<li>and wave.getState().submitDelta({&#8216;key1:&#8217; value1, &#8216;key2&#8242;: value2} for setting information</li>
</ul>
<p>And that&#8217;s it. It&#8217;s very simple, hope you enjoy it <img src='http://blog.brunogola.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.brunogola.com.br/2009/10/creating-a-tweet-gadget-for-google-wave/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Transparência HackDay</title>
		<link>http://blog.brunogola.com.br/2009/10/transparencia-hackday/</link>
		<comments>http://blog.brunogola.com.br/2009/10/transparencia-hackday/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 15:19:21 +0000</pubDate>
		<dc:creator>Bruno Gola</dc:creator>
				<category><![CDATA[Hacklab]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.brunogola.com.br/?p=104</guid>
		<description><![CDATA[&#8220;Two days for hacking the Brazilian politics&#8221; This weekend (October 3rd and 4th) will happen the first &#8220;Transparência HackDay&#8221; (&#8220;Transparency HackDay&#8221; in english), a free and open hacking event with focus on bringing together hackers, activists, managers and people with ideas to make government information/public data more accessible for everyone using and writing web tools. [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>&#8220;Two days for hacking the Brazilian politics&#8221;</em></strong></p>
<p>This weekend (<strong>October 3rd</strong> and <strong>4th</strong>) will happen the first &#8220;<em>Transparência HackDay</em>&#8221; (&#8220;<em>Transparency HackDay</em>&#8221; in english), a free and open hacking event with focus on bringing together hackers, activists, managers and people with ideas to make government information/public data more accessible for everyone using and writing web tools.</p>
<p>I&#8217;m attending and one of my ideas is to hack <strong>CET</strong> (<em>Companhia de Engenharia de Tráfego / Traffic Engineering Company</em>) data and make them available. The idea is to improve a crawler I wrote (in <strong>python</strong> <img src='http://blog.brunogola.com.br/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) that downloads and stores data about the traffic in São Paulo every 30 minutes from the &#8220;traffic now&#8221; <strong>CET</strong> website (as they don&#8217;t store it [or at least don't provide anything]).</p>
<p>More information about the <strong>HackDay</strong> (in <em>portuguese</em>):<br />
<a href="http://www.slideshare.net/esferamobi/transparencia-hackday-proposta">http://www.slideshare.net/esferamobi/transparencia-hackday-proposta</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.brunogola.com.br/2009/10/transparencia-hackday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
