<?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"
	>

<channel>
	<title>for i in infinity</title>
	<atom:link href="http://www.anup.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anup.info</link>
	<description>Ruby on Rails Developer, London</description>
	<pubDate>Mon, 12 Jul 2010 22:49:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>MooTools: Class Methods and Inheritance</title>
		<link>http://www.anup.info/2010/07/12/mootools-class-methods-and-inheritance/</link>
		<comments>http://www.anup.info/2010/07/12/mootools-class-methods-and-inheritance/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 22:49:59 +0000</pubDate>
		<dc:creator>anup.narkhede</dc:creator>
		
		<category><![CDATA[Code Recipes]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[MooTools]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.anup.info/?p=172</guid>
		<description><![CDATA[In my last project, I enjoyed scripting using mootools and started exploring it more deeply. One of my extensive use was to define UI elements&#8217; functionality in classes and then create multiple instances for re-usability. 
Mootools makes use of Javascript&#8217;s native prototype model for inheritance. To extend a base functionality into sub class, mootools provide [...]]]></description>
			<content:encoded><![CDATA[<p>In my last project, I enjoyed scripting using mootools and started exploring it more deeply. One of my extensive use was to define UI elements&#8217; functionality in classes and then create multiple instances for re-usability. </p>
<p>Mootools makes use of Javascript&#8217;s native prototype model for inheritance. To extend a base functionality into sub class, mootools provide &#8216;Extends&#8217; method. However, if you have class methods in your base model, Extends is insufficient to get them into the sub classes. After some research, I managed to solve this by using Class Mutators and overriding the Mootools &#8216;Extends&#8217; to take care of class methods inheritance.</p>
<p>First of all, we need to define a ClassMethods mutator. Mutators belong to a class, not to their instances and they are called only when we define a new Class.</p>
<textarea name="code" class="javascript:nocontrols" cols="60" rows="10">
Class.Mutators.ClassMethods = function(methods){
  this.__classMethods = $extend(this.__classMethods || {}, methods);
  this.extend(methods);
};
</textarea>
<p>Next, we need to redefine Mootools Extends mutator:</p>
<textarea name="code" class="javascript:nocontrols" cols="60" rows="10">
Class.Mutators.Extends = function(parent){
  this.parent = parent;
  this.prototype = Class.instantiate(parent);

  this.implement('parent', function(){
    var name = this.caller._name, previous = this.caller._owner.parent.prototype[name];
    if (!previous) throw new Error('The method "' + name + '" has no parent.');
    return previous.apply(this, arguments);
  }.protect());

  this.extend(parent.__classMethods);
};
</textarea>
<p>Check out the example below:</p>
<textarea name="code" class="javascript:nocontrols" cols="60" rows="10">
var Foo = new Class({
  ClassMethods: {
    hello: function(){
      alert('hello from foo');
    }
  },
  
  size: function(){
    alert('foo instance method called');
  }
});

var Bar = new Class({
  Extends: Foo,
  
  ClassMethods: {
    hola: function(){
      alert('hola from bar');
    }
  }
});

var f = new Foo();
var b = new Bar();


// ClassMethods
Foo.hello() => alerts "hello from foo"
Bar.hello() => alerts "hello from foo"
Bar.hola()  => alerts "hola from bar"

// Instance methods
f.size() => 'foo instance method called'
b.size() => 'foo instance method called'

// Call ClassMethods from instances
f.constructor.hello() => "hello from foo"
b.constructor.hello() => "hello from foo"
</textarea>
<p>You can see the above code working here. <a href=" http://jsfiddle.net/rZvJE/11/"><br />
http://jsfiddle.net/rZvJE/11/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anup.info/2010/07/12/mootools-class-methods-and-inheritance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Daily Blockers #2</title>
		<link>http://www.anup.info/2010/03/02/daily-blockers-2/</link>
		<comments>http://www.anup.info/2010/03/02/daily-blockers-2/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 17:31:53 +0000</pubDate>
		<dc:creator>anup.narkhede</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[blockers]]></category>

		<guid isPermaLink="false">http://www.anup.info/?p=169</guid>
		<description><![CDATA[Problem:

/Users/railsbob/multiruby/install/1.8.7-p249/lib/ruby/gems/1.8/gems/
activesupport-2.3.5/lib/active_support/multibyte/unicode_database.rb:37:
[BUG] Segmentation fault
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin9.6.0]

Solution:
Somehow my activesupport-2.3.5/lib/active_support/values/unicode_tables.dat was corrupted. Reinstalling activesupport gem fixed the issue.
]]></description>
			<content:encoded><![CDATA[<p>Problem:</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
/Users/railsbob/multiruby/install/1.8.7-p249/lib/ruby/gems/1.8/gems/
activesupport-2.3.5/lib/active_support/multibyte/unicode_database.rb:37:
[BUG] Segmentation fault
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin9.6.0]
</textarea>
<p>Solution:<br />
Somehow my activesupport-2.3.5/lib/active_support/values/unicode_tables.dat was corrupted. Reinstalling activesupport gem fixed the issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anup.info/2010/03/02/daily-blockers-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rails 3.0: Mount Multiple Apps as Engines</title>
		<link>http://www.anup.info/2010/02/21/rails-30-mount-multiple-apps-as-engines/</link>
		<comments>http://www.anup.info/2010/02/21/rails-30-mount-multiple-apps-as-engines/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 01:31:06 +0000</pubDate>
		<dc:creator>anup.narkhede</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.anup.info/?p=155</guid>
		<description><![CDATA[Since last week I have been working on upgrading a major project from Rails 2.3.5 to Rails 3.0.0.beta and also on moving other projects to use the latest version of bundler. Getting all to work was not easy, but this gave me a chance to look into the rails initialization code in detail. Based on [...]]]></description>
			<content:encoded><![CDATA[<p>Since last week I have been working on upgrading a major project from Rails 2.3.5 to Rails 3.0.0.beta and also on moving other projects to use the latest version of bundler. Getting all to work was not easy, but this gave me a chance to look into the rails initialization code in detail. Based on this adventure, I tried to convert some plugins into gems and also explored ways of mounting a Rails 3.0 application into another. Here is a very basic example of how you can mount a reusable Rails 3.0 application into a container application. This might not be the best approach for developing multi apps, but it surely offers some fun :).</p>
<p>My setup is Rails 3.0.0.beta with ruby 1.9.1 for this example. If the steps sound confusing, you can follow the example code here <a href="http://github.com/railsbob/MyApp">http://github.com/railsbob/MyApp</a>.</p>
<p>First of all, lets create a generic, reusable application. My reusable &#8216;login application&#8217; with one controller is called as &#8216;Saas&#8217;.</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
# Saas/controllers/saas/sessions_controller.rb
module Saas
  class SessionsController < ApplicationController
    def new
      render :text => 'Hi from SessionsController'
    end
  end
end
</textarea>
<p>To allow sharing of this application by others, we need to wrap it as a Rails::Engine. To do so, add a file named &#8216;engine.rb&#8217; to config folder.</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
# Saas/config/engine.rb
module Saas
  class Engine < Rails::Engine
    engine_name :saas
  end
end
</textarea>
<p>Create a &#8217;saas.rb&#8217; in lib folder which requires this engine.rb. This is required, as we want to load the application as Saas::Engine instead of Saas::Application.</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
# Saas/lib/saas.rb
module Saas
  require File.expand_path('../../config/engine', __FILE__)
end
</textarea>
<p>Lets create a container app which mounts the Saas Application.</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
rails MyApp
</textarea>
<p><strong>To mount it</strong>, copy the Saas application into lib of MyApp.</p>
<p>Saas application&#8217;s routes.rb should be modified to replace Saas::Application by Rails::Application. Also, to keep things modular, add a namespace to the routes.</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
# MyApp/lib/saas/config/routes.rb
Rails::Application.routes.draw do |map|
  namespace :saas do
    resources :sessions
  end
end
</textarea>
<p>The next step is to hook Saas app into the initializer process of MyApp. There are many ways to do it, but we will follow the bundler approach.</p>
<p>In MyApp/Gemfile, require the saas application from lib directory as a gem.</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
gem 'saas', :require => 'saas', :path => 'lib/saas'
</textarea>
<p>At this stage, bundler complains about missing version for saas as it is expecting a gem. So lets add a saas.gemspec at MyApp/lib/saas/saas.gemspec with basic information.</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
Gem::Specification.new do |s|
  s.platform    = Gem::Platform::RUBY
  s.name        = 'saas'
  s.version     = '0.1'
  s.description = 'A generic modular application.'
  s.required_ruby_version = '>= 1.8.7'
  s.author        = 'Anup Narkhede'
  s.require_path  = 'lib'
end
</textarea>
<p>Start the server from the container app and if you go to /saas/sessions you should see the text &#8216;Hi from SessionsController&#8217;. </p>
<p>Note that even if the Saas application was modified to be an engine, it still works as a standalone application when run from its root.<br />
The example code discussed above is available at <a href="http://github.com/railsbob/MyApp">http://github.com/railsbob/MyApp</a>.<br />
.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anup.info/2010/02/21/rails-30-mount-multiple-apps-as-engines/feed/</wfw:commentRss>
		</item>
		<item>
		<title>LRUG (Feb 2010)</title>
		<link>http://www.anup.info/2010/02/11/lrug-feb-2010/</link>
		<comments>http://www.anup.info/2010/02/11/lrug-feb-2010/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 16:26:34 +0000</pubDate>
		<dc:creator>anup.narkhede</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.anup.info/?p=153</guid>
		<description><![CDATA[These are the slides of my presentation at LRUG lightening talks 2010. The talk was about a brief introduction of birdpie.com.
Birdpie
View more presentations from anupnarkhede.

]]></description>
			<content:encoded><![CDATA[<p>These are the slides of my presentation at LRUG lightening talks 2010. The talk was about a brief introduction of <a href="http://www.birdpie.com">birdpie.com</a>.</p>
<div style="width:425px;text-align:left" id="__ss_3128322"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/anupnarkhede/birdpie" title="Birdpie">Birdpie</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=lrugbirdpie2-100210175857-phpapp02&#038;stripped_title=birdpie" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=lrugbirdpie2-100210175857-phpapp02&#038;stripped_title=birdpie" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/anupnarkhede">anupnarkhede</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.anup.info/2010/02/11/lrug-feb-2010/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Continuous Authority and repeated transactions using SagePay Gateway</title>
		<link>http://www.anup.info/2010/02/04/continuous-authority-and-repeated-transactions-using-sagepay-gateway/</link>
		<comments>http://www.anup.info/2010/02/04/continuous-authority-and-repeated-transactions-using-sagepay-gateway/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 00:02:19 +0000</pubDate>
		<dc:creator>anup.narkhede</dc:creator>
		
		<category><![CDATA[Code Recipes]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.anup.info/?p=144</guid>
		<description><![CDATA[SagePay allows us to process repeated capture transactions against a successful payment authorization. You can get more information about the introduction and instructions for obtaining a Continuous Authority Internet Merchant Number here.
This example makes use of a forked version of ActiveMerchant and SagePay Simulator environment. Please refer to the previous article for setup instructions.
Setup:
Make sure [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sagepay.com/">SagePay</a> allows us to process repeated capture transactions against a successful payment authorization. You can get more information about the introduction and instructions for obtaining a Continuous Authority Internet Merchant Number <a href="http://www.sagepay.com/developers/industry_knowledge/continuous_info.asp">here</a>.</p>
<p>This example makes use of a forked version of <a href="http://github.com/dynamic50/active_merchant">ActiveMerchant</a> and <a href="https://test.sagepay.com/simulator/">SagePay Simulator</a> environment. Please refer to the previous<a href="http://www.anup.info/2009/12/25/3d-secure-transactions-using-sagepay-gateway-and-activemerchant/"> article</a> for setup instructions.</p>
<p><strong>Setup:</strong></p>
<p>Make sure to check &#8216;Continuous Authority&#8217; in the simulator account settings.</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
ActiveMerchant::Billing::Base.mode = :test  
ActiveMerchant::Billing::SagePayGateway.simulate = true

credit_card = ActiveMerchant::Billing::CreditCard.new(
:first_name         => 'Bob',
:last_name          => 'Bobsen',
:number             => '4111111111111111',
:month              => '8',
:year               => '2012',
:verification_value => '123',
:type               => 'Visa'
)
</textarea>
<p><strong>Case 1: A non 3D Authorized Transaction</strong></p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
gateway = ActiveMerchant::Billing::SagePayGateway.new({ :login => LOGIN, 
:password => PASSWORD, :enable_3d_secure => true })

response = gateway.authorize(1000, credit_card, :order_id => '00001')
</textarea>
<p>response.authorization shows a value simiar to:<br />
00001;{E5AC4385-06F8-40DD-8486-22EFB23768AE};9030;03FQG5AJA6;authorization</p>
<p>Capture the Payment</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
gateway.capture(1000, r.authorization)
=> {"Status" => "OK"}
</textarea>
<p>Repeat the transaction using previous authorization reference.</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
gateway.repeat(1000, r.authorization, :order_id => '00002')
=> { "Status" => "OK", "StatusDetail" => "The transaction was REPEATed successfully"}
</textarea>
<p><strong>Case 2: 3D Authorized transaction</strong></p>
<p>Follow the steps 1-3 for 3D Secure Payment Transaction as shown in the previous article. You&#8217;ll notice that the authorization returned by a three_d_complete process is incomplete and it looks something like &#8220;;{FB448BBF-CB72-414A-B293-316004162EEB};6598;OUWEBUCWL3;three_d_complete&#8221;<br />
Prepend the order_id used in step 1 to this authorization reference so that it matches following format:</p>
<p>three_d_auth_reference = &#8220;00003;{FB448BBF-CB72-414A-B293-316004162EEB};6598;OUWEBUCWL3;three_d_complete&#8221;</p>
<p>Where &#8220;00003&#8243; is the order_id used for authorization in step 1.</p>
<p>Capture this 3D Authorized payment for the first time by calling:</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
gateway.capture(1000, three_d_auth_reference)
=> { "Status"=>"OK", "StatusDetail"=> "The transaction was RELEASEed successfully." }
</textarea>
<p>This transaction can be repeated by using the previous successful authorization (three_d_auth_reference) with a new order_id.</p>
<textarea name="code" class="ruby:nocontrols" cols="60" rows="10">
gateway.repeat(1000, three_d_auth_reference, :order_id => '00004')
=> { "Status"=>"OK", "StatusDetail"=> "The transaction was REPEATed successfully." }
</textarea>
]]></content:encoded>
			<wfw:commentRss>http://www.anup.info/2010/02/04/continuous-authority-and-repeated-transactions-using-sagepay-gateway/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.681 seconds -->
