Skip to content

Instantly share code, notes, and snippets.

View steve9001's full-sized avatar

Steve Masterman steve9001

View GitHub Profile
class Array
def promote_element(e)
i = self.index(e)
return self if i == 0 or i == nil
result = self.slice(0, i-1)
result << e
result << self[i-1]
result.concat(self.slice(i+1, self.length))
end
@steve9001
steve9001 / application.rb
Created December 7, 2011 16:18
Rails middleware to provide information about errors during requests
module MyApp
class Application < Rails::Application
if Rails.env == 'test'
require 'diagnostic'
config.middleware.use(MyApp::DiagnosticMiddleware)
end
end
end
@steve9001
steve9001 / foo.rake
Created April 27, 2012 14:46
db:test:prepare weirdness
desc "db:test:prepare makes the connected db different from the one implied by Rails.env"
task :foo => :environment do
puts Rails.env #development
puts User.count #1
Rake::Task["db:test:prepare"].invoke
puts Rails.env #??
puts User.count #??
end
@steve9001
steve9001 / balanced_payments_guest_checkout.md
Created May 22, 2012 15:18
Balanced Payments guest checkout workflow

Workflow for (repeat) guest checkout

  1. In your form, gather email address, credit card, and amount

  2. With balanced.js post the card data to Marketplace cards_uri

  • response is unique card token URI
  • response is never 409 Conflict ; passing the same card will always create a new token
  1. In js callback, post the email address, card token and amount to your server
class Exception
def pretty
trace = backtrace.select{ |l|l.start_with?(Rails.root.to_s) }.join("\n ")
"#{self.class}\n#{message}\n#{trace}\n"
end
end
@steve9001
steve9001 / setup.sh
Created December 28, 2012 16:44 — forked from bkaney/setup.sh
#!/usr/bin/env zsh
# Install the following first:
#
# - chrome
# - iterm2
# - connect.apple.com command-line: XCode tools
successfully() {
@steve9001
steve9001 / patch.rb
Created August 13, 2013 17:17
Exception#pretty
class Exception
def pretty
%|\n#{self.class} (#{self.message}):\n #{backtrace.join("\n ")}\ n|
rescue Exception => e
"error in Exception#pretty: #{e}"
end
end
# supersub text_to_replace replacement_text directory
function supersub {
ack -l "$1" "$3" | xargs perl -p -i -e "s/$1/$2/g"
}
say -v princess 'lalalalalala' &
say -v 'Agnes' lalalalala &
say -v 'Albert' lalalalala &
say -v 'Alex' lalalalala &
say -v 'Bad News' lalalalala &
say -v 'Bahh' lalalalala &
say -v 'Bells' lalalalala &
say -v 'Boing' lalalalala &
say -v 'Bruce' lalalalala &
say -v 'Bubbles' lalalalala &
date sell_type sell_quantity buy_type buy_quantity
Mar 28, 2018 5:09:04 AM USD 500 BTC 0.06197515
Mar 29, 2018 4:59:23 PM USD 800 BTC 0.11595698
Apr 21, 2018 2:14:32 AM BTC 0.05 USD 444.66
May 05, 2018 8:15:17 AM BTC 0.05 USD 494.18