<?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>spiral_code &#187; sinatra</title>
	<atom:link href="http://blog.trydionel.com/tag/sinatra/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.trydionel.com</link>
	<description></description>
	<lastBuildDate>Fri, 27 Aug 2010 00:35:24 +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>Easy code reloading with FSSM</title>
		<link>http://blog.trydionel.com/2010/08/22/easy-code-reloading-with-fssm/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=easy-code-reloading-with-fssm</link>
		<comments>http://blog.trydionel.com/2010/08/22/easy-code-reloading-with-fssm/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 19:40:21 +0000</pubDate>
		<dc:creator>Jeff Tucker</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[fssm]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[unicorn]]></category>

		<guid isPermaLink="false">http://blog.trydionel.com/?p=185</guid>
		<description><![CDATA[After a several month hiatus (filled with such activities as getting married and honeymooning), I&#8217;m finally getting back into the swing of &#8220;normal&#8221; life. I&#8217;ve been working on a pet project using Sinatra and Unicorn (doing some long-polling stuff, so &#8230; <a href="http://blog.trydionel.com/2010/08/22/easy-code-reloading-with-fssm/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After a several month hiatus (filled with such activities as getting married and honeymooning), I&#8217;m finally getting back into the swing of &#8220;normal&#8221; life.</p>
<p>I&#8217;ve been working on a pet project using Sinatra and Unicorn (doing some long-polling stuff, so I needed to support multiple connections even in dev).  Unfortunately, this combination makes code reloading tricky to tackle, as it rules out <a href="http://rtomayko.github.com/shotgun/">shotgun</a> entirely, and seems to also bust <a href="http://github.com/rkh/sinatra-reloader">Sinatra::Reloader</a>.</p>
<p>After a couple hours of HUPping unicorns manually, I decided that I needed a more robust solution. <a href="http://github.com/chriseppstein/compass/blob/stable/lib/compass/commands/watch_project.rb#L61">Some digging</a> led me to the  <a href="http://github.com/ttilley/fssm"><abbr title="File System State Monitor">FSSM</abbr> gem by ttilley</a>.  This library will watch your file system for events and runs a registered callback when they occur.  A few minutes of hacking and my reloading woes are solved!</p>
<pre class="brush: ruby;">
#!/usr/bin/env ruby -wKU

require 'rubygems'
require 'fssm'

puts &quot;Monitoring #{File.expand_path(File.dirname(__FILE__))} for changes...&quot;
FSSM.monitor(File.dirname(__FILE__), ['**/*.rb', '**/*.ru', '**/*.yml']) do
  update { system &quot;kill -HUP `cat pids/unicorn.pid`&quot; }
end

exit 0
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.trydionel.com/2010/08/22/easy-code-reloading-with-fssm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lightning-Quick Redis Viewer</title>
		<link>http://blog.trydionel.com/2010/02/27/lightning-quick-redis-viewer/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=lightning-quick-redis-viewer</link>
		<comments>http://blog.trydionel.com/2010/02/27/lightning-quick-redis-viewer/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 21:34:10 +0000</pubDate>
		<dc:creator>Jeff Tucker</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[redis]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://blog.trydionel.com/?p=135</guid>
		<description><![CDATA[I&#8217;ve had the opportunity to work with the Redis datastore this week. If you&#8217;re not familiar with it, Redis is a blindingly-fast, in-memory key-value store. It supports several nice features such as string, list and set support (complete with set &#8230; <a href="http://blog.trydionel.com/2010/02/27/lightning-quick-redis-viewer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had the opportunity to work with the Redis datastore this week.  If you&#8217;re not familiar with it, Redis is a blindingly-fast, in-memory key-value store.  It supports several nice features such as string, list and set support (complete with set operations) and the ability to persist data to disk.  Check out the <a href="http://code.google.com/p/redis/">official site</a> for lots more info.</p>
<p>My project revolved around data collection, and I pretty quickly ran into the need to see what I was actually shoving into the database.  After 10 minutes and only ~50 lines, I came up with a Sinatra backed Redis viewer.  See the code below, or check out <a href="http://gist.github.com/316957">my gist on Github</a>!</p>
<pre class="brush: ruby;">
# app.rb
require 'rubygems'
require 'haml'
require 'sinatra'
require 'redis'

helpers do
  def redis
    @redis ||= Redis.new
  end
end

get &quot;/&quot; do
  @keys = redis.keys(&quot;*&quot;)
  haml :index
end

get &quot;/:key&quot; do
  @key = params[:key]
  @data = case redis.type(@key)
  when &quot;string&quot;
    Array(redis[@key])
  when &quot;list&quot;
    redis.lrange(@key, 0, -1)
  when &quot;set&quot;
    redis.set_members(@key)
  else
    []
  end
  haml :show
end

# views/index.haml
%html
%body
  %h1 Current Keys
  %ul
    - @keys.each do |key|
      %li
        %a{:href =&gt; &quot;/#{key}&quot;}= key

# views/show.haml
%html
%body
  %h1= &quot;Data stored in '#{@key}'&quot;
  %ul
    -@data.each do |data|
      %li
        %p= data
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.trydionel.com/2010/02/27/lightning-quick-redis-viewer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
