<?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>The House of Ding &#187; Ruby</title>
	<atom:link href="http://www.houseofding.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.houseofding.com</link>
	<description>Technology, programming, design, and everything in-between.</description>
	<lastBuildDate>Fri, 30 Oct 2009 03:09:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>iTunes Veto: avoid those overplayed new songs</title>
		<link>http://www.houseofding.com/2009/06/itunes-veto-avoid-those-overplayed-new-songs/</link>
		<comments>http://www.houseofding.com/2009/06/itunes-veto-avoid-those-overplayed-new-songs/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 19:10:18 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.houseofding.com/?p=217</guid>
		<description><![CDATA[I listen to a stream of The Current almost all day, every day. I love this station, but I cringe every time they play that new Green Day song or when I hear Bono sing, well, anything. No longer! I&#8217;ve written a set of Ruby scripts that&#8217;ll let me veto away the ugliness so that [...]]]></description>
			<content:encoded><![CDATA[<p>I listen to a stream of <a href="http://minnesota.publicradio.org/tools/play/streams/the_current.pls" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://minnesota.publicradio.org/tools/play/streams/the_current.pls');">The Current</a> almost all day, every day. I love this station, but I cringe every time they play that new Green Day song or when I hear Bono sing, well, anything. No longer! I&#8217;ve written a set of Ruby scripts that&#8217;ll let me veto away the ugliness so that I&#8217;ll never get nasty songs stuck in my head&nbsp;again.</p>
<p>I should point out that these scripts assume you&#8217;re running Mac <span class="caps">OS</span> X 10.5 with Developer Tools installed. Both scripts use the <code>osx/cocoa</code> library to interact with&nbsp;iTunes.</p>
<h3>veto</h3>
<p>the <code>veto</code> script pulls the track title that iTunes is currently streaming and appends it to&nbsp;<code>~/.itunes_vetoes_songs</code>.</p>
<pre>
#!/usr/bin/env ruby -w

require 'osx/cocoa'
include OSX
OSX.require_framework 'ScriptingBridge'

itunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
`echo "#{itunes.currentStreamTitle}" >> ~/.itunes_vetoed_songs`
</pre>
<h3>veto_watcher</h3>
<p><code>veto_watcher</code> runs in the background and looks for vetoes songs to appear the iTunes stream. When they do, it turns down the volume and spares your ears. When the vetoed track is done, the volume goes back up. Note: this <em>should</em> return the volume to it&#8217;s previous setting, but the instance variable kept breaking, so it just goes back up to&nbsp;100%&thinsp;&mdash;&thinsp;careful!</p>
<pre>
#!/usr/bin/env ruby -w

# start a new thread
pid = fork do

  require 'osx/cocoa'
  include OSX
  OSX.require_framework 'ScriptingBridge'

  @itunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")

  def itunes_is_running?
    return !`ps -A -o comm | grep iTunes.app`.empty?
  end

  def mute
    @itunes.soundVolume = 0 if @itunes.soundVolume > 0
  end

  def unmute
    @itunes.soundVolume = 100 if @itunes.soundVolume == 0
  end

  def check_for_veto
    vetoes = `cat ~/.itunes_vetoed_songs`.split("\n")

    if vetoes.index(@itunes.currentStreamTitle)
      mute
    elsif @itunes.soundVolume == 0
      unmute
    end
  end

  # main loop: check for a veto every 5 seconds
  loop do
    check_for_veto if itunes_is_running?
    sleep(5)
  end

end

Process.detach(pid)
</pre>
<p>I have the <code>veto_watcher</code> script start up when I log in and I&#8217;ve set up a Quicksilver trigger to run the <code>veto</code> script. What&#8217;s up now,&nbsp;Bono?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.houseofding.com/2009/06/itunes-veto-avoid-those-overplayed-new-songs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://minnesota.publicradio.org/tools/play/streams/the_current.pls" length="0" type="audio/x-scpls" />
		</item>
		<item>
		<title>Create an RSS feed of your git commits</title>
		<link>http://www.houseofding.com/2009/03/create-an-rss-feed-of-your-git-commits/</link>
		<comments>http://www.houseofding.com/2009/03/create-an-rss-feed-of-your-git-commits/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 21:33:08 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.houseofding.com/?p=166</guid>
		<description><![CDATA[It&#8217;s sometimes hard to stay up-to-date on changes your development team makes to projects. Especially when there&#8217;s a flurry of activity. To deal with this, I&#8217;ve written a ruby script that takes output from git log and transforms it into a valid RSS feed. It includes name, commit notes, and affected files but it can [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s sometimes hard to stay up-to-date on changes your development team makes to projects. Especially when there&#8217;s a flurry of activity. To deal with this, I&#8217;ve written a ruby script that takes output from <code>git log</code> and transforms it into a valid RSS feed. It includes name, commit notes, and affected files but it can be easily modified to include more (or&nbsp;less).</p>
<p>Because git&#8217;s built-in hooks system is only available client-side, this is set to run via a cron task. One <em>could</em> implement some sort of push system pretty easily with client-side hooks, but the hook scripts would have to be distributed to each of the developers. That seems like a pain. This script is meant to be executed on the server that holds your git&nbsp;repositories.</p>
<h3>gitrss.rb</h3>
<p>gitrss.rb takes one argument: the path to the&nbsp;repository.</p>
<pre>
repository_path = $*[0]

git_history = `cd #{repository_path} &amp;&amp; git log --max-count=10 --name-status`
entries = git_history.split(&quot;\ncommit &quot;)

rss = &quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
  &lt;rss version=&quot;2.0&quot;&gt;

  &lt;channel&gt;
  &lt;title&gt;your_repository commits&lt;/title&gt;
  &lt;description&gt;Git commits to your_repository&lt;/description&gt;
  &lt;link&gt;http://example.com/your_respository.xml&lt;/link&gt;
  &lt;lastBuildDate&gt;#{Time.now}&lt;/lastBuildDate&gt;
  &lt;pubDate&gt;#{Time.now}&lt;/pubDate&gt;
&quot;

entries.each do |entry|
  guid = entry.gsub(/^.*commit /ms, '').gsub(/\n.*$/ms, '')
  author_name = entry.gsub(/^.*Author: /ms, '').gsub(/ &lt;.*$/ms, '')
  date = entry.gsub(/^.*Date: +/ms, '').gsub(/\n.*$/ms, '')
  comments = entry.gsub(/^.*Date[^\n]*/ms, '')

  rss += &quot;
    &lt;item&gt;
      &lt;title&gt;Commit by #{author_name}&lt;/title&gt;
      &lt;description&gt;#{author_name} made a commit on #{date}&lt;/description&gt;
      &lt;content&gt;&lt;![CDATA[
        &lt;h2&gt;#{author_name}&lt;/h2&gt;
        &lt;p&gt;#{date}&lt;/p&gt;
        &lt;pre&gt;#{comments}&lt;/pre&gt;
      ]]&gt;&lt;/content&gt;
      &lt;link&gt;&lt;/link&gt;
      &lt;guid isPermaLink=&quot;false&quot;&gt;#{guid}&lt;/guid&gt;
      &lt;pubDate&gt;#{date}&lt;/pubDate&gt;
    &lt;/item&gt;&quot;
end 

rss += &quot;
  &lt;/channel&gt;
&lt;/rss&gt;&quot;

puts rss
</pre>
<h3>cron</h3>
<p>The gitrss.rb script only outputs the <span class="caps">RSS</span> <span class="caps">XML</span>; we&#8217;ll have to redirect the output in cron. Here&#8217;s an example cron task that runs this every 30&nbsp;minutes:</p>
<pre>
*/30 * * * * root ruby /var/git/gitrss.rb /var/git/your_repository.git > /var/www/your_repository.xml
</pre>
<p>This cron task will run the gitrss.rb script every 30 minutes and redirect its output to a file called&nbsp;your_repository.xml</p>
]]></content:encoded>
			<wfw:commentRss>http://www.houseofding.com/2009/03/create-an-rss-feed-of-your-git-commits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
