<?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>Fabiano PS</title>
	<atom:link href="http://fabianosoriani.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://fabianosoriani.wordpress.com</link>
	<description>Not perfect, agile</description>
	<lastBuildDate>Fri, 06 Jan 2012 18:18:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='fabianosoriani.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Fabiano PS</title>
		<link>http://fabianosoriani.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://fabianosoriani.wordpress.com/osd.xml" title="Fabiano PS" />
	<atom:link rel='hub' href='http://fabianosoriani.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Ruby&#8217;s fear-cancer</title>
		<link>http://fabianosoriani.wordpress.com/2011/11/11/rubys-fear-cancer/</link>
		<comments>http://fabianosoriani.wordpress.com/2011/11/11/rubys-fear-cancer/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 13:25:34 +0000</pubDate>
		<dc:creator>fabianosoriani</dc:creator>
				<category><![CDATA[node.js]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://fabianosoriani.wordpress.com/?p=452</guid>
		<description><![CDATA[This video: High Performance Ruby: Threading Versus Evented by Dr Nic Williams, Engine Yard It meant so much to me! For around 4 months I&#8217;ve been using Node.js, and before that, for 3 years, programming Rails. As soon as I started on Node.js, I could feel that something was different. My little Computer Science bachelor conscience was starting to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=452&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>This video: <a href="http://vimeo.com/31204217">High Performance Ruby: Threading Versus Evented by Dr Nic Williams, Engine Yard</a></h2>
<p><strong>It meant so much to me!</strong></p>
<p>For around 4 months I&#8217;ve been using Node.js, and before that, for 3 years, programming Rails.</p>
<p>As soon as I started on Node.js, I could feel that something was different. My little Computer Science bachelor conscience was starting to tell me: now you are <em><strong>starting</strong></em> to do it right <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>But then, lets go back, Ruby&#8217;s syntax is lovely.. Rails API is sugar! But still, it&#8217;s <strong>neverland</strong>. Why??</p>
<p>It does not fit real world! It is a thin layer of happiness, so delicate, that we feel <strong>fear</strong> of touching it and <strong>breaking</strong> it. So what we puny humans do? We delegate it to those genius heroes who will be able to take that code and maybe squeeze a few more couples of requests/sec!</p>
<p>But not even that is the <em>cancer</em> I mean.</p>
<p>The cancer here is represented by clown hosting the video. &#8220;<em>Oh those scientific articles mess with our head and stuff O.o Let me chew that evil reality and I will give you the RIGHT (sugar coated) solution!</em>&#8221; and all other non fun nor assertive statements. By the way, <em>he may be</em> referring to the <a href="http://www.kegel.com/c10k.html" target="_blank">C10K problem</a>, and <a href="http://www.google.com.br/search?q=c10k+threads+problem" target="_blank">alike</a>, articles.</p>
<p>The problem here is, VP  EngineYard and want ppl addicted on his junk. He does not host Node.js.</p>
<p>Ruby always had so many language implementations to solve some important language problems, as well as servers. This is not the first time a good solution for ruby is born (JRuby+Trinidad), but why would they share it before if he could have people paying for so much RAM?</p>
<p>The reason I believe he felt compelled to share it now, is that Node.js unoptimized code can outperform Rails by a LOT,  under 150Mb.</p>
<p>But my main problem is <strong>fear of complexity</strong>. The host talks about it all over the initial part of the video. <em>He refers his audience under constant fear of it&#8217;s own ignorance all the time</em>. This is a awful, and that&#8217;s how I felt using <strong>Rails</strong>. Such a large stack, complex language design, only understanding the framework code itself was hard task.</p>
<p>To keep people in bliss ignorance he just goes like: &#8220;Oh I promissed evented? We are past that, right?! HAAAA&#8221; so just be happy and keep the <em>status quo</em>. You would&#8217;t want to mess your pretty little head with <em>asynchronous code</em>, would you?</p>
<p>I like Node.js, besides performance, language is simple; it is JavaScript, open Objects, closure and more. Of course, don&#8217;t assume well-written JS is something easy to do. No great code in any modern language is easy to achieve.</p>
<p>If you&#8217;ve developed Rails, you have concepts of MRI, thin, mongrel, jruby, 1.8.7, 1.9.2, rubinius, unicorn, and LOT MORE, whilst in node.js world all that stands for: node.js. <strong>It is a unification point for language and server</strong>.</p>
<p>What about gems?  npm, a easier system of distributing packages.</p>
<p><strong>Wrapping it up</strong>, node.js is no silver bullet, it just made me realize the problems I had while programming ruby, as much as ruby did it for me on php. If nothing else, node.js helped improve ruby&#8217;s community by adding options to the web development mainstream.</p>
<p>Would I work with Rails again? If a employer would point me that out as the only chosen solution, then yes, and I&#8217;d probably try that stack, but I prefer confidence instead of fear.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fabianosoriani.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fabianosoriani.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fabianosoriani.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fabianosoriani.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fabianosoriani.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fabianosoriani.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fabianosoriani.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fabianosoriani.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fabianosoriani.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fabianosoriani.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fabianosoriani.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fabianosoriani.wordpress.com/452/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fabianosoriani.wordpress.com/452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fabianosoriani.wordpress.com/452/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=452&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fabianosoriani.wordpress.com/2011/11/11/rubys-fear-cancer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/922c9fdc02ec0531cd152ca7cadb33bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fabianosoriani</media:title>
		</media:content>
	</item>
		<item>
		<title>When to Ruby on Rails, when to Node.js</title>
		<link>http://fabianosoriani.wordpress.com/2011/09/11/when-to-ruby-on-rails-when-to-node-js/</link>
		<comments>http://fabianosoriani.wordpress.com/2011/09/11/when-to-ruby-on-rails-when-to-node-js/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 00:56:48 +0000</pubDate>
		<dc:creator>fabianosoriani</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://fabianosoriani.wordpress.com/?p=442</guid>
		<description><![CDATA[Hello! I am trying to do a sort of indirect comparison between Rails and Node.js. The very main reason of being indirect, is that Rails is a Framework, while Node.js is an implementation of a programming language. If it were be to put in a simple phrase, Rails is resourceful and Node.js is fast. Lets [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=442&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello!</p>
<p>I am trying to do a sort of <strong>indirect comparison</strong> between Rails and Node.js. The very main reason of being indirect, is that <strong>Rails is a Framework</strong>, while <strong>Node.js is an implementation of a programming language</strong>.</p>
<p>If it were be to put in a simple phrase, <strong>Rails is resourceful</strong> and <strong>Node.js is fast</strong>.</p>
<p>Lets elaborate some..</p>
<h3><strong>Rails</strong></h3>
<p>Is the most complete open-source framework available (that I know of)! Big companies use it. It can do lots of stuff well, in an organized manner; this meaning, Rails is more than just MVC, it has a full stack of features well-integrated, at the same time being very modular. <em>Some</em> of the features included out of the box:</p>
<ul>
<li>Database adapter for the majority of them, supporting plug your own.</li>
<li>Database migrations, so multiple dev can sync and experiment with their DB.</li>
<li>Powerful engines for Views, Controllers and Models.</li>
<li>Support to code generator.</li>
<li>Has structure to all sorts of tests and friendly to TDD.</li>
<li>Really awesome documentation.</li>
<li>Model has all kinds of hooks, validations and associations.</li>
<li>Controller has support to handle XML/JSON in the same action that serves HTML.</li>
<li>Gems that integrate, for instance, Memcached, MongoDB, Auth and lots more.</li>
</ul>
<div>So Rails is war-proven, capable of integrating lots of features together without harass. There is also a very cool post of Fabio Akita in the refs. about how it made possible to develop systems in periods before impossible.</div>
<h3>Node.js</h3>
<p>Two things make this language extremely suitable for web:</p>
<p>Its engine, V8 is very fast! In a very loose average, 8 times faster than Python (or even up to 200 at peak). Python already outperforms Ruby</p>
<p>Second point; and this argument is separated from the above, is that it async-driven. As in the case, requests can be performed in parallel, without any blocking I/O. A single server can handle a lot.</p>
<p>So, it is a very new sort of backend language, but huge players, besides Joyent, who invented it, are adopting it, including LearnBoost and LinkedIn, which has an awesome article about using. The language, and it main web framework, Express, deserve a list of features (you can check more info in the references below).</p>
<ul>
<li>It´s web server is able to handle a HUGE number of connections out of the box</li>
<li>Various libraries can be run on browser, the same as in the server</li>
<li>Very friendly to Websockets (real-time web apps)</li>
<li>Lots of libraries are being ported to it from other langs.</li>
<li>Express, inspired in ruby´s Sinatra; is very light on memory but also very powerful</li>
</ul>
<div>Running a simple benchmark against a single server instance, I were able to get 587 req/s accessing MySQL without any external cache support. This number could scale, if I used Cluster to spawn at least a process per processor.</div>
<h3>Summarizing, When to use each?</h3>
<p><strong>Rails</strong> really shines when..</p>
<ul>
<li>The database is complex in terms of associations.</li>
<li>Business rules are complex, and validation is needed.</li>
<li>When the number of requests isn´t the a decisive factor.</li>
<li>Administrative interfaces.</li>
<li>Many developers in parallel each using his own database</li>
<li>The database to be used is undefined, or may vary.</li>
</ul>
<div>What about <strong>Node.js</strong>?</div>
<div>
<ul>
<li>APIs</li>
<li>Real-time web/mobile apps.</li>
<li>Application that should scale to lots of concurrent requests.</li>
<li>Little memory footprint</li>
</ul>
</div>
<p><strong>This being said, there is no reason at all, a web-site or service can´t easily integrate both</strong>.</p>
<p><em>&#8211; I&#8217;d appreciate if you could leave a comment, either to talk about your case, or add up.</em></p>
<p><span class="Apple-style-span" style="font-weight:bold;">References</span></p>
<p>&nbsp;</p>
<p>UPDATE: <a href="http://www.mikealrogers.com/posts/a-new-direction-for-web-applications-.html">http://www.mikealrogers.com/posts/a-new-direction-for-web-applications-.html</a></p>
<p><a href="http://guides.rubyonrails.org/">http://guides.rubyonrails.org/</a></p>
<p><a href="http://railscasts.com/">http://railscasts.com/</a></p>
<p><a href="http://blog.heroku.com/archives/2011/6/22/the_new_heroku_2_node_js_new_http_routing_capabilities/">http://blog.heroku.com/archives/2011/6/22/the_new_heroku_2_node_js_new_http_routing_capabilities/</a></p>
<p><a href="http://nodejs.org/">http://nodejs.org/</a></p>
<p><a href="http://akitaonrails.com/2011/04/16/twitter-muda-de-ruby-para-java-ruby-e-3x-mais-lento-que-java">http://akitaonrails.com/2011/04/16/twitter-muda-de-ruby-para-java-ruby-e-3x-mais-lento-que-java</a></p>
<p><a href="http://venturebeat.com/2011/08/16/linkedin-node/">http://venturebeat.com/2011/08/16/linkedin-node/</a></p>
<p><a href="http://blog.bossylobster.com/2011/08/lesson-v8-can-teach-python-and-other.html">http://blog.bossylobster.com/2011/08/lesson-v8-can-teach-python-and-other.html</a></p>
<p><a href="https://github.com/LearnBoost">https://github.com/LearnBoost</a></p>
<p><a href="http://www.readwriteweb.com/hack/2011/01/how-3-companies-are-using-node.php">http://www.readwriteweb.com/hack/2011/01/how-3-companies-are-using-node.php</a></p>
<p><a href="http://twitter.com/#!/FlockonUS/status/104655096956190720">http://twitter.com/#!/FlockonUS/status/104655096956190720</a></p>
<p><a href="https://github.com/LearnBoost/cluster">https://github.com/LearnBoost/cluster</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fabianosoriani.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fabianosoriani.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fabianosoriani.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fabianosoriani.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fabianosoriani.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fabianosoriani.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fabianosoriani.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fabianosoriani.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fabianosoriani.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fabianosoriani.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fabianosoriani.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fabianosoriani.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fabianosoriani.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fabianosoriani.wordpress.com/442/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=442&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fabianosoriani.wordpress.com/2011/09/11/when-to-ruby-on-rails-when-to-node-js/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/922c9fdc02ec0531cd152ca7cadb33bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fabianosoriani</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing a Node.js Express API server with Vows (functional)</title>
		<link>http://fabianosoriani.wordpress.com/2011/08/31/testing-a-node-js-express-api-server-with-vows-functional/</link>
		<comments>http://fabianosoriani.wordpress.com/2011/08/31/testing-a-node-js-express-api-server-with-vows-functional/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 21:08:15 +0000</pubDate>
		<dc:creator>fabianosoriani</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[technique]]></category>
		<category><![CDATA[tecnica]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[auth]]></category>
		<category><![CDATA[functional test]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://fabianosoriani.wordpress.com/?p=435</guid>
		<description><![CDATA[How to test an API that must be authenticated via session? vows: plural of vow Noun: A solemn promise. Verb: Solemnly promise to do a specified thing: &#8220;one fan vowed, “I&#8217;ll picket every home game.”&#8221;. Oh wait.. Vows.js Asynchronous behaviour driven development for Node. I should&#8230; test every method I expose to the client.. Since the Vows documentation is very [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=435&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>How to test an API that must be authenticated via session?</p>
<blockquote>
<h3><em>vows: </em>plural of<em> vow</em></h3>
<div>
<div>Noun: A solemn promise.</div>
<div>Verb: Solemnly promise to do a specified thing: &#8220;one fan <strong>vowed</strong>, “I&#8217;ll picket every home game.”&#8221;.</div>
</div>
</blockquote>
<h2>Oh wait..</h2>
<blockquote><p>
  <strong><a href="http://vowsjs.org/#reference">Vows.js</a></strong><br />
  Asynchronous behaviour driven development for Node.
</p></blockquote>
<p>I should&#8230; test every method I expose to the client..<br />
Since the <a href="http://vowsjs.org/#intro" target="_blank">Vows documentation is very awesome</a>, and I already have <a title="Starting a Node.js Express API to serve json, (with auth, MySQL – based)" href="http://fabianosoriani.wordpress.com/2011/08/15/express-api-on-node-js-with-mysql-auth/" target="_blank">another post</a> that explains the strategy used on the API, there is no need to much talk; just not that this code is still very early in maturity.<br />
<em>Straight to current code [ test/api-test-authed.js ]</em><br />
<pre class="brush: jscript;">
/*
 * INSTRUCTIONS
 *
 * run the site at localhost, port 8010
 *
 * run vows --spec test/api-test-authed.js
 *
 */


var request = require('request'),
    vows = require('vows'),
    assert = require('assert'),
    apiUrl = &quot;http://localhost:8010/&quot;,
    cookie = null


var apiTest = {
  general: function( method, url, data, cb ){
    //console.log( 'cb?', cb )
    request(
      {
        method: method,
        url: apiUrl+(url||''),
        json: data || {},
        headers: {Cookie: cookie}
      },
      function(req, res){
        cb( res )
      }
    )
  },
  get: function( url, data, cb  ){ apiTest.general( 'GET', url, data, cb    )  },
  post: function( url, data, cb ){ apiTest.general( 'POST', url, data, cb   )  },
  put: function( url, data, cb  ){ apiTest.general( 'PUT', url, data, cb    )  },
  del: function( url, data, cb  ){ apiTest.general( 'DELETE', url, data, cb )  }
}

function assertStatus(code) {
  return function (res, b, c) {
    assert.equal(res.statusCode, code);
  };
}


function assertJSONHead(){
  return function(res, b, c ){
    assert.equal( res.headers['content-type'], 'application/json; charset=utf-8' )
  }
}

function assertValidJSON(){
  return function(res, b ){
    // this can either be a Object or Array
    assert.ok( typeof( res.body ) == 'object' )
    //assert.isObject( res.body)
  }
}





// TODO include unauthed tests
var suite = vows.describe('API Localhost HTTP Authenticated Tests')

// Very first test!
.addBatch({
  &quot;Server should be UP as in: var apiUrl&quot;: {
    topic: function(){
      apiTest.get('', {} ,this.callback )
    },

    '/ should repond something' : function(res, b){
      assert.ok(res.body)
    }
  }
})

.addBatch({
  'Authenticate to /login': {
    topic: function(){
      request.post(
        {
          url: &quot;http://localhost:8010/login&quot;,
          json: { user:{ username: 'flockin_lab', password: '123456' }}
        },
        this.callback
      );
    },



    'get a valid Cookie': function(req, res, body, err){
      try{
        cookie = res.headers['set-cookie'].pop().split(';')[0]
        console.log(&quot;GOT COOKIE!&quot;, cookie)
      } catch(e){ }

      assert.ok( typeof(cookie) == 'string' &amp;&amp; cookie.length &gt; 10 )
    }
  }
})
.addBatch({
  'Users#index': {
    topic: function(){
      apiTest.get('admin/employees', {}, this.callback)
    },
    'should be 200': assertStatus(200),
    'should have JSON header' : assertJSONHead(),
    'body is valid JSON' : assertValidJSON(),

  },
})
.addBatch({
  'Qrcodes#index': {
    topic: function(){
      apiTest.get('admin/qrcodes', {}, this.callback)
    },
    'should be 200': assertStatus(200),
    'should have JSON header' : assertJSONHead(),
    'body is valid JSON' : assertValidJSON(),

  },
})

//suite.run( )
suite.export( module )
</pre></p>
<h2>Brief Discussion</h2>
<p>This code is still state-of-art,<br />
We depend on the lib &#8216;request&#8217;, which is pretty good,<br />
The server should already be started, since I see no point in having the test being responsible to bring it up and handle it.</p>
<p>Can improve it? Please leave a comment! <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/fabianosoriani.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fabianosoriani.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fabianosoriani.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fabianosoriani.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fabianosoriani.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fabianosoriani.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fabianosoriani.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fabianosoriani.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fabianosoriani.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fabianosoriani.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fabianosoriani.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fabianosoriani.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fabianosoriani.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fabianosoriani.wordpress.com/435/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=435&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fabianosoriani.wordpress.com/2011/08/31/testing-a-node-js-express-api-server-with-vows-functional/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/922c9fdc02ec0531cd152ca7cadb33bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fabianosoriani</media:title>
		</media:content>
	</item>
		<item>
		<title>Starting a Node.js Express API to serve json, (with auth, MySQL &#8211; based)</title>
		<link>http://fabianosoriani.wordpress.com/2011/08/15/express-api-on-node-js-with-mysql-auth/</link>
		<comments>http://fabianosoriani.wordpress.com/2011/08/15/express-api-on-node-js-with-mysql-auth/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 22:45:08 +0000</pubDate>
		<dc:creator>fabianosoriani</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[technique]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[auth]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://fabianosoriani.wordpress.com/?p=428</guid>
		<description><![CDATA[Hello and welcome! Foreword, and purpose I will be putting this JSON-API up, to serve USERS as a restful resource, trying to be light as possible, still serving content only to authenticated peers (auth based on cookie). The regular use will be something as, the client makes login, sending params via POST, ant then is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=428&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello and welcome!</p>
<h2>Foreword, and purpose</h2>
<p>I will be putting this JSON-API up, to serve USERS as a restful resource, trying to be light as possible, still serving content only to authenticated peers (auth based on cookie).</p>
<p>The regular use will be something as, the client makes login, sending params via POST, ant then is able to access all resources we may serve.</p>
<p>I will be using some packages, all being possible to install via <em>npm install</em>, lets talk about them:</p>
<ul>
<li><a href="http://expressjs.com/" target="_blank">Express</a>, itself is like the Ruby&#8217;s <a href="http://www.sinatrarb.com/" target="_blank">Sinatra</a> Framework, but async, for Node.js</li>
<li><a href="https://github.com/visionmedia/express-resource" target="_blank">Express-resource</a>, a simple and extendable way to define Restful resources</li>
<li><a href="http://www.sequelizejs.com/#installation" target="_blank">Sequelize</a>, a MySQL ORM! Offer n-m relations, and a <em>.sync()</em> way to define your own Schema! (<em>better than migrations?</em>)</li>
<li><a href="https://github.com/marak/Faker.js/" target="_blank">Faker</a>, a generator of fake-data that we need</li>
<li><a href="http://mustache.github.com/mustache.5.html" target="_blank">Mustache</a>, String template engine. Will be using for minimal tasks, not required.</li>
<li><a href="https://github.com/visionmedia/jade" target="_blank">Jade</a>, view template engine. Not required at all, but since I started coding there, will keep it for now.</li>
</ul>
<h2>The app skeleton</h2>
<p>Install express with -g and generate an app from it.</p>
<p>We will be keeping 3 core files:</p>
<p><em><strong>app.js  </strong></em>: The main file; require all other from there, and configure Express!</p>
<p><em><strong>models.js</strong></em> : The file that has all models definitions exported.</p>
<p><em><strong>routes.js</strong></em> : Acts as a general router and controller for the app. Also holds the functionality of authenticating all users that get past <em>/admin/*</em></p>
<p>&nbsp;</p>
<h2>Files</h2>
<pre>./app.js<br />
<pre class="brush: jscript;">

// Detect Params  http://nodejs.org/docs/latest/api/process.html#process.argv
if (process.argv.indexOf('--seed') &gt; -1) {
  /**
   * Indicates when the DB should be re-schemed and seeded again
   */
  GLOBAL.db_seed = true;
}

if (process.argv.indexOf('--no-auth') &gt; -1 ){
  /**
   * Indicates when to run without requiring auth for API
   */
  GLOBAL.no_auth = true;
}


var express = require('express'),
    /**
     * Instantiate the unique Express instance
     */
    app = module.exports = express.createServer(),
    models = require('./models.js'),
    S = require('mustache').to_html;


/**
 * @type {Object}
 *
 * A list of all Sequelize Models available, representing the tables.
 */
GLOBAL.models = models;

/**
 * @type {Express}
 *
 * The Singleton of Express app instance
 */
GLOBAL.app = app;



// Configuration

app.configure(function() {
  app.use(express.logger({format: 'dev'}));
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.cookieParser());
  app.use(express.session({ secret: 'evilWorldDom1nat10nPlanzisstillsmallshouldhaveNoWords' }));
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));

});

app.configure('development', function() {
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function() {
  app.use(express.errorHandler());
});


// Routes

require('./routes.js');


app.listen(8010);
console.log('Express server listening on port %d in %s mode',
   app.address().port, app.settings.env);
</pre></p>
<p>./models.js</p>
<p><pre class="brush: jscript;">
var Sequelize = require('sequelize'),
    db = new Sequelize('dev_', 'root', '123456');

  /**
   * @type {Object}
   * Map all attributes of the registry
   * (Instance method useful to every sequelize Table)
   * @this {SequelizeRegistry}
   * @return {Object} All attributes in a Object.
   */
    var map_attributes = function() {
      var obj = new Object(),
          ctx = this;
      ctx.attributes.forEach(
        function(attr) {
          obj[attr] = ctx[attr];
        }
      );
      return obj;
    };

/**
 * @type {Object}
 * All models we have defined over Sequelize, plus the db instance itself
 */
var self = module.exports = {
  'db' : db,

  User: db.define('user',
    {
      name: {
              type: Sequelize.STRING,
              defaultValue: 'Not Big Deal',
              allowNull: false
            }
    },
    {
      timestamps: true,
      freezeTableName: true,

      classMethods: {
        staticExample: function() { this.name }
      },
      instanceMethods: {
        mapAttributes: map_attributes
      }
    }
  ),

  Activity: db.define('activity',
    {
      type: { type: Sequelize.STRING },
      value: { type: Sequelize.STRING }
    },
    {
      timestamps: true,
      freezeTableName: true,

      instanceMethods: {
        mapAttributes: map_attributes
      }
    }
  ),

  Company: db.define('company',
  {
    name: { type: Sequelize.STRING, defaultValue: 'MegaCorp', allowNull: false }
  },
  {
    timestamps: true,
    freezeTableName: true,

    instanceMethods: {
        mapAttributes: map_attributes
      }
  })


};

self.Activity.belongsTo(self.User, {foreignKey: 'user_id'});
self.User.hasMany(self.Activity, {foreignKey: 'user_id'});

self.User.belongsTo(self.Company, {foreignKey: 'company_id'});
self.Company.hasMany(self.User, {foreignKey: 'company_id'});



if (GLOBAL.db_seed) {
  console.info('SEED TIME!');

  var chainer = new Sequelize.Utils.QueryChainer;

  chainer
    .add(self.Company.sync({force: true}))
    .add(self.User.sync({force: true}))
    .add(self.Activity.sync({force: true}))
    .run()
    .on('success', function() {

      var seeds = require('./seeds');
      for (var model_name in seeds) {
        console.log('MODEL', model_name);
        for (var i = 0; i &lt; seeds[model_name].length; i++) {
          self[model_name].create(seeds[model_name][i])
            .on('success', function(novo) { })
            .on('failure', function(erro) {
              console.error('DB SEED ERROR!!', erro);
              process.kill();
            });
          console.log('  ', seeds[model_name][i]);
        }
      }
    })
    .on('failure', function(errors) {

      console.error('DB schema change FAIL', errors);
      process.kill();
    });

}

// User.staticExample()
// User.build({}).instanceExample()
</pre>&nbsp;</p>
<p>./routes.js</p>
<p><pre class="brush: jscript;">
S = require('mustache').to_html;
Resource = require('express-resource'); // paths Express, add .resource



/**
 * ROOT
 */
app.get('/', function(req, res) {

  // This big mess just points out all routes we have, along with the verbs
  var path_list = S(
    '{{#routes_obj}}' +
    &quot;&lt;a href='{{path}}'&gt;{{method}}: {{path}} &lt;/a&gt; &lt;br/&gt;&quot; +
    '{{/routes_obj}}',
    {
      routes_obj: (app.routes.routes.get ? app.routes.routes.get : [])
        .concat((app.routes.routes.post ? app.routes.routes.post : [])
          .concat((app.routes.routes.put ? app.routes.routes.put : [])
            .concat(app.routes.routes.delete ? app.routes.routes.delete : [])
              .concat([{ path: '/auth.html', method: 'get'}])))
    }
  );

  res.render('index', {
    title: 'DBServer',
    'path_list': path_list,
    logged: req.session.authed ? 'YES :)' : 'NO :('
  });

});





/**
 * AUTH methods
 */
app.post('/login', function(req, res) {

  console.info('login PARAM: ', req.body);

  var credentials = req.body.user;

  if (GLOBAL.no_auth ||
       (credentials &amp;&amp;
        credentials.username == 'super_safe' &amp;&amp;
        credentials.password == '123456')
      ) {

    req.session.authed = true;
    res.json(['OK']);
  } else {
    res.json(['FAIL']);
  }

});

app.get('/logout', function(req, res) {
  req.session.authed = null;
  res.json(['OK']);
});





/*
 * API Authentication filter
 */
app.all('/admin*', function(req, res, next) {

  if (req.session.authed) {
    next();
  } else {
    res.json(['must auth']);
  }
});



/*
 * Resources
 */
app.resource('admin/users', require('./resources/users'));


/**
 * Just say it is all fine.
 */
module.exports = true;
</pre></p>
<p>./seeds.js<br />
<pre class="brush: jscript;">
// https://github.com/marak/Faker.js/
// npm install Faker
var Faker = require('Faker'),
    times = 0,
    id = 0

var self = {
  Company: [ ],
  User: [ ],
  Activity: [ ],
}



// Company: create 3 - 5
id = 1
times = Faker.Helpers.randomNumber(3)+3
for (; times &gt; 0 ; times--) {
  var novo = {
    id: id++,
    name: Faker.Company.companyName(),
  }
  self.Company.push( novo )
  //console.log(&quot;Company&quot;, novo)
};


// Users: create 0 - 8 per company
id = 1
for (var i=0; i &lt; self.Company.length; i++) {
  times = Faker.Helpers.randomNumber(9)
  for (; times &gt; 0 ; times--) {
    var novo = {
      id: id++,
      name: Faker.Name.firstName(),
      company_id: Faker.Helpers.randomize( self.Company ).id,
    }
    self.User.push( novo )
    //console.log(&quot;User&quot;, novo)
  };
};


// Activities: create 0 - 10 per user
var TYPES = ['level_up', 'timeout' ],
    VALUES = ['win', 'fail']
id = 1
for (var i=0; i &lt; self.User.length; i++) {
  times = Faker.Helpers.randomNumber(11)
  for (; times &gt; 0 ; times--) {
    var novo = {
      id: id++,
      type: Faker.Helpers.randomize( TYPES ),
      value: Faker.Helpers.randomize( VALUES ),
      user_id: Faker.Helpers.randomize( self.User ).id,
    }
    self.Activity.push( novo )
    //console.log(&quot;Activity&quot;, novo)
  };
}

module.exports = self

</pre></p>
<p>./resources/users.js<br />
<pre class="brush: jscript;">
exports.index = function(req, res) {
  models.User.findAll().on('success', function(users) {

    res.json(
      users.map(function(user) {
        return user.mapAttributes();
      })
    );
  });
};
</pre></p>
<p>./views/index.jade<br />
<pre class="brush: plain;">
h1= title
p Welcome to #{title}
p Paths we have:
div!= path_list
div .
footer Loggedin? #{ logged }
</pre></p>
<p>./public/auth.html<br />
<pre class="brush: plain;">
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
	&lt;head&gt;
		&lt;meta charset=&quot;utf-8&quot; /&gt;
		&lt;title&gt;auth&lt;/title&gt;
		&lt;link rel='stylesheet' href='/stylesheets/style.css' /&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;div&gt;
			&lt;header&gt;
				&lt;h1&gt;Auth&lt;/h1&gt;
			&lt;/header&gt;
			&lt;nav&gt;
				&lt;p&gt;
					&lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;
				&lt;/p&gt;
			&lt;/nav&gt;
			&lt;div&gt;
				&lt;form action=&quot;/login&quot; method=&quot;post&quot;&gt;
					&lt;label&gt;Username: &lt;input name=&quot;user[username]&quot; type=&quot;text&quot; /&gt;&lt;/label&gt;&lt;/br&gt;
					&lt;label&gt;Password: &lt;input name=&quot;user[password]&quot; type=&quot;password&quot; /&gt;&lt;/label&gt;&lt;/br&gt;
					&lt;button type=&quot;submit&quot;&gt;OK&lt;/button&gt;
				&lt;/form&gt;
			&lt;/div&gt;
			&lt;footer&gt;
				&lt;p&gt;
					Express API
				&lt;/p&gt;
			&lt;/footer&gt;
		&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<h2>
Brief Discussion</h2>
<p>Overall, this post presents a short and extensible way to start a API that requires authentication, via cookie, and returns data in JSON format.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fabianosoriani.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fabianosoriani.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fabianosoriani.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fabianosoriani.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fabianosoriani.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fabianosoriani.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fabianosoriani.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fabianosoriani.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fabianosoriani.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fabianosoriani.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fabianosoriani.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fabianosoriani.wordpress.com/428/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fabianosoriani.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fabianosoriani.wordpress.com/428/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=428&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fabianosoriani.wordpress.com/2011/08/15/express-api-on-node-js-with-mysql-auth/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/922c9fdc02ec0531cd152ca7cadb33bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fabianosoriani</media:title>
		</media:content>
	</item>
		<item>
		<title>A fresh work enviroment for Node.js and Express on Ubuntu 10  in about 30 minutes</title>
		<link>http://fabianosoriani.wordpress.com/2011/08/01/a-fresh-work-enviroment-for-node-js-and-express-on-ubuntu-10-in-about-30-minutes/</link>
		<comments>http://fabianosoriani.wordpress.com/2011/08/01/a-fresh-work-enviroment-for-node-js-and-express-on-ubuntu-10-in-about-30-minutes/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 19:53:02 +0000</pubDate>
		<dc:creator>fabianosoriani</dc:creator>
				<category><![CDATA[js]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[aptana studio]]></category>
		<category><![CDATA[envioronment setup]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://fabianosoriani.wordpress.com/?p=414</guid>
		<description><![CDATA[Hello and welcome. Node.js came to me as likely the smartest choice for web development, as you are constrained at JavaScript for dynamic programming server side (ActionScript and Java, please don&#8217;t cry). Having all String, and Date operations the same as server or client is just a big thing! Also validations come to my mind [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=414&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello and welcome.</p>
<p>Node.js came to me as likely the smartest choice for web development, as you are constrained at JavaScript for dynamic programming server side (ActionScript and Java, please don&#8217;t cry). Having all String, and Date operations the same as server or client is just a big thing! Also validations come to my mind as not-anymore duplicated code. Besides, the concurrency performance seems really nice. (<em>most importantly, <a href="http://www.olympum.com/internet/why-node-js-matters/" target="_blank">people smarter then me</a> thinks the same</em>)</p>
<p><strong>This post intention is to document my efforts under Ubuntu 10.04 to install everything needed from Node.js to the actual work environment.</strong></p>
<p>Lets start by some git and a good working java for Aptana, and some dependencies for Node.js install itself.<br />
<code><br />
sudo aptitude install git-core sun-java6-bin sun-java6-jre sun-java6-plugin sun-java6-jdk python libssl-dev socat curl libev<br />
</code></p>
<p>Now, you should be good to both install version 0.4x as referenced here: <a title="Node.js installation instructions" href="https://github.com/joyent/node/wiki/Installation" target="_blank">https://github.com/joyent/node/wiki/Installation</a> and I also recommend you start dl <a href="http://www.aptana.com/products/studio3/download" target="_blank">Aptana Studio 3</a> this is my IDE of choice for web dev. (as Rails developer)</p>
<p>If you are new to Aptana, I also recommend going to Window &gt; Preferences and choosing a theme(Aptana&gt;Themes) you like, as well as configuring JS to not alert apparent errors(General&gt;Editor&gt;Texte Editor&gt;Errors : uncheck boxes), since it does not know Node.js functions.<br />
<a href="http://fabianosoriani.files.wordpress.com/2011/08/screenshot-web-qq1-app-js-aptana-studio-3.png"><img class="aligncenter size-medium wp-image-420" title="javascript Aptana Studio 3" src="http://fabianosoriani.files.wordpress.com/2011/08/screenshot-web-qq1-app-js-aptana-studio-3.png?w=300&#038;h=223" alt="" width="300" height="223" /></a></p>
<p>Install NPM, which is the best package handler at the moment and all packages to head into web dev, I will explain later on<br />
<code><br />
curl http://npmjs.org/install.sh | sh<br />
npm install jade<br />
npm install less<br />
npm install -g express<br />
npm install -g node-dev<br />
npm install -g node-inspector<br />
</code></p>
<p>About <strong><a title="Express Node.js web framework" href="http://expressjs.com/" target="_blank">Express</a></strong>, you can have noticed, it is close to ruby&#8217;s Sinatra web framework MVC, which is pretty cool, and has a great performance. I recommend some learning from their web-site videos.</p>
<p><a href="http://fabianosoriani.files.wordpress.com/2011/08/node1.png"><img class="aligncenter size-medium wp-image-417" title="express base" src="http://fabianosoriani.files.wordpress.com/2011/08/node1.png?w=300&#038;h=277" alt="" width="300" height="277" /></a></p>
<p>In my machine, AMD Phenom II X4 965, 3.2GB Ram (bla bla) running some intensive apache ab, I got these fantastic results:<br />
<code><br />
ab -n 100000 -c 100 http://127.0.0.1:3000/</code></p>
<p>Document Path: /<br />
Document Length: 11 bytes</p>
<p>Concurrency Level: 100<br />
Time taken for tests: 10.789 seconds<br />
Complete requests: 100000<br />
Failed requests: 0<br />
Write errors: 0<br />
Total transferred: 13200000 bytes<br />
HTML transferred: 1100000 bytes<br />
Requests per second: 9268.48 [#/sec] (mean)<br />
Time per request: 10.789 [ms] (mean)<br />
Time per request: 0.108 [ms] (mean, across all concurrent requests)</p>
<p><strong>Jade and Less</strong> are about the View layer</p>
<p>Now&#8230; node-dev and node-inspector.. <strong>CLASSY STUFF!</strong></p>
<p>If you are used to developing Rails or Sinatra, you are used to have your code auto-reloaded (development-mode or shotgun), <strong>node-dev</strong> accomplishes just that! everytime you make any changes to <em>any file.js</em> from the current folder it will kill and restart your Node app for you; nice!<br />
<a href="http://fabianosoriani.files.wordpress.com/2011/08/asdasd.png"><img class="aligncenter size-medium wp-image-419" title="node-dev" src="http://fabianosoriani.files.wordpress.com/2011/08/asdasd.png?w=300&#038;h=102" alt="" width="300" height="102" /></a></p>
<p>Now, <strong>node-inspector</strong> this it the coolest debug tool I&#8217;ve ever seen! And you can use it along with node-dev with no problem <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<a href="http://twitpic.com/5xu4ie" target="_blank"><img class="aligncenter size-medium wp-image-419" title="node-dev" src="http://twitpic.com/5xu4ie" alt="" width="300" height="102" /></a><br />
You can learn more from then at their <a title="Coolest node.js debug tool ever" href="https://github.com/dannycoates/node-inspector" target="_blank">Github page</a></p>
<p>If you want to develop along with <a href="http://couchdb.apache.org/" target="_blank">CouchDB</a>, you should install it too.</p>
<p><code><br />
sudo aptitude install automake spidermonkey-bin autoconf subversion-tools libtool help2man build-essential erlang erlang-manpages libicu38 libmozjs-dev wget libicu-dev libreadline5-dev checkinstall<br />
sudo aptitude install couchdb<br />
npm install cradle<br />
</code></p>
<p>If couch installed fine, you can see it via <a href="http://127.0.0.1:5984/_utils/index.html" target="_blank">http://127.0.0.1:5984/_utils/index.html</a>. And a daemon is started along with your machine every boot.</p>
<p>About <strong>cradle</strong>, they have a real good <a href="http://cloudhead.io/cradle" target="_blank">documentation at their website</a>, you should start there.</p>
<p>And that&#8217;s it! Due <em>aptitude</em> and <em>npm</em> you can have it all done in about 30 min, heavily depending on your network connection. Good coding! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fabianosoriani.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fabianosoriani.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fabianosoriani.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fabianosoriani.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fabianosoriani.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fabianosoriani.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fabianosoriani.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fabianosoriani.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fabianosoriani.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fabianosoriani.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fabianosoriani.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fabianosoriani.wordpress.com/414/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fabianosoriani.wordpress.com/414/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fabianosoriani.wordpress.com/414/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=414&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fabianosoriani.wordpress.com/2011/08/01/a-fresh-work-enviroment-for-node-js-and-express-on-ubuntu-10-in-about-30-minutes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/922c9fdc02ec0531cd152ca7cadb33bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fabianosoriani</media:title>
		</media:content>

		<media:content url="http://fabianosoriani.files.wordpress.com/2011/08/screenshot-web-qq1-app-js-aptana-studio-3.png?w=300" medium="image">
			<media:title type="html">javascript Aptana Studio 3</media:title>
		</media:content>

		<media:content url="http://fabianosoriani.files.wordpress.com/2011/08/node1.png?w=300" medium="image">
			<media:title type="html">express base</media:title>
		</media:content>

		<media:content url="http://fabianosoriani.files.wordpress.com/2011/08/asdasd.png?w=300" medium="image">
			<media:title type="html">node-dev</media:title>
		</media:content>

		<media:content url="http://twitpic.com/5xu4ie" medium="image">
			<media:title type="html">node-dev</media:title>
		</media:content>
	</item>
		<item>
		<title>Importing data from MongoHQ, and sending to MongoLab (as Heroku plugin)</title>
		<link>http://fabianosoriani.wordpress.com/2011/07/18/importing-data-drom-mongohq-and-sending-as-heroku-plugin/</link>
		<comments>http://fabianosoriani.wordpress.com/2011/07/18/importing-data-drom-mongohq-and-sending-as-heroku-plugin/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 15:09:13 +0000</pubDate>
		<dc:creator>fabianosoriani</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[migrate]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[mongohq]]></category>
		<category><![CDATA[mongolab]]></category>

		<guid isPermaLink="false">http://fabianosoriani.wordpress.com/?p=406</guid>
		<description><![CDATA[Up to present date, I have not found a complete guide about it, so I am assembling it here, but please, have in mind that I am a MongoDB noob What I want to do: - Get all collection I have in MongoHQ, and backup locally - Also, lets dump it into binary - Get [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=406&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Up to present date, I have not found a complete guide about it, so I am assembling it here, but please, have in mind that I am a <strong>MongoDB noob</strong></p>
<p>What I want to do:<br />
- Get all collection I have in MongoHQ, and backup locally<br />
- Also, lets dump it into binary<br />
- Get all collection of documents locally, and transmit to MongoLab (lets say, because they give 200MB of host free <strong>*Please see comments on more insight about this subject</strong> )</p>
<p>To do so, I first got to: <a href="http://www.mongodb.org/display/DOCS/Import+Export+Tools">http://www.mongodb.org/display/DOCS/Import+Export+Tools</a>, but then, they warn it is easier to achieve by: <a href="http://www.mongodb.org/display/DOCS/Copy+Database+Commands command">http://www.mongodb.org/display/DOCS/Copy+Database+Commands command</a>: <em>db.copyDatabase</em></p>
<h3>Step1, backup</h3>
<p>On the folder associated to heroku (where you commit and push your app) run:<br />
<em>heroku config</em></p>
<p>focus on the key:<br />
<em>MONGOHQ_URL =&gt; mongodb://heroku:some_pass@flame.mongohq.com:27021/app9000</em></p>
<p>You can have more info about MongoHQ here <a href="http://devcenter.heroku.com/articles/mongohq" target="_blank">http://devcenter.heroku.com/articles/mongohq</a></p>
<p>So, after figuring out this string, you just log on your local mongo console via: <em>mongo</em></p>
<p>Now, you plan to backup to some db name, as &#8216;my_heroku_app_bckp&#8217;<br />
run: <em>db.copyDatabase( &#8216;app9000&#8242;, &#8216;my_heroku_app_bckp&#8217;, &#8216;flame.mongohq.com:27021/app9000&#8242;, &#8216;heroku&#8217;, &#8216;some_pass&#8217; )</em></p>
<p>And you should get: <em>{ &#8220;ok&#8221; : 1 }</em> <strong>ftw</strong>! If you get some #fail, refer to someone wiser than me, like <a href="http://www.StackOverflow.com" target="_blank">www.StackOverflow.com</a> :L</p>
<p>If all went right now you have you database replicated in your PC, and you can do whatever you want with it. For extra paranoid run: <em>db.some_coll_you_know_has_stuff.count()</em></p>
<h3>STEP 2, dump</h3>
<p>Lets dump all data locally, using:<br />
<em>mongodump -o mongo_bckp -d my_heroku_app_bckp</em></p>
<p>That sould create a folder and the data inside, as bson.</p>
<h3>STEP 3, migrate</h3>
<p>Lets add MongoLab at heroku; follow this guide: http://devcenter.heroku.com/articles/mongolab</p>
<p>All right? Again run: <em>heroku config</em></p>
<p>Now focus on:<br />
MONGOLAB_URI =&gt; mongodb://heroku_app9000:other_pass@dbh22.mongolab.com:27227/heroku_app9000</p>
<p>Lets make a straigth import to them, using:<br />
<em>mongorestore -h dbh22.mongolab.com:27227 -d heroku_app9000 -u heroku_app9000 -p &#8220;mongo_bckp/my_heroku_app_bckp&#8221;</em></p>
<p>Enter the huge password when propted, and if everything ran smooth you will <strong>see many importations</strong> and no #fail</p>
<p>All is left to do is to <strong>switch the DB connection inside your app</strong>.</p>
<p>Now, commit cross your fingers! Check your app, all good? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>* If you get a empty DB, check the database name</p>
<h3>End Notes</h3>
<p>MongoLabs and MongoHQ have different ways of counting and charging for data, in ways that can make a huge difference. For instance, for the same 6,582 doccuments under 1 collection, I may get 2.18Mb in one, while in the other I get 6.91 MB! <em>(see comments)</em></p>
<p>Finally, by a very very <strong>very</strong> loose benchmark, their response has pretty much the same speed, being MongoLabs a tiny bit faster</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fabianosoriani.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fabianosoriani.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fabianosoriani.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fabianosoriani.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fabianosoriani.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fabianosoriani.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fabianosoriani.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fabianosoriani.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fabianosoriani.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fabianosoriani.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fabianosoriani.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fabianosoriani.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fabianosoriani.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fabianosoriani.wordpress.com/406/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=406&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fabianosoriani.wordpress.com/2011/07/18/importing-data-drom-mongohq-and-sending-as-heroku-plugin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/922c9fdc02ec0531cd152ca7cadb33bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fabianosoriani</media:title>
		</media:content>
	</item>
		<item>
		<title>2 jquery animation parallel (or a effect)</title>
		<link>http://fabianosoriani.wordpress.com/2011/06/27/2-jquery-animation-parallel-or-a-effect/</link>
		<comments>http://fabianosoriani.wordpress.com/2011/06/27/2-jquery-animation-parallel-or-a-effect/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 21:51:37 +0000</pubDate>
		<dc:creator>fabianosoriani</dc:creator>
				<category><![CDATA[animation]]></category>
		<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[animate]]></category>
		<category><![CDATA[animate color]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[multiple]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[shake]]></category>

		<guid isPermaLink="false">http://fabianosoriani.wordpress.com/?p=398</guid>
		<description><![CDATA[This post is kinda drafty, but since the Google&#8217;s first page for this were outdated, here we go! When trying running 2 animations (or multiple) side by side (in parallel) at a same element, via JQuery .animate() they run one after another; like they are supposed to do by default, but there is a argument to override;  queue. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=398&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post is kinda drafty, but since the Google&#8217;s first page for this were outdated, here we go!</p>
<p>When trying running 2 animations (or multiple) side by side (in parallel) at a <strong>same</strong> element, via JQuery <em><a href="http://api.jquery.com/animate/" target="_blank">.animate()</a></em> they run one after another; like they are <strong>supposed to do by default,</strong> but there is a argument to override;  <em><strong>queue</strong></em>. In a silly example:</p>
<p><pre class="brush: jscript;">
  j('body').animate({ paddingTop: 100}, 500, function(){ alert('Took half a second!')}).animate({paddingLeft: 100}, {duration: 500, queue:false})
</pre></p>
<p>Here we are animating both in parallel, and the callback <em>alert</em>, run after half a second. (<em>*be careful about callbacks on animations with queue:false, since they don&#8217;t seem to trigger </em>)</p>
<p>In <strong>another example</strong>, fairly more complex (and real <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ), I am using <a href="http://jqueryui.com" target="_blank">JQueryUI</a> for both  shake, and color effects.<br />
The objective is to simulate a <em>div </em>that gets overheated and waves to chill, <em>real fast</em>.</p>
<p><pre class="brush: jscript;">
var pointsE = j('#health_bar .stats')
pointsE.css( {color: 'rgb(255,0,0)' })
        .stop(true)
        .effect('bounce', {times: 5, distance:10, easing: 'easeOutElastic'}, 300 )
        .html('OUCH!')
        .animate({ color: 'rgb(255,255,255)' }, { duration: 500, queue: false})
</pre></p>
<p>Just be aware, that it doesn&#8217;t seen <em>.effect()</em>, supporting <em>queue: false &#8211;it breaks</em>. That&#8217;s why I put it in the <em>.animate()</em><br />
About the <em>.stop(true)</em>, it is just to be sure that the queue is empty before starting the animation (in practice, it is a minor fix for consecutive <em>.effect(&#8216;shake&#8217;)</em>)</p>
<p>&nbsp;</p>
<p>References:<br />
<a href="http://api.jquery.com/animate/" target="_blank">jQuery .animate() API</a><br />
<a href="http://jqueryui.com/demos/animate/" target="_blank">jQueryUI Color</a><br />
<a href="http://docs.jquery.com/UI/Effects/Shake#options" target="_blank">jQueryUi Shake Effect</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fabianosoriani.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fabianosoriani.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fabianosoriani.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fabianosoriani.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fabianosoriani.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fabianosoriani.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fabianosoriani.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fabianosoriani.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fabianosoriani.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fabianosoriani.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fabianosoriani.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fabianosoriani.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fabianosoriani.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fabianosoriani.wordpress.com/398/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=398&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fabianosoriani.wordpress.com/2011/06/27/2-jquery-animation-parallel-or-a-effect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/922c9fdc02ec0531cd152ca7cadb33bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fabianosoriani</media:title>
		</media:content>
	</item>
		<item>
		<title>Very simple invisible JavaScript &amp; Rails captcha</title>
		<link>http://fabianosoriani.wordpress.com/2011/06/15/very-simple-invisible-javascript-rails-captcha/</link>
		<comments>http://fabianosoriani.wordpress.com/2011/06/15/very-simple-invisible-javascript-rails-captcha/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 15:16:00 +0000</pubDate>
		<dc:creator>fabianosoriani</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[technique]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[secure]]></category>
		<category><![CDATA[side]]></category>
		<category><![CDATA[simple]]></category>

		<guid isPermaLink="false">http://fabianosoriani.wordpress.com/?p=389</guid>
		<description><![CDATA[Hello! Visual captchas are far from being desirable on most public sites, but spam is even less desirable, mainly in contact forms. This solution I am implementing is dead simple, but also, weaker than reCaptcha. snippet: Put this in the application_controller.rb Put this in a javascript that is executed on every public page, typically, application.js [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=389&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello!</p>
<p>Visual captchas are far from being desirable on most public sites, but spam is even less desirable, mainly in contact forms. This solution I am implementing is dead simple, but also, weaker than <a href="http://www.google.com/recaptcha">reCaptcha</a>.</p>
<p style="text-align:center;"><a href="http://fabianosoriani.files.wordpress.com/2011/06/captcha_012.jpg"><img class="aligncenter size-medium wp-image-395" title="Captcha_012" src="http://fabianosoriani.files.wordpress.com/2011/06/captcha_012.jpg?w=300&#038;h=119" alt="" width="300" height="119" /></a></p>
<p><strong>snippet:</strong></p>
<p>Put this in the <em>application_controller.rb</em></p>
<p><pre class="brush: ruby;">
  before_filter :form_spam_control

  private

  def form_spam_control
    if request.post? || request.put?
      unless params['agent_smith'] == 'Mr Anderson, welcome back'
        render :text =&gt; &quot;Please make sure cookies and js are enabled&quot;
        return false
      end
    end
  end
</pre></p>
<p>Put this in a javascript that is executed on every public page, typically, <em>application.js</em> (*does require jQuery loaded)</p>
<p><pre class="brush: jscript;">
$(document).ready( function(){
  $('form').append( j('&lt;input/&gt;', {
    type: 'hidden',
    id: 'agent_smith',
    name: 'agent_smith',
    value: 'Mr Anderson, welcome back'
  }) )
})
//UPDATE! in order to support AJAX without extra params add:
j('body').ajaxSend(function(a,b,c){ if( c.type == 'POST' || c.type == 'PUT' ) c.data = c.data.length &gt; 0 ? c.data+'&amp;agent_smith=Mr+Anderson%2C+welcome+back' : 'agent_smith=Mr+Anderson%2C+welcome+back'})
</pre></p>
<p><strong>Discussion:</strong><br />
This is <strong>totally invisible and harass-free</strong> for the user.<br />
I am based on the principle that spam <strong>crawlers does not run JavaScript</strong>, which may not be true for all of them. Still this will deny some crawlers that may be considered good, such as <a href="https://github.com/tenderlove/mechanize" target="_blank">Mechanize</a>.<br />
This technique can be <strong>easily ported</strong> to other backend languages, such as PHP, ASP, C#, Java, since it only requires a parameter filter on POSTs and PUTs<br />
If the attacker focus your website, this will be <strong>easily</strong> broken.<br />
If the user has <strong>JavaScript disabled</strong>, he can&#8217;t post, but this is a normal <strong>drawback</strong> on some captchas.<br />
* the part of the error message including &#8216;cookies&#8217; is just a disguise =)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fabianosoriani.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fabianosoriani.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fabianosoriani.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fabianosoriani.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fabianosoriani.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fabianosoriani.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fabianosoriani.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fabianosoriani.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fabianosoriani.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fabianosoriani.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fabianosoriani.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fabianosoriani.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fabianosoriani.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fabianosoriani.wordpress.com/389/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=389&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fabianosoriani.wordpress.com/2011/06/15/very-simple-invisible-javascript-rails-captcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/922c9fdc02ec0531cd152ca7cadb33bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fabianosoriani</media:title>
		</media:content>

		<media:content url="http://fabianosoriani.files.wordpress.com/2011/06/captcha_012.jpg?w=300" medium="image">
			<media:title type="html">Captcha_012</media:title>
		</media:content>
	</item>
		<item>
		<title>accepts_nested_attributes_for 3.0.5 :reject_if still have gotchas</title>
		<link>http://fabianosoriani.wordpress.com/2011/06/07/accepts_nested_attributes_for-3-0-5-reject_if-still-have-gotchas/</link>
		<comments>http://fabianosoriani.wordpress.com/2011/06/07/accepts_nested_attributes_for-3-0-5-reject_if-still-have-gotchas/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 20:33:16 +0000</pubDate>
		<dc:creator>fabianosoriani</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[technique]]></category>
		<category><![CDATA[tecnica]]></category>
		<category><![CDATA[:reject_if]]></category>
		<category><![CDATA[Rails associations]]></category>

		<guid isPermaLink="false">http://fabianosoriani.wordpress.com/?p=381</guid>
		<description><![CDATA[Hey Nested forms are nasty, but many times, a necessary evil Rails tackled it since version 2.3x, when added the ActiveRecord method accepts_nested_attributes_for, main ref here. For its complexity, I believe, it is still hard to master it, and still bugs may happen; this was my lesson. Ryan Bates, (a ruby hero) has made some screencasts [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=381&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey</p>
<p>Nested forms are nasty, but many times, a necessary evil <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Rails tackled it since version 2.3x, when added the ActiveRecord method <em><a href="http://apidock.com/rails/ActiveRecord/NestedAttributes/ClassMethods/accepts_nested_attributes_for" target="_blank">accepts_nested_attributes_for</a>, main <a href="http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html" target="_blank">ref here</a>.</em> For its complexity, I believe, it is still hard to master it, and still bugs may happen; this was my lesson.</p>
<p><a href="https://twitter.com/#!/rbates" target="_blank">Ryan Bates</a>, (a ruby hero) has made some screencasts from it, watch <a href="http://railscasts.com/episodes/196" target="_blank">part1</a>, <a href="http://railscasts.com/episodes/197-nested-model-form-part-2" target="_blank">part2</a>. Soon after, he and some buds, made a gem for it, targeting <strong>Adding and Removing via JavaScript</strong>, without harassment. You can <a href="https://github.com/ryanb/nested_form" target="_blank">find on GitHub</a>, along with the necessary doc.</p>
<p>So, using the gem or not, still there are things to cover over this methods params;</p>
<p>From what I could observe, <strong>:reject_if</strong>, does not work for &#8216;rejecting&#8217; a existing record, i.e.: those that have ID. <strong>But</strong>, it is called for those too! &#8211; In this topic, (what may be a bug) is that, if the record gets rejected, it does not get updated (it does not go through it&#8217;s model&#8217;s validations either).</p>
<p>The solution I found was <strong>not using <em>:reject_if</em></strong>,  instead, validating whatever I wanted on the nested Model in order to keep dry.</p>
<p>For this scenario, consider the following setup (rails v3.0.5)</p>
<p><pre class="brush: ruby;">
class A &lt; ActiveRecord::Base
 has_many :bs
 accepts_nested_attributes_for :bs,
                               :allow_destroy =&gt; true
                               #no use. :reject_if =&gt; :combo_elem_zero?

 # wont use this function at all
 def combo_elem_zero?( att )
  #puts(atribs.to_yaml)
  #att['_destroy'] = '1' # wont work here

  # only useful for new records
  if atribs['id'].blank? &amp;&amp; att[:some_atrib].to_f &lt; something_blah
   true
  else
   false
  end
 end
end

class B &lt; ActiveRecord::Base
 belongs_to :a

 validate :destruction_update # works both for create/update

 def destruction_update
  if self.some_atrib.to_f &lt; something_blah
   self.mark_for_destruction
  end
 end

end
</pre></p>
<p>If on the other hand, you only need to check on the nested new records, :reject_if may do the job.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fabianosoriani.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fabianosoriani.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fabianosoriani.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fabianosoriani.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fabianosoriani.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fabianosoriani.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fabianosoriani.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fabianosoriani.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fabianosoriani.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fabianosoriani.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fabianosoriani.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fabianosoriani.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fabianosoriani.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fabianosoriani.wordpress.com/381/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=381&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fabianosoriani.wordpress.com/2011/06/07/accepts_nested_attributes_for-3-0-5-reject_if-still-have-gotchas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/922c9fdc02ec0531cd152ca7cadb33bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fabianosoriani</media:title>
		</media:content>
	</item>
		<item>
		<title>Leaving Google AppEngine for Rails and going Heroku</title>
		<link>http://fabianosoriani.wordpress.com/2011/06/02/leaving-google-appengine-for-rails-and-going-heroku/</link>
		<comments>http://fabianosoriani.wordpress.com/2011/06/02/leaving-google-appengine-for-rails-and-going-heroku/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 01:19:41 +0000</pubDate>
		<dc:creator>fabianosoriani</dc:creator>
				<category><![CDATA[Desenvolvimento]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[gae]]></category>
		<category><![CDATA[go]]></category>
		<category><![CDATA[google appengine]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[linode]]></category>
		<category><![CDATA[scalable]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://fabianosoriani.wordpress.com/?p=373</guid>
		<description><![CDATA[Hey all Introduction (goal) I&#8217;ve been projecting for sometime my tag based search engine for sometime now. And while it is something relatively simple, query performance still have a great impact on that matter. It should be a project, with roots in gamification; and I choose Ruby on Rails, and not GAE&#8217;s Python or Java framework due I do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=373&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey all</p>
<h3>Introduction (goal)</h3>
<p>I&#8217;ve been projecting for sometime my tag based search engine for sometime now. And while it is something relatively simple, query performance still have a great impact on that matter.</p>
<p><a href="http://fabianosoriani.files.wordpress.com/2011/06/ggg.png"><img class="aligncenter size-medium wp-image-374" title="ggg" src="http://fabianosoriani.files.wordpress.com/2011/06/ggg.png?w=300&#038;h=57" alt="" width="300" height="57" /></a></p>
<p>It should be a project, with roots in <a href="http://en.wikipedia.org/wiki/Gamification" target="_blank">gamification</a>; and I choose Ruby on Rails, and not GAE&#8217;s Python or Java framework due I do not want to be stuck in a hosting platform for whatsoever reason.</p>
<h3>AppEngine, what&#8217;s great?</h3>
<p>AppEngine has many, <a href="http://code.google.com/appengine/whyappengine.html">cool things</a>. Those including some that should make my life a lot simpler</p>
<ul>
<li>Generous elastic <a href="http://code.google.com/appengine/docs/quotas.html">free quota</a> for all stuff I needed</li>
<li>BigTable, with stable performance (it is suppost to perform so well with thousand entry through a million )[<a title="this does not prove a thing ;)" href="http://gaejava.appspot.com/" target="_blank">demo</a>]</li>
<li>They have the <a href="http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html">type List</a> in DataStore, witch is exactly what I need to make a good queries</li>
<li>Should scale seamless, no pain</li>
<li>Have a great panel, that allows easy data manipulation, and great reports.</li>
</ul>
<div>Besides, it is clear that Google is investing heavy on that product, which is a huge plus.</div>
<h3>AppEngine, what is bad, for Rails?</h3>
<p>After building <a href="http://fabianosoriani.wordpress.com/2010/12/11/creating-a-rails-2-3-8-on-google-app-engine/" target="_blank">my hello world on GAE</a>, things looked awesome; a proof of concept right there! Rails 2.3.8 running smooth.</p>
<p><img class="aligncenter" title="jruby gae" src="http://code.google.com/p/appengine-jruby/logo?cct=1288280276" alt="" width="72" height="55" /></p>
<p>But then it began.. migration, data backup, gems like omniauth, sorta elaborated queries.. where to look for all those stuff? Rubygems system is disabled, and no doc is easily found, if any doc is around. So I got to go build conceptual proofs  for all those things?</p>
<p>So it happens, that their <a href="http://code.google.com/p/appengine-jruby/wiki/RunningRails" target="_blank">landing page for Rails</a>, is stale for years; a big turn down! And still it hard to find some decent support for Rails (@woodie <a href="https://gist.github.com/825451" target="_blank">does help</a> in docs, but can&#8217;t be accepted as the only source)</p>
<p>Recently they&#8217;ve announced a they are going beta with the <a href="http://blog.golang.org/2011/05/go-and-google-app-engine.html" target="_blank">Go language</a>;  what sounds really great, still in practice it mean Ruby won&#8217;t be getting support (if ever) in a very long while.</p>
<h3>So, Heroku and why</h3>
<p>For being a Computer Scientist . I am a big fan of Google capacity of execution and performance for years, but the downsides have been just too great too keep on. So let&#8217;s check <a href="http://www.heroku.com/" target="_blank">Heroku</a>.</p>
<ul>
<li>I had prior experience there</li>
<li>Heroku offers Rails out of the box, working with Omniauth.</li>
<li>They also have a free quota to try (1 dyno ~ 10-50req/sec)</li>
<li>240MB from MongoLab (*important)</li>
<li>Nice <a href="http://addons.heroku.com/" target="_blank">features</a></li>
<li>Robust and elastic scalable (dyno charge per hour)</li>
</ul>
<h3>Final Considerations</h3>
<p>The pro in this scenario, is that they take Rails with all gems I could need, no harass there, things just work! And if I grow tired of then, I can just switch host <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Why not a <strong>VPS</strong>? I&#8217;ve had <a href="http://linode.com" target="_blank">Linode</a> for sometime now, they have some great management panel; but the concern about the O.S. security and app scalability is considerable.. Sure is cool to config all my features from the ground; but considering business this kind of setup must be taken professionally.</p>
<p>Google AppEngine, or <strong>GAE, is a great platform,</strong> for their supported languages. If I were to host there, I would definitely <a title="Go programming Language" href="http://golang.org/" target="_blank">learn Go</a>, for all great features intended, and the attention Google is giving it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fabianosoriani.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fabianosoriani.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fabianosoriani.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fabianosoriani.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fabianosoriani.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fabianosoriani.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fabianosoriani.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fabianosoriani.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fabianosoriani.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fabianosoriani.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fabianosoriani.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fabianosoriani.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fabianosoriani.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fabianosoriani.wordpress.com/373/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fabianosoriani.wordpress.com&amp;blog=3656200&amp;post=373&amp;subd=fabianosoriani&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fabianosoriani.wordpress.com/2011/06/02/leaving-google-appengine-for-rails-and-going-heroku/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/922c9fdc02ec0531cd152ca7cadb33bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fabianosoriani</media:title>
		</media:content>

		<media:content url="http://fabianosoriani.files.wordpress.com/2011/06/ggg.png?w=300" medium="image">
			<media:title type="html">ggg</media:title>
		</media:content>

		<media:content url="http://code.google.com/p/appengine-jruby/logo?cct=1288280276" medium="image">
			<media:title type="html">jruby gae</media:title>
		</media:content>
	</item>
	</channel>
</rss>
