Skip to content

Instantly share code, notes, and snippets.

View zealoushacker's full-sized avatar

Alex Notov zealoushacker

View GitHub Profile
@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: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"=>"[email protected]", "id"=>"AC5xQY0AdN6Ex8i7QOIsbPZQ", "credits_uri"=>"/v1/marketpl
@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: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 / 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 / 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 / sq_cat.js
Created August 1, 2011 20:24
A meowing Cat FTW!
var SQAPP = {};
SQAPP.Cat = function ( name ) {
this.name = name;
}
SQAPP.Cat.prototype.meow = function () {
alert(this.name + " says meow!");
}
# Allow RSpec assertions over the elements of a collection. For example:
#
# collection.should all_be > 0
#
# will specify that each element of the collection should be greater
# than zero. Each element of the collection that fails the test will
# be reported in the error message.
#
# Examples:
# [1,1,1].should all_be eq(1)
<!DOCTYPE html>
<html>
<head>
<title>Site</title>
</head>
<body class="app">
<%= render :partial => 'layouts/flashes' %>
<%= yield %>
</body>
</html>
@zealoushacker
zealoushacker / better_table_step.feature
Created July 13, 2011 17:16
Better table matching step
Then table "business_services" should look like:
| field 1 | field 2 | field 3 |
| x | y | z |
| a | b | c |