<?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>FlowingData &#187; Coding</title>
	<atom:link href="http://flowingdata.com/category/flowingdata-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://flowingdata.com</link>
	<description>Strength in Numbers</description>
	<lastBuildDate>Fri, 10 Feb 2012 20:28:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel="next" href="http://flowingdata.com/category/flowingdata-code/feed/?page=2" />

		<item>
		<title>Programming gets you freedom to do what you want with data</title>
		<link>http://flowingdata.com/2011/10/26/programming-gets-you-freedom-to-do-what-you-want-with-data/</link>
		<comments>http://flowingdata.com/2011/10/26/programming-gets-you-freedom-to-do-what-you-want-with-data/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 07:18:12 +0000</pubDate>
		<dc:creator>Nathan Yau</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[flexibility]]></category>
		<category><![CDATA[programs]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=19496</guid>
		<description><![CDATA[<p><a href="http://flowingdata.com/2011/10/26/programming-gets-you-freedom-to-do-what-you-want-with-data/"><img width="625" height="325" src="http://flowingdata.com/wp-content/uploads/2011/10/After-the-vote-625x325.png" class="attachment-medium wp-post-image" alt="After the vote" title="After the vote" /></a></p>Casey Reas and Chandler McWilliams asked visual designers why they write their own software and how it affects their process: &#8230;]]></description>
			<content:encoded><![CDATA[<p><a href="http://flowingdata.com/2011/10/26/programming-gets-you-freedom-to-do-what-you-want-with-data/"><img width="625" height="325" src="http://flowingdata.com/wp-content/uploads/2011/10/After-the-vote-625x325.png" class="attachment-medium wp-post-image" alt="After the vote" title="After the vote" /></a></p><p>Casey Reas and Chandler McWilliams asked visual designers <a href="http://www.creativeapplications.net/theory/designing-programs-theory/">why they write their own software and how it affects their process</a>:</p>
<blockquote><p>The answers reflect the individuality of the designers and their process, but some ideas are persistent. The most consistent answer is that custom software is written because it gives more control. This control is often expressed as individual freedom. Another thread is writing custom software to create a precise realization for a precise idea. To put it another way, writing custom code is one way to move away from generic solutions; new tools can create new opportunities.</p></blockquote>
<p>Most of the interviewees are media artists, but there are a couple of names you'll recognize. My favorite, Amanda Cox, uses a Mad Libs metaphor:</p>
<blockquote><p>Mad Libs is a game where key words in a short story have been replaced with blanks. Players fill in the blanks with designated parts of speech (“noun”, “adverb”) or types of words (“body part”, “type of liquid”), without seeing the rest of the story. Occasionally, hilarity ensues, but no one really believes that this is an effective method for generating great literature.</p></blockquote>
<p>I'm looking at you, <a href="http://flowingdata.com/2011/10/18/statisticians-dont-program/">non-programming statistician</a>. </p>
<p><strong>Update:</strong> The article isn't there anymore, so you can <a href="http://webcache.googleusercontent.com/search?q=cache:_khg5NpLzL4J:www.creativeapplications.net/theory/designing-programs-theory/+site:www.creativeapplications.net+amanda+cox&cd=1&hl=en&ct=clnk&gl=us">read the cached page</a> for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2011/10/26/programming-gets-you-freedom-to-do-what-you-want-with-data/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Sorting algorithms demonstrated with Hungarian folk dance</title>
		<link>http://flowingdata.com/2011/04/14/sorting-algorithms-demonstrated-with-hungarian-folk-dance/</link>
		<comments>http://flowingdata.com/2011/04/14/sorting-algorithms-demonstrated-with-hungarian-folk-dance/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 07:17:00 +0000</pubDate>
		<dc:creator>Nathan Yau</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[dance]]></category>
		<category><![CDATA[nerd]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=15943</guid>
		<description><![CDATA[<p><a href="http://flowingdata.com/2011/04/14/sorting-algorithms-demonstrated-with-hungarian-folk-dance/"><img width="625" height="346" src="http://flowingdata.com/wp-content/uploads/2011/04/Bubble-sort-dance-625x346.png" class="attachment-medium wp-post-image" alt="Bubble sort dance" title="Bubble sort dance" /></a></p>We've seen sorting algorithms visualized and auralized, but now it's time to see them through the spirit of Hungarian folk &#8230;]]></description>
			<content:encoded><![CDATA[<p><a href="http://flowingdata.com/2011/04/14/sorting-algorithms-demonstrated-with-hungarian-folk-dance/"><img width="625" height="346" src="http://flowingdata.com/wp-content/uploads/2011/04/Bubble-sort-dance-625x346.png" class="attachment-medium wp-post-image" alt="Bubble sort dance" title="Bubble sort dance" /></a></p><p>We've seen sorting algorithms <a href="http://flowingdata.com/2010/07/26/sorting-algorithms-visualized/">visualized</a> and <a href="http://flowingdata.com/2010/09/01/what-different-sorting-algorithms-sound-like/">auralized</a>, but now it's time to see them through the spirit of Hungarian folk dance. In <a href="http://www.youtube.com/user/AlgoRythmics">a series of four videos</a> (so far), folks at Sapientia University in Romania demonstrate how different sorting algorithms work with numbered people dancing around and arranging themselves from least to greatest. </p>
<p>See them in action in the video below. This one is for Bubble-sort. They move with such zest.</p>
<p><iframe title="YouTube video player" width="575" height="353" src="http://www.youtube.com/embed/lyZQPjUT5B4?rel=0" frameborder="0" allowfullscreen></iframe></p>
<p>[<a href="http://www.youtube.com/user/AlgoRythmics">Video Link</a> via @<a href="https://twitter.com/#!/shancarter/status/57876142216060929">shancarter</a> & <a href="http://www.boingboing.net/2011/04/11/central-european-fol.html">Boing Boing</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2011/04/14/sorting-algorithms-demonstrated-with-hungarian-folk-dance/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Code to make your own movie barcodes available</title>
		<link>http://flowingdata.com/2011/03/16/code-to-make-your-own-movie-barcodes-available/</link>
		<comments>http://flowingdata.com/2011/03/16/code-to-make-your-own-movie-barcodes-available/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 16:42:22 +0000</pubDate>
		<dc:creator>Nathan Yau</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=15307</guid>
		<description><![CDATA[<p><a href="http://flowingdata.com/2011/03/16/code-to-make-your-own-movie-barcodes-available/"><img width="625" height="185" src="http://flowingdata.com/wp-content/uploads/2011/03/Austin-Powers-Jay-Roach-1997-small-625x185.png" class="attachment-medium wp-post-image" alt="Austin Powers - Jay Roach (1997)" title="Austin Powers - Jay Roach (1997)" /></a></p>You know those compressed movie barcodes that we saw last week? Here's a Python script by Benoît Romito to make &#8230;]]></description>
			<content:encoded><![CDATA[<p><a href="http://flowingdata.com/2011/03/16/code-to-make-your-own-movie-barcodes-available/"><img width="625" height="185" src="http://flowingdata.com/wp-content/uploads/2011/03/Austin-Powers-Jay-Roach-1997-small-625x185.png" class="attachment-medium wp-post-image" alt="Austin Powers - Jay Roach (1997)" title="Austin Powers - Jay Roach (1997)" /></a></p><p>You know those <a href="http://flowingdata.com/2011/03/07/entire-movies-compressed-into-single-barcodes/">compressed movie barcodes</a> that we saw last week? Here's <a href="http://bromito.perso.info.unicaen.fr/wiki/index.php/wiki/page/barcodes#source">a Python script by Benoît Romito to make your own</a>. Run a .avi format movie through, and voila. Free gift idea: digitize some old home movies and make a personalized barcode for your family.</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2011/03/16/code-to-make-your-own-movie-barcodes-available/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why everyone should learn programming</title>
		<link>http://flowingdata.com/2010/10/28/why-everyone-should-learn-programming/</link>
		<comments>http://flowingdata.com/2010/10/28/why-everyone-should-learn-programming/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 19:00:28 +0000</pubDate>
		<dc:creator>Nathan Yau</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=12430</guid>
		<description><![CDATA[Daniel Shiffman, assistant professor at the NYU Interactive Telecommunications Program, talks programming, computation, data, and why everyone should learn programming &#8230;]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.shiffman.net/">Daniel Shiffman</a>, assistant professor at the NYU Interactive Telecommunications Program, talks programming, computation, data, and why everyone should learn programming in this interview by <a href="http://cargocollective.com/mwebster">Mark Webster</a>. </p>
<blockquote><p>It's not just about saving time. There are certain things you can discover and be creative with with computation that you can't by hand. They both go together.</p></blockquote>
<p>Watch the four-minute interview below. The excitement in Shiffman's voice alone might want to make you learn some <a href="http://processing.org/">Processing</a> (which he wrote <a href="http://www.amazon.com/gp/product/0123736021?ie=UTF8&tag=flowingdata-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=0123736021">a useful book</a> for).</p>
<p><iframe src="http://player.vimeo.com/video/16140257" width="549" height="309" frameborder="0"></iframe></p>
<p>[<a href="http://vimeo.com/16140257">Mark Webster</a> via @<a href="http://twitter.com/#!/ben_fry/status/28836417933">ben_fry</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2010/10/28/why-everyone-should-learn-programming/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Make Your Own Twitter Bot &#8211; Python Implementation</title>
		<link>http://flowingdata.com/2008/11/05/how-to-make-your-own-twitter-bot-python-implementation/</link>
		<comments>http://flowingdata.com/2008/11/05/how-to-make-your-own-twitter-bot-python-implementation/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 07:16:22 +0000</pubDate>
		<dc:creator>Nathan Yau</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Self-surveillance]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=1107</guid>
		<description><![CDATA[Following up on my post last week about using Twitter to track eating and weight, some of you voiced some &#8230;]]></description>
			<content:encoded><![CDATA[<p>Following up on my post last week about using Twitter to <a href="http://flowingdata.com/2008/10/30/tracking-weight-and-what-i-eat-with-twitter-self-surveillance-made-easy/">track eating and weight</a>, some of you voiced some interest in creating your own Twitter bot. This post covers how you can do that. </p>
<h2>The Gist of It</h2>
<p>Creating my own Twitter bot was pretty straightforward (much more than I thought it'd be), mostly because Twitter provides <a href="http://apiwiki.twitter.com/">an API</a> and the resources to make it that way. </p>
<p>I wanted something really simple that I could play around with. I just wanted to be able to send a direct message to my Twitter bot, and from there, it would store my data. OK, so here are the basic steps I took:</p>
<ol>
<li>Create Twitter account for bot</li>
<li>Turn on email notification for direct messages only</li>
<li>Check email periodically for new direct messages</li>
<li>Parse direct messages and store in database</li>
</ol>
<h2>Create a Twitter Account (and Email Address)</h2>
<p>The first step is easy. Create a Twitter account specifically for your bot. The account name should be short and easy to remember. Make sure you enter an IMAP email address that is only for your bot. You could put in a general purpose email address, but it'll make your life a lot easier if the email address was specifically for Twitter.</p>
<h2>Turn on Email Notifications</h2>
<p>Once you've setup your bot account, turn on email notification via the Twitter options menu. For now, tell Twitter to only send you notifications when your bot receives direct messages and <em>not</em> when someone new follows.</p>
<h2>Check Email and Do Something with Messages</h2>
<p>Here's where the actual code comes in. Here's the general framework. I've left out some details that will be specific to your own purposes.</p>
<pre class="python">&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">imaplib</span> <span style="color: #ff7700;font-weight:bold;">import</span> *
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">email</span>.<span style="color: black;">Parser</span> <span style="color: #ff7700;font-weight:bold;">import</span> Parser
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span>, <span style="color: #dc143c;">time</span>, <span style="color: #dc143c;">email</span>, <span style="color: #dc143c;">email</span>.<span style="color: black;">Utils</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Connect to email server</span>
server = IMAP4<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;__EMAIL_SERVER.COM__&quot;</span><span style="color: black;">&#41;</span>
server.<span style="color: black;">login</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;__EMAIL_ACCOUNT_NAME__&quot;</span>, <span style="color: #483d8b;">&quot;__EMAIL_PASSWORD__&quot;</span><span style="color: black;">&#41;</span>
r = server.<span style="color: #dc143c;">select</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;INBOX&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Find only new mail (i.e. new direct messages)</span>
r, data = server.<span style="color: black;">search</span><span style="color: black;">&#40;</span><span style="color: #008000;">None</span>, <span style="color: #483d8b;">&quot;(NEW)&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># If there are new direct messages:</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> &gt; <span style="color: #ff4500;">0</span>:
&nbsp;
    p = Parser<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Loop through new emails</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> num <span style="color: #ff7700;font-weight:bold;">in</span> data<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
&nbsp;
        <span style="color: #808080; font-style: italic;"># Who email is from (Should be one line, broken for display only)</span>
        r, data = server.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span>num, <span style="color: #483d8b;">'(BODY[HEADER.FIELDS
            (DATE SUBJECT FROM X-TwitterEmailType X-TwitterSenderScreenName
            X-TwitterCreatedAt X-TwitterRecipientScreenName)])'</span><span style="color: black;">&#41;</span>
        msg = p.<span style="color: black;">parsestr</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        who = msg.<span style="color: #0000cd;">__getitem__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'From'</span><span style="color: black;">&#41;</span>
        matchemail = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'[<span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\-</span>][<span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\-</span><span style="color: #000099; font-weight: bold;">\.</span>]+@[<span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\-</span>][<span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\-</span><span style="color: #000099; font-weight: bold;">\.</span>]+[a-zA-Z]{1,4}'</span><span style="color: black;">&#41;</span>
        email_addy = matchemail.<span style="color: black;">findall</span><span style="color: black;">&#40;</span>who<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Twitter username</span>
        twitter_un = msg.<span style="color: #0000cd;">__getitem__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'X-TwitterSenderScreenName'</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># If the email is a direct message sent from Twitter</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> msg.<span style="color: #0000cd;">__getitem__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'X-TwitterEmailType'</span><span style="color: black;">&#41;</span> == <span style="color: #483d8b;">'direct_message'</span>:
&nbsp;
	    <span style="color: #808080; font-style: italic;"># When direct message sent, convert to epoch seconds</span>
            twitter_time = msg.<span style="color: #0000cd;">__getitem__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'X-TwitterCreatedAt'</span><span style="color: black;">&#41;</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            time_tuple = <span style="color: #dc143c;">email</span>.<span style="color: black;">Utils</span>.<span style="color: black;">parsedate</span><span style="color: black;">&#40;</span>twitter_time<span style="color: black;">&#41;</span>
            epoch_seconds = <span style="color: #dc143c;">time</span>.<span style="color: black;">mktime</span><span style="color: black;">&#40;</span>time_tuple<span style="color: black;">&#41;</span>
&nbsp;
            <span style="color: #808080; font-style: italic;"># Get body of email sent by Twitter</span>
            r, data = server.<span style="color: black;">fetch</span><span style="color: black;">&#40;</span>num, <span style="color: #483d8b;">'(RFC822.TEXT)'</span><span style="color: black;">&#41;</span>
            body = data<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
            twitter_dm = body.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
            <span style="color: #808080; font-style: italic;"># Do something with the twitter direct message...</span>
            <span style="color: #808080; font-style: italic;"># Parse it...</span>
            <span style="color: #808080; font-style: italic;"># Store it in a database?...</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Logout of email server</span>
server.<span style="color: black;">logout</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;</pre>
<p>I run this script every 30 minutes with a <a href="http://en.wikipedia.org/wiki/Cron">cron</a>. You could of course run it more frequently. The important part of this code though is that Twitter attaches its own <a href="http://apiwiki.twitter.com/REST+API+Documentation#HowshouldmyTwitterbotfollowusersthatfollowitorinspectdirectmessages">special headers</a> (e.g. X-TwitterEmailType). If you wanted your bot to automatically follow users that followed it, you could check the EmailType and then use the Twitter API to follow a Twitter user. For my simple purposes though, I only cared about direct messages.</p>
<p>That's all. There is of course plenty of room for improvement. Like I said, you could make this useful to lots of users by making your bot automatically follow those who follow it. Users can only direct message another Twitter user, if he is following. I would also delete emails that have already been read and stored somewhere so that the INBOX doesn't pile up. Yup.</p>
<p>Did I miss anything?</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2008/11/05/how-to-make-your-own-twitter-bot-python-implementation/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>

