Skip to content

Instantly share code, notes, and snippets.

View zealoushacker's full-sized avatar

Alex Notov zealoushacker

View GitHub Profile
@zealoushacker
zealoushacker / your_class_spec.rb
Created September 20, 2011 05:06
RSpec shorthand for YourClass.stub(:your_method).and_return(true)
require 'spec_helper'
describe YourClass do
describe "some functionality that depends on YourClass::your_method" do
# YourClass.stub(:your_method).and_return(true) is equivalent to:
YourClass.stub(:your_method) { true }
end
end
@zealoushacker
zealoushacker / model_mocks.rb
Created September 20, 2011 23:22
Model mocks
# a typical controller spec
require 'spec_helper'
describe PaymentsController do
# A typical model mock object (with memoization ftw):
def mock_customer_user(stubs={})
@mock_customer_user ||= mock_model(CustomerUser, stubs).as_null_object
end
@zealoushacker
zealoushacker / gist:1705801
Created January 30, 2012 18:25 — forked from davist11/gist:1204569
Campfire sounds
crickets: "hears crickets chirping"
drama: "https://123.campfirenow.com/images/drama.jpg"
greatjob: "https://123.campfirenow.com/images/greatjob.png"
live: "is DOING IT LIVE"
nyan: "https://123.campfirenow.com/images/nyan.gif"
ohmy: "raises an eyebrow :smirk:"
pushit: "https://123.campfirenow.com/images/pushit.gif"
rimshot: "plays a rimshot"
secret: "found a secret area :key:"
tada: "plays a fanfare :flags:"
@zealoushacker
zealoushacker / gist:3010137
Created June 28, 2012 09:17
max subarray (sub array with the greatest sum)
class Array
def max_subarray_last_index
max_sum = new_maxium = last_index = 0
each_with_index do |value, i|
new_maxium = [new_maxium + value, 0].max
# update everything if we found a truly new maximum =)
max_sum, last_index = new_maxium, i if max_sum < new_maxium
end
@zealoushacker
zealoushacker / gist:3063419
Created July 6, 2012 23:38
attempting to void a captured hold on balanced
1.9.2p290 :026 > @hold = Balanced::Hold.find :first
=> #<Balanced::Hold:0x000001030cf6f8 @attributes={"account"=>#<Balanced::Account:0x00000102f809c8 @attributes={"holds_uri"=>"/v1/marketplaces/TEST-MP4Z4RaRDF6TWqeupiVUSu8m/accounts/AC5xQY0AdN6Ex8i7QOIsbPZQ/holds", "name"=>"New Buyer", "roles"=>["buyer"], "created_at"=>"2012-07-06T19:28:06.379052Z", "uri"=>"/v1/marketplaces/TEST-MP4Z4RaRDF6TWqeupiVUSu8m/accounts/AC5xQY0AdN6Ex8i7QOIsbPZQ", "bank_accounts_uri"=>"/v1/marketplaces/TEST-MP4Z4RaRDF6TWqeupiVUSu8m/accounts/AC5xQY0AdN6Ex8i7QOIsbPZQ/bank_accounts", "refunds_uri"=>"/v1/marketplaces/TEST-MP4Z4RaRDF6TWqeupiVUSu8m/accounts/AC5xQY0AdN6Ex8i7QOIsbPZQ/refunds", "meta"=>{}, "debits_uri"=>"/v1/marketplaces/TEST-MP4Z4RaRDF6TWqeupiVUSu8m/accounts/AC5xQY0AdN6Ex8i7QOIsbPZQ/debits", "transactions_uri"=>"/v1/marketplaces/TEST-MP4Z4RaRDF6TWqeupiVUSu8m/accounts/AC5xQY0AdN6Ex8i7QOIsbPZQ/transactions", "email_address"=>"david+new+buyer@bizeebee.com", "id"=>"AC5xQY0AdN6Ex8i7QOIsbPZQ", "credits_uri"=>"/v1/marketpl
@zealoushacker
zealoushacker / gist:3912841
Created October 18, 2012 16:09
Balanced 402 on card create
{"status":402,"error":{"status":"Payment Required","category_code":"card-declined","status_code":"402","category_type":"banking","request_id":"OHMa0f08dee188711e2b2ae026ba7d31e6f","description":"Processor did not accept this card. Your request id is OHMa0f08dee188711e2b2ae026ba7d31e6f."}}
@zealoushacker
zealoushacker / gist:3970953
Created October 29, 2012 01:55
Explanation of hex colors.
HTML colors are broken into 3 components:
R: Red
G: Green
B: Blue
These 3 components may be represented in hexadecimal.
A hexadecimal representation of the 3 components is called a triplet, or group of 3 numbers.
R G B R G B
@zealoushacker
zealoushacker / gist:4047959
Created November 9, 2012 20:16
balanced card-declined-generic
{
"status": "Payment Required",
"category_code": "card-declined",
"additional": "Generic decline - No other information is being provided by the issuer.",
"status_code": 402,
"category_type": "banking",
"extras": {},
"request_id": "OHMf496075c292211e2ad35026ba7d31e6f",
"description": "R530: Do Not Honor. Your request id is OHMf496075c292211e2ad35026ba7d31e6f."
}
@zealoushacker
zealoushacker / create_sublime_alias
Last active December 31, 2015 19:29
sublime alias for your terminal
If you are on a mac, please follow these instructions to get your sublime link set up appropriately.
Run this command if you have sublime text 2:
echo "alias subl='/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl'" >> ~/.bash_profile
Or, if you have sublime text 3, run this command:
echo "alias subl='/Applications/Sublime\ Text\ 3.app/Contents/SharedSupport/bin/subl'" >> ~/.bash_profile
@zealoushacker
zealoushacker / pure_function_within_a_closure.js
Created December 23, 2013 04:24
A closure containing a pure function in js
/*
Functions containing no free/unbound variables are called pure functions.
Functions containing one or more free variables are called closures.
Adapted from the quick exercise in https://leanpub.com/javascript-allonge/read#closures
If pure functions can contain closures, can a closure contain a pure function?
Attempt to compose a closure that contains a pure function.
Many thanks to @raganwald!