Skip to content

Instantly share code, notes, and snippets.

View bparanj's full-sized avatar

Bala Paranj bparanj

View GitHub Profile
@bparanj
bparanj / new.html.erb
Created November 26, 2014 08:57
Stripe API error
<form action="create" method="POST" id="payment-form">
<span class="payment-errors">
<noscript>JavaScript is not enabled and is required for this form. First enable it in your web browser settings.</noscript>
</div>
</span>
<% if @error_message %>
<%= @error_message %>
<% end %>
<%= hidden_field_tag :authenticity_token, form_authenticity_token -%>
require "rubygems"
require "rack"
require "thin"
cgi_inspector = lambda do |env|
[200, {}, ["Your request:
http method is #{env['REQUEST_METHOD']}
path is #{env['PATH_INFO']}
params is #{env['QUERY_STRING']}
@bparanj
bparanj / wait_until.rb
Created December 12, 2015 05:55 — forked from metaskills/wait_until.rb
Never sleep() using Capybara!
# Have you ever had to sleep() in Capybara-WebKit to wait for AJAX and/or CSS animations?
describe 'Modal' do
should 'display login errors' do
visit root_path
click_link 'My HomeMarks'
within '#login_area' do
fill_in 'email', with: 'will@not.work'
fill_in 'password', with: 'test'
@bparanj
bparanj / separate.rb
Created April 21, 2016 18:19
How to separate business logic from exception handling
def run_with_exception_handling
begin
puts '1'
yield
puts '2'
rescue Exception
puts 'Exception thrown'
end
end
def run_with_exception_handling
begin
puts '1'
v = yield
puts v
rescue Exception
puts 'Exception thrown'
end
end
last_name first_name date_of_birth email
Doe John 1982/10/08 john.doe@foobar.com
Ann Mary 1975/09/15 mary.ann@foobar.com
require 'json'
class Transformer
def initialize(string)
@string = string
end
def transformed_string(type)
if type == :json
JSON.parse(@string)
1.upto(100) do |i|
if i % 3 == 0 && i % 5 == 0
puts 'FizzBuzz'
elsif i % 3 == 0
puts 'Fizz'
elsif i % 5 == 0
puts 'Buzz'
else
puts i
end
@bparanj
bparanj / delegate_matcher.rb
Created November 3, 2015 23:55 — forked from txus/delegate_matcher.rb
RSpec matcher for delegations
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:month).to(:created_at) }
# it { should delegate(:year).to(:created_at) }
# end
@bparanj
bparanj / while.rb
Created March 30, 2017 06:49
Ruby Object Model Exercise #2
sum = 0
i = 1
while i < 5
sum += i
i += 1
end
p sum