Skip to content

Instantly share code, notes, and snippets.

View sivabudh's full-sized avatar

Sivabudh Umpudh sivabudh

View GitHub Profile
@sivabudh
sivabudh / PaypalExpressController.rb
Created December 16, 2011 16:00
PaypalExpressController#purchase
class PaypalExpressController < ApplicationController
# ... everything else was covered in the previous blog
def purchase
if params[:token].nil? or params[:payer_id].nil?
redirect_to home_url, :notice => "Sorry! Something went wrong with the Paypal purchase. Please try again later."
return
end
total_as_cents, purchase_params = get_purchase_params @cart, request, params
@sivabudh
sivabudh / routes.rb
Created December 16, 2011 16:06
Second addition to routes.rb
get "paypal_express/review"
@sivabudh
sivabudh / routes.rb
Created December 16, 2011 16:10
Third addition to routes.rb
get "paypal_express/purchase"
@sivabudh
sivabudh / paypal_express_helper.rb
Created December 16, 2011 16:20
PaypalExpressHelper#get_purchase_params
module PaypalExpressHelper
# ... other methods were implemented in the previous blog posts
def get_totals(cart)
# implemented in the previous blog posts
end
def to_cents(total)
# implemented in the previous blog posts
end
@sivabudh
sivabudh / blah.coffee
Created December 19, 2011 19:49
script to move elements
list = $('#answers')
first = $(list.children()[0])
second = $(list.children()[1])
top = first.offset().top
bottom = second.offset().top
offsetDiff = bottom - top
dragDistance = offsetDiff+1
console.log dragDistance
@sivabudh
sivabudh / gist:2699577
Created May 15, 2012 06:28
Level 3: Challenge 1
<% zombie = Zombie.first %>
<h1><%= zombie.name %></h1>
<p>
<%= truncate zombie.graveyard, :length => 10 %>
</p>
@sivabudh
sivabudh / gist:2699589
Created May 15, 2012 06:33
Level 3: Challenge 2
<% zombie = Zombie.first %>
<p>
<%= link_to zombie.name, zombie, :class=>"bloody" %>
</p>
@sivabudh
sivabudh / gist:2699639
Created May 15, 2012 06:49
Level 3: Challenge 5
<% zombies = Zombie.all %>
<ul>
<% zombies.each do |zombie| %>
<li>
<%= link_to zombie.name, edit_zombie_path(zombie) %>
</li>
<% end %>
</ul>
@sivabudh
sivabudh / gist:2760616
Created May 21, 2012 05:02
Grandfather Clock Ruby solution
def clock(&block)
(Time.now.hour % 12 + 1).times do
block.call
end
end
@sivabudh
sivabudh / scheduler.rb
Created June 26, 2012 08:49
Implementation of the implementation we talked about yesterday.
require 'chronic'
class Scheduler
def self.process(params)
raise 'start_date must be supplied' if params[:start_date].nil?
raise 'end_date must be supplied' if params[:end_date].nil?
raise 'occurs_on must be supplied' if params[:occurs_on].nil?
start_date = DateTime.parse params[:start_date]
end_date = DateTime.parse params[:end_date]