<?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>Stereonaut! &#187; code</title>
	<atom:link href="http://stereonaut.net/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://stereonaut.net</link>
	<description>A weblog by David Moreno.</description>
	<lastBuildDate>Mon, 23 Aug 2010 00:45:00 +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>curl POST data and newlines</title>
		<link>http://stereonaut.net/curl-post-data-and-newlines/</link>
		<comments>http://stereonaut.net/curl-post-data-and-newlines/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 03:10:35 +0000</pubDate>
		<dc:creator>David Moreno</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://stereonaut.net/?p=1190</guid>
		<description><![CDATA[I&#039;m writing a Rails application for the microblogging strategy for Debian (which I used to call, debian-twitter, but you know how us Debian folks are ). I came up with a strange issue, that at first I thought was ActionController&#039;s fault or some crap. So, I was testing one of my controllers with something like [...]]]></description>
			<content:encoded><![CDATA[<p>I&#039;m writing a <a href="http://rubyonrails.org/">Rails</a> application for the <a href="http://en.wikipedia.org/wiki/Microblogging">microblogging</a> strategy for <a href="http://debian.org">Debian</a> (which I used to call, <a href="http://github.com/damog/debian-twitter">debian-twitter</a>, but you know how us Debian folks are <img src='http://stereonaut.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ). I came up with a strange issue, that at first I thought was <a href="http://guides.rubyonrails.org/action_controller_overview.html">ActionController</a>&#039;s fault or some crap.</p>
<p>So, I was testing one of my controllers with something like this:</p>
<pre class="brush: bash">cat /tmp/mm.txt | curl -d @- http://localhost:3000/message/new</pre>
<p>/tmp/mm.txt is a <a href="http://en.wikipedia.org/wiki/Pretty_Good_Privacy">PGP</a> signed message which then I just send as POST data to my application. So far so good. However, when accessing the data from Rails, using request.body.read, I was a getting a single line, with the newlines (carriage returns) removed. So I started looking at how ActionController was getting the HTTP data and stuff. But then I tested:</p>
<pre class="brush: bash">cat /tmp/mm.txt | lwp-request -m POST  http://localhost:3000/message/new</pre>
<p>And that had the carriage returns in place.</p>
<p>So, I started looking at the curl man page and discovered this little gem:</p>
<blockquote><p>&#8211;data-binary &lt;data&gt;</p>
<p>(HTTP) This posts data exactly as specified with no extra processing whatsoever.</p>
<p>If you start the data with the letter @, the rest should be a filename. Data is posted in a similar manner as &#8211;data-ascii does, except that newlines are preserved and conversions are never done.</p>
<p>If this option is used several times, the ones following the first will append data as described in -d/&#8211;data.</p></blockquote>
<pre class="brush: bash">cat /tmp/mm.txt | curl --data-binary @- http://localhost:3000/message/new</pre>
<p>&#8230;did indeed the tricky. Maybe someone needs this info some day.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereonaut.net/curl-post-data-and-newlines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sync your Twitter followers and friends</title>
		<link>http://stereonaut.net/sync-your-twitter-followers-and-friends/</link>
		<comments>http://stereonaut.net/sync-your-twitter-followers-and-friends/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 18:30:29 +0000</pubDate>
		<dc:creator>David Moreno</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[planeta linux]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gems]]></category>

		<guid isPermaLink="false">http://log.damog.net/?p=898</guid>
		<description><![CDATA[I have a couple of accounts in Twitter (namely @debian and @planetalinux) that are starting to bring a lot of followers (well, at least some of them). And given that I consider these accounts to be Twitter-polite enough, I like to follow the followers back too; however, this task sometimes gets really hard and it&#039;s [...]]]></description>
			<content:encoded><![CDATA[<p>I have a couple of accounts in Twitter (namely @<a href="http://twitter.com/debian">debian</a> and @<a href="http://twitter.com/planetalinux">planetalinux</a>) that are starting to bring a lot of followers (well, at least some of them). And given that I consider these accounts to be Twitter-polite enough, I like to follow the followers back too; however, this task sometimes gets really hard and it&#039;s tiring to go through the followers pages and follow those that I don&#039;t follow yet over and over.</p>
<p>So, I spent a few minutes and came up with this simple Ruby script that uses <a href="http://addictedtonew.com/">John Nunemaker</a>&#039;s awesome <a href="http://twitter.rubyforge.org">Twitter gem</a>.</p>
<pre class="brush: ruby">
#!/opt/local/bin/ruby

require &quot;rubygems&quot;
require &quot;twitter&quot;

httpauth = Twitter::HTTPAuth.new(
	ARGV[0] || &#039;yehyeh&#039;,
	ARGV[1] || &#039;kissm3&#039;
)

base = Twitter::Base.new(httpauth)

i = 0
(base.follower_ids - base.friend_ids).each do |id|
  i += 1
  begin
    base.friendship_create id
  rescue Twitter::General =&gt; e
    puts &quot;#{e.class}: #{e.message}&quot;
  end
end
puts &quot;#{i} new friendships.&quot;

i = 0
(base.friend_ids - base.follower_ids).each do |id|
  i += 1
  base.friendship_destroy id
end
puts &quot;#{i} destroyed friendships.&quot;

puts &quot;#{base.friend_ids.size} friends now.&quot;
puts &quot;#{base.follower_ids.size} followers now.&quot;
</pre>
<p>What this little code does is exactly that, it will start following the followers you don&#039;t follow yet, and it will stop following the people that don&#039;t follow you back, right? Got it? It&#039;s basically synchronizing your friends with your followers. As said, this is particularly helpful when you are maintaining a community account and want to keep up befriending your kind followers <img src='http://stereonaut.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Handling the exception <code>Twitter::General</code> on line 18 is only done because the twitter gem raises it even when you are trying to befriend an account to which you have already requested friendship (like pending requests to protected updates accounts) or those of suspended accounts (spammers).</p>
]]></content:encoded>
			<wfw:commentRss>http://stereonaut.net/sync-your-twitter-followers-and-friends/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
