<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Wondering Bear</title>
	<atom:link href="http://wbear.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://wbear.wordpress.com</link>
	<description>Random thoughts on software and life</description>
	<lastBuildDate>Wed, 14 Dec 2011 05:41:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='wbear.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Wondering Bear</title>
		<link>http://wbear.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://wbear.wordpress.com/osd.xml" title="Wondering Bear" />
	<atom:link rel='hub' href='http://wbear.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Prime numbers with Erlang</title>
		<link>http://wbear.wordpress.com/2011/12/08/prime-numbers-with-erlang/</link>
		<comments>http://wbear.wordpress.com/2011/12/08/prime-numbers-with-erlang/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 04:29:11 +0000</pubDate>
		<dc:creator>Wondering Bear</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://wbear.wordpress.com/?p=109</guid>
		<description><![CDATA[I was helping my son with math homework today.. One of the problems was to find all prime numbers up to a 100.. That was enough for me to start looking for an old Erlang script I have played with few years ago&#8230; -module(eratosthenes). -export([prime_numbers/1]). % Sieve of Eratosthenes algorithm for finding all prime numbers [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=109&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was helping my son with math homework today.. One of the problems was to find all prime numbers up to a 100.. That was enough for me to start looking for an old Erlang script I have played with few years ago&#8230;</p>
<pre>
-module(eratosthenes).
-export([prime_numbers/1]).

% Sieve of Eratosthenes algorithm for finding all prime numbers up to N.
% http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

% Generate list of prime numbers up to N.
prime_numbers(N) when is_number(N) -&gt;
  prime_numbers(N, generate(N)).

prime_numbers(Max, [H|T]) when H * H =
  [H | prime_numbers(Max, [R || R  0])];

prime_numbers(_, T) -&gt; T.

% Generate sequence 2..N
generate(N) -&gt; generate(N, 2).

generate(Max, Max) -&gt; [Max];

generate(Max, X) -&gt; [X | generate(Max, X + 1)].
</pre>
<p>What can I say&#8230; Love Erlang <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wbear.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wbear.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wbear.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wbear.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wbear.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wbear.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wbear.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wbear.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wbear.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wbear.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wbear.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wbear.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wbear.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wbear.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=109&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wbear.wordpress.com/2011/12/08/prime-numbers-with-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84dc5c6521685b28ec5b0fb363abd69f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wbear</media:title>
		</media:content>
	</item>
		<item>
		<title>Sinatra: using partials with xml builder</title>
		<link>http://wbear.wordpress.com/2011/04/23/sinatra-using-partials-with-xml-builder/</link>
		<comments>http://wbear.wordpress.com/2011/04/23/sinatra-using-partials-with-xml-builder/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 13:19:50 +0000</pubDate>
		<dc:creator>Wondering Bear</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://wbear.wordpress.com/?p=89</guid>
		<description><![CDATA[After working mostly with Java for last few years I am back to using Ruby as a main language for my every day work. I have to say just thinking of that makes me smile . We use Sinatra to cover our web needs and I love it. Recently I had to generate some outbound [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=89&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After working mostly with Java for last few years I am back to using Ruby as a main language for my every day work. I have to say just thinking of that makes me smile <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . We use Sinatra to cover our web needs and I love it.<br />
Recently I had to generate some outbound xml feeds and wanted to reuse builder templates. Following is my take on a <a href="https://gist.github.com/938576">builder partial implementation</a> :<br />
<code></p>
<pre>
module Sinatra
  module BuilderHelper
    def helper_modules
      @helper_mods ||= Sinatra::Application.ancestors.select{|m| m.name =~ /Helper/}
    end

    def builder_partial(template, xml, locals = {}, helper_mods = nil)
      template = "#{template}.builder" unless "#{template}" =~ /[.]builder$/
      helper_mods ||= self.helper_modules

      class &lt;&lt; (context = OpenStruct.new({:xml =&gt; xml}.merge(locals))); self; end.send(:include, *helper_mods)

      File.open(File.join(settings.views, "#{template}")) do |f|
        eval f.read, context.send(:binding)
      end
    end
  end

  helpers BuilderHelper
end
</pre>
<p></code></p>
<p>As you can see, I am using OpenStruct as a context object in order to limit variable scope to the locals being passed to the partial&#8230; If you use other Sinatra helper modules and follow a naming convention, helper_mod will find it and make them available to the builder template&#8230;<br />
This is a pretty simple helper module&#8230; but I am hoping it will save somebody time.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wbear.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wbear.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wbear.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wbear.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wbear.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wbear.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wbear.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wbear.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wbear.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wbear.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wbear.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wbear.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wbear.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wbear.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=89&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wbear.wordpress.com/2011/04/23/sinatra-using-partials-with-xml-builder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84dc5c6521685b28ec5b0fb363abd69f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wbear</media:title>
		</media:content>
	</item>
		<item>
		<title>JQuery: Collect input data</title>
		<link>http://wbear.wordpress.com/2010/11/17/jquery-collect-input-data/</link>
		<comments>http://wbear.wordpress.com/2010/11/17/jquery-collect-input-data/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 05:16:30 +0000</pubDate>
		<dc:creator>Wondering Bear</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://wbear.wordpress.com/?p=74</guid>
		<description><![CDATA[Working on a simple data entry app I&#8217;ve ran into a need to collect data from multiple rows of input fields in order to post json data back to the server. Following is a simple jquery plugin, that in combination with few extra html attributes allows to collect data and convert it into json: (function( [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=74&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Working on a simple data entry app I&#8217;ve ran into a need to collect data from multiple rows of input fields in order to post json data back to the server. Following is a <a href="https://gist.github.com/702981">simple jquery plugin</a>, that in combination with few extra html attributes allows to collect data and convert it into json:<br />
<code></p>
<pre>
(function( $ ){
  $.fn.collectFields = function(fieldSelector) {
	var convert = function(type, value) {
		switch (type) {
			case "int"     : return value ? parseInt(value) : 0;
			case "float"   : return value ? parseFloat(value): 0.0;
			case "boolean" : return Boolean(value);
			default        : return value;
		}
	};

	var result = [];
	this.each(function() {
	  	var fields = {};
		$(this).find(fieldSelector).each(function(){
			var name = $(this).attr('name');
			if (name) {
				fields[name] = convert($(this).attr("json-type"), $(this).val());
			}
		});
		result.push(fields);
	});
	return result;

  };
})( jQuery );
</pre>
<p></code></p>
<p>As you can see, I am using &#8220;json-type&#8221; attribute to indicate a type of the data field. In html it looks something like the following:</p>
<p><code><br />
&lt;tr class="player"&gt;<br />
&nbsp;&nbsp;&lt;td&gt;&lt;input type="hidden" id="id__5" name="_id" value="5" class="field" /&gt;&lt;/td&gt;<br />
&nbsp;&nbsp;&lt;td&gt;&lt;input type="text" id="number__5" name="number" value="23" class="field" json-type="int"/&gt;&lt;/td&gt;<br />
&nbsp;&nbsp;&lt;td&gt;&lt;input type="text" id="name__5" name="name" value="Some Good Player" class="field"/&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
...<br />
</code></p>
<p>Script to collect data for all players would look something like this:<br />
<code><br />
&lt;script&gt;<br />
&nbsp;&nbsp;var players = $(".player").collectFields(".field");<br />
&lt;/script&gt;<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wbear.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wbear.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wbear.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wbear.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wbear.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wbear.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wbear.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wbear.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wbear.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wbear.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wbear.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wbear.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wbear.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wbear.wordpress.com/74/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=74&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wbear.wordpress.com/2010/11/17/jquery-collect-input-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84dc5c6521685b28ec5b0fb363abd69f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wbear</media:title>
		</media:content>
	</item>
		<item>
		<title>Discovering Python</title>
		<link>http://wbear.wordpress.com/2010/08/07/discovering-python/</link>
		<comments>http://wbear.wordpress.com/2010/08/07/discovering-python/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 17:14:09 +0000</pubDate>
		<dc:creator>Wondering Bear</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://wbear.wordpress.com/?p=66</guid>
		<description><![CDATA[Despite my strong bias towards Ruby, I am finally learning Python. I think functional nature of the Python is what makes it attractive to me. After spending a lot of time with Erlang and Ruby, I found Python to be an interesting hybrid.. kind of &#8220;in between&#8221; Ruby magic and pure functional feel of Erlang. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=66&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Despite my strong bias towards Ruby, I am finally learning Python.<br />
I think functional nature of the Python is what makes it attractive to me. After spending a lot of time with Erlang and Ruby, I found Python to be an interesting hybrid.. kind of  &#8220;in between&#8221; Ruby magic and pure functional feel of Erlang. I like the fact that pretty much all Ruby meta programming is still possible and on top of that Python has a very good support for functions, higher level functions, which makes is very interesting combination for me. For a few years now I&#8217;ve been hearing people talking about it, but it did not register with me until I started playing with it. One thing for sure I am going to put more time into it&#8230;</p>
<p>Functional Example (very Erlangish and Rubyish in the same time <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )<br />
<code></p>
<pre>
In [21]: def wrapper(fun):
      ....:   def func(*args, **kwargs):
      ....:     print " begin execution %s " % (fun.__name__)
      ....:     fun(*args, **kwargs)
      ....:     print " finished execution %s " % (fun.__name__)
      ....:   return func
      ....: 

In [22]: def hello(msg):
      ....:   print "hello %s" % (msg)
      ....: 

In [23]: f = wrapper(hello)

In [24]: f("Alex")
 begin execution hello
 hello Alex
 finished execution hello
</pre>
<p></code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wbear.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wbear.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wbear.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wbear.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wbear.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wbear.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wbear.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wbear.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wbear.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wbear.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wbear.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wbear.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wbear.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wbear.wordpress.com/66/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=66&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wbear.wordpress.com/2010/08/07/discovering-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84dc5c6521685b28ec5b0fb363abd69f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wbear</media:title>
		</media:content>
	</item>
		<item>
		<title>Sinatra request headers helper</title>
		<link>http://wbear.wordpress.com/2010/03/20/sinatra-request-headers-helper/</link>
		<comments>http://wbear.wordpress.com/2010/03/20/sinatra-request-headers-helper/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 18:12:07 +0000</pubDate>
		<dc:creator>Wondering Bear</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://wbear.wordpress.com/?p=58</guid>
		<description><![CDATA[It is pretty simple, but here is an example of getting request headers from the Rack Environment in a Sinatra application : require 'rubygems' require 'sinatra' helpers do def request_headers env.inject({}){&#124;acc, (k,v)&#124; acc[$1.downcase] = v if k =~ /^http_(.*)/i; acc} end end get '/headers' do puts request_headers.inspect end request_headers helper will filter all HTTP headers [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=58&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It is pretty simple, but here is an <a href="http://gist.github.com/338809">example</a> of getting request headers from the Rack Environment in a Sinatra application :<br />
<code></p>
<pre>
require 'rubygems'
require 'sinatra'

helpers do
  def request_headers
    env.inject({}){|acc, (k,v)| acc[$1.downcase] = v if k =~ /^http_(.*)/i; acc}
  end
end

get '/headers' do
  puts request_headers.inspect
 end
</pre>
<p></code></p>
<p>request_headers helper will filter all HTTP headers and downcase names.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wbear.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wbear.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wbear.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wbear.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wbear.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wbear.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wbear.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wbear.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wbear.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wbear.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wbear.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wbear.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wbear.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wbear.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=58&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wbear.wordpress.com/2010/03/20/sinatra-request-headers-helper/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84dc5c6521685b28ec5b0fb363abd69f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wbear</media:title>
		</media:content>
	</item>
		<item>
		<title>Easy Mocking in Erlang</title>
		<link>http://wbear.wordpress.com/2010/01/15/easy-mocking-in-erlang/</link>
		<comments>http://wbear.wordpress.com/2010/01/15/easy-mocking-in-erlang/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 02:34:31 +0000</pubDate>
		<dc:creator>Wondering Bear</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://wbear.wordpress.com/?p=53</guid>
		<description><![CDATA[Working on yarmo and trying to do test driven development I ran into need to mock some modules to avoid need for hitting database every time. After a bit of trying and errors I ended up using pretty simple set up based on parametrized modules. Basic idea is to pass a proplist, with mock responses [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=53&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Working on <strong><a href="http://github.com/aportnov/yarmo">yarmo</a></strong> and trying to do test driven development I ran into need to mock some modules to avoid need for hitting database every time. After a bit of trying and errors I ended up using pretty simple set up based on parametrized modules. Basic idea is to pass a proplist, with mock responses for methods I am trying to mock, into the module as module parameter and have methods look it up:<br />
<code></p>
<pre>
-module(mock_store, [MockStore]).
-export([read/1, create/1]).

read(Key) -&gt;
	callback(read, [Key]).

create(Key, Document) -&gt;
	callback(create, [Key, Document]).

%% Helper Functions

callback(Name, Args) -&gt;
	case proplists:lookup(Name, MockStore) of
		none -&gt; undefined;
		{Name, Fun} when is_function(Fun) -&gt; Fun(Args);
		{Name, Value} -&gt; Value
	end.
</pre>
<p></code></p>
<p>The callback is pretty simple, but allows to pass in ether mock result or a function, which will generate response based on parameters, passed to the method.<br />
Now I can mock read/create in the test as following:<br />
<code></p>
<pre>
test_mod(StoreOptions) -&gt;
	Store = mock_store:new(StoreOptions),
	yarmo_destination:new(Store).

....

Mod = test_mod([{read, not_found}]),
.....

Mod = test_mod([{read, fun([Key]) -&gt; ?assertEqual("sample", Key), Doc end}])
</pre>
<p></code></p>
<p>Nothing special, but so far it is helping me to keep my tests from hitting real storage <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wbear.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wbear.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wbear.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wbear.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wbear.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wbear.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wbear.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wbear.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wbear.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wbear.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wbear.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wbear.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wbear.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wbear.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=53&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wbear.wordpress.com/2010/01/15/easy-mocking-in-erlang/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84dc5c6521685b28ec5b0fb363abd69f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wbear</media:title>
		</media:content>
	</item>
		<item>
		<title>YARMO &#8211; Yet Another RESTFul Messaging Option</title>
		<link>http://wbear.wordpress.com/2009/12/23/yarmo-yet-another-restful-messaging-option/</link>
		<comments>http://wbear.wordpress.com/2009/12/23/yarmo-yet-another-restful-messaging-option/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 15:19:26 +0000</pubDate>
		<dc:creator>Wondering Bear</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://wbear.wordpress.com/?p=49</guid>
		<description><![CDATA[I&#8217;ve been spending a lot of time in a past few month doing research around a &#8220;RESTful&#8221; messaging solution. The idea is to have a web service that can support queue and topic notations and provide more less simple REST based API. What I found so far is that there is no good &#8220;out of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=49&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending a lot of time in a past few month doing research around a &#8220;RESTful&#8221; messaging solution. The idea is to have a web service that can support queue and topic notations and  provide more less simple REST based API. What I found so far is that there is no good &#8220;out of the box&#8221; implementation. There is a specification <a href="http://www.rest-star.org">REST-*</a>, that looks very promising in my opinion&#8230;   So, I&#8217;ve decided it would be fun to try implementing this spec. Since I am still a big fan of <a href="http://erlang.org/">Erlang</a>, I will be using it for the <a href="http://github.com/aportnov/yarmo">project</a>. So far it is shaping up to be a  <a href="http://code.google.com/p/mochiweb/">MochiWeb</a> application with <a href="http://couchdb.apache.org/">CouchDB</a> used for storage. It is still very much work in progress, but for now it is my new Erlang playground <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wbear.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wbear.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wbear.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wbear.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wbear.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wbear.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wbear.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wbear.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wbear.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wbear.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wbear.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wbear.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wbear.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wbear.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=49&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wbear.wordpress.com/2009/12/23/yarmo-yet-another-restful-messaging-option/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84dc5c6521685b28ec5b0fb363abd69f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wbear</media:title>
		</media:content>
	</item>
		<item>
		<title>More fun with Erlang</title>
		<link>http://wbear.wordpress.com/2009/07/21/more-fun-with-erlang/</link>
		<comments>http://wbear.wordpress.com/2009/07/21/more-fun-with-erlang/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 14:23:54 +0000</pubDate>
		<dc:creator>Wondering Bear</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://wbear.wordpress.com/?p=45</guid>
		<description><![CDATA[I am working on a prototype of an application that needs to proxy client HTTP requests to different origins. I needed a function that will filter HTTP headers before I forward them. Application is in Erlang, but since I&#8217;ve been a big Ruby fan for a while now&#8230; Here is a comparison of possible implementations: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=45&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am working on a prototype of an application that needs to proxy client HTTP requests to different origins. I needed a function that will filter HTTP headers before I forward them. Application is in Erlang, but since I&#8217;ve been a big Ruby fan for a while now&#8230; Here is a comparison of possible implementations:</p>
<p>Ruby:</p>
<p><code></p>
<pre>
  NO_FORWARD = ['Host', 'Content-Length', 'Accept-Encoding']

  def filter_headers(headers)
      headers.inject({}) do |result, (name, value)|
         result[name.to_s] = value unless NO_FORWARD.include?(name.to_s)
         result
      end
  end
</pre>
<p></code></p>
<p>Now, same code &#8230; but in Erlang:</p>
<p><code><br />
filter_headers(Headers) -&gt;<br />
        NoForward = ['Host', 'Content-Length', 'Accept-Encoding'],</p>
<p>	Pred = fun({Name, Value}, L) -&gt;<br />
		case lists:member(Name, NoForward) of<br />
			false -&gt;<br />
				Key = case is_atom(Name) of<br />
					true  -&gt; atom_to_list(Name);<br />
					false -&gt; Name<br />
				end,<br />
				[{Key, Value} | L];<br />
			true  -&gt; L<br />
		end<br />
	end,	</p>
<p>	lists:foldl(Pred, [], Headers).<br />
</code></p>
<p>I think given a bit more effort, each code sample might be even more compact, but even what I have looks pretty readable <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wbear.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wbear.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wbear.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wbear.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wbear.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wbear.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wbear.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wbear.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wbear.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wbear.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wbear.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wbear.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wbear.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wbear.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=45&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wbear.wordpress.com/2009/07/21/more-fun-with-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84dc5c6521685b28ec5b0fb363abd69f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wbear</media:title>
		</media:content>
	</item>
		<item>
		<title>Erlang &#8211;  elegant, but mind blowing :)</title>
		<link>http://wbear.wordpress.com/2009/07/16/erlang-elegant-but-mind-blowing/</link>
		<comments>http://wbear.wordpress.com/2009/07/16/erlang-elegant-but-mind-blowing/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 19:22:32 +0000</pubDate>
		<dc:creator>Wondering Bear</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://wbear.wordpress.com/?p=34</guid>
		<description><![CDATA[I&#8217;ve been playing around with Erlang for a while now. Interesting thing about Erlang is that the language is pretty small and very consistent, I guess it is typical for functional language , but in a same time it takes a long time to start thinking in &#8220;Erlang way&#8221;. Everything is based on pattern matching [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=34&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with <a href="http://www.erlang.org">Erlang</a> for a while now. Interesting thing about Erlang is that the language is pretty small and very consistent, I guess it is typical for functional language <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  , but in a same time it takes a long time to start thinking in &#8220;Erlang way&#8221;. Everything is based on pattern matching &#8211;  function signatures, case and if statements are all just pattern matching. Once you get a hold of it&#8230; it is a lot of fun and makes code pretty clean, short and readable.<br />
Here is an example of function that parses ttl &#8211; 20s, 10m, 2h :</p>
<p>first we have an entry point:</p>
<p><code><br />
parse(Ttl) -&gt; parse_ttl(lists:reverse(Ttl)).<br />
</code></p>
<p>And here comes all the fun :</p>
<p><code><br />
%% Private Functions.</code></p>
<p>parse_ttl([$s | Ttl]) -&gt; list_to_integer(lists:reverse(Ttl));<br />
parse_ttl([$S | Ttl]) -&gt; parse_ttl([$s | Ttl]);</p>
<p>parse_ttl([$m | Ttl]) -&gt; 60 * list_to_integer(lists:reverse(Ttl));<br />
parse_ttl([$M | Ttl]) -&gt; parse_ttl([$m | Ttl]);</p>
<p>parse_ttl([$h | Ttl]) -&gt; 60* 60 * list_to_integer(lists:reverse(Ttl));<br />
parse_ttl([$H | Ttl]) -&gt; parse_ttl([$h | Ttl]);</p>
<p>parse_ttl(_) -&gt; false.</p>
<p>Since strings in Erlang are just lists of integers, it is very common to apply list functions to strings. The [H | T] notation allows you to separate &#8220;head&#8221; and a &#8220;tail&#8221; of the list; in our case first symbol and the rest of the string. And since we have reversed our original string before applying our pattern &#8230; it is working pretty well <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wbear.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wbear.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wbear.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wbear.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wbear.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wbear.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wbear.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wbear.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wbear.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wbear.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wbear.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wbear.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wbear.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wbear.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=34&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wbear.wordpress.com/2009/07/16/erlang-elegant-but-mind-blowing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84dc5c6521685b28ec5b0fb363abd69f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wbear</media:title>
		</media:content>
	</item>
		<item>
		<title>Easy Helpers for Sinatra</title>
		<link>http://wbear.wordpress.com/2009/07/06/easy-helpers-for-sinatra/</link>
		<comments>http://wbear.wordpress.com/2009/07/06/easy-helpers-for-sinatra/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 01:37:26 +0000</pubDate>
		<dc:creator>Wondering Bear</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://wbear.wordpress.com/?p=35</guid>
		<description><![CDATA[I am spending more time with Sinatra apps. I think it is a perfect framework to start application with. What I like about Sinatra the most is how easy it is to extend it. Recently I was building a small app, that processes user provided templates and was looking for an easy way to add [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=35&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am spending more time with Sinatra apps. I think it is a perfect framework to start application with. What I like about Sinatra the most is how easy it is to extend it. Recently I was building a small app, that processes user provided templates and was looking for an easy way to add template components (helpers) to give customers a sort of DSL to work with. What I ended up doing was the following:<br />
<code></p>
<pre>
module Components

  components_path = File.expand_path(File.dirname(__FILE__) + '/components')

  files = Dir.new(components_path).select{|f| f =~ /.*\.rb/ } || []
  files.each do |f|
    body = File.new(File.join([components_path, f])).read
    name = File.basename(f, '.rb').capitalize + "Helper"
    module_eval &lt;&lt;-&quot;end;&quot;
      module #{name}
        #{body}
      end
    end;
    Sinatra.helpers(const_get(name))
  end

end
</pre>
<p></code></p>
<p>Link to the file: <a href="http://gist.github.com/141220">http://gist.github.com/141220</a></p>
<p>As you can see this pretty simple Ruby magic allows me to put my &#8220;components&#8221; into a subdirectory and add them all as Sinatra helpers. Since the body of the component is wrapped into a module, component development becomes very easy. Following code, once saved into components directory will add a search helper to your app:<br />
<code><br />
def search(options = {})<br />
......<br />
end<br />
</code> </p>
<p>Pretty simple, but still fun <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wbear.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wbear.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wbear.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wbear.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wbear.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wbear.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wbear.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wbear.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wbear.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wbear.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wbear.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wbear.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wbear.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wbear.wordpress.com/35/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wbear.wordpress.com&amp;blog=3060503&amp;post=35&amp;subd=wbear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wbear.wordpress.com/2009/07/06/easy-helpers-for-sinatra/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/84dc5c6521685b28ec5b0fb363abd69f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wbear</media:title>
		</media:content>
	</item>
	</channel>
</rss>
