This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default 'bar'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/Code/playground/rails-3-2-stable $ cat app/models/person.rb | |
class Person | |
attr_accessor :abc | |
end | |
~/Code/playground/rails-3-2-stable $ cat app/models/story.rb | |
class Story < ActiveRecord::Base | |
attr_accessor :abc | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
merchant_id = 'XXXXXXXXXXXXXXXXXXX' | |
merchant_hash_key = 'XXXXXXXXXXXXXXXXXXX' | |
# implemetation for generating form | |
payment_service_for @order.id, merchant_id, \ | |
merchant_hash_key: merchant_hash_key, | |
service: :veritrans, | |
amount: @order.total_amount, | |
currency: 'IDR', | |
html: {:id => 'payment-form' , :authenticity_token => false } do |service| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mechanize' | |
require 'nokogiri' | |
require 'active_support/all' | |
class SaadAlGhamidi | |
def initialize | |
@page_agent = Mechanize.new | |
@file_agent = Mechanize.new | |
@file_agent.pluggable_parser.default = Mechanize::Download | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RSpec matcher for alias_method. | |
# https://gist.github.com/1950961 | |
# Usage: | |
# | |
# describe User do | |
# it { should alias_from(:username).to(:email) } | |
# end | |
RSpec::Matchers.define :alias_from do |alias_method| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Floyd-Warshall Algorithm | |
## Introduction: | |
Finds Shortest Path (or longest path) among all pairs of nodes in a graph. | |
Complexity: O(|n|³) | |
## How does it work? | |
- There can be more than one route between two nodes. | |
- The number of nodes in the route isn’t important (Path 4 has 4 nodes but is shorter than Path 2, which has 3 nodes) | |
- There can be more than one path of minimal length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://ariejan.net/2011/09/24/rspec-speed-up-by-tweaking-ruby-garbage-collection | |
# | |
# Usage: | |
# DEFER_GC=10 rspec spec/ | |
# DEFER_GC=10 cucumber features/ | |
# | |
# put it to spec/support/deferred_garbage_collection_all_in_one.rb | |
# or feature/support/hooks.rb | |
class DeferredGarbageCollection | |
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || -1).to_f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateItemChildrenCountView < ActiveRecord::Migration | |
def self.up | |
execute <<-SQL | |
CREATE VIEW item_children_count AS | |
SELECT parent_id AS item_id, COUNT(*) as children_count | |
FROM items GROUP BY parent_id; | |
SQL | |
end | |
def self.down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get RSpec-style let() in your Mocha/Jasmine specs. | |
*/ | |
var let = function (callback) { | |
var value, called = false; | |
var memoizer = function() { | |
if (called) { | |
return value; | |
} else { | |
called = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Optimized for writes, sort on read | |
# LVC | |
redis.hset("bonds|1", "bid_price", 96.01) | |
redis.hset("bonds|1", "ask_price", 97.53) | |
redis.hset("bonds|2", "bid_price", 95.50) | |
redis.hset("bonds|2", "ask_price", 98.25) | |
redis.sadd("bond_ids", 1) | |
redis.sadd("bond_ids", 2) |
OlderNewer