Skip to content

Instantly share code, notes, and snippets.

View finbarr's full-sized avatar

Finbarr Taylor finbarr

View GitHub Profile
class Array
def bucketize(n)
return [] if (buckets = n.to_i) <= 0
j = length / buckets.to_f
result = each_with_index.chunk { |_, i| (i / j).floor }.map { |_, v| v.map(&:first) }
result << [] until result.length == buckets
result
end
end
class Contractor < ActiveRecord::Base
....
def stripe_recipient
return nil if stripe_recipient_id.nil?
Stripe::Recipient.retrieve stripe_recipient_id
end
....
end
class BankDetailsController < ApplicationController
before_filter :set_recipient
def show
end
def update
if @recipient.present? && @recipient.verified
update_bank_account
else
= form_tag({}, {:method => :put}) do
- if @recipient.present? && @recipient.verified
= text_field_tag 'routing_number'
= text_field_tag 'account_number'
- else
= text_field_tag 'name'
= text_field_tag 'tax_id'
@finbarr
finbarr / gist:5715953
Created June 5, 2013 18:14
Stripe Transfer snippet.
stripe_transfer = Stripe::Transfer.create(
:amount => transaction_amount_in_cents,
:currency => 'usd',
:recipient => contractor.stripe_recipient_id,
:description => ''
)
#we store this after creating the transfer
stripe_tranfer.id
require 'set'
# n^2 solution
nums = (-50..50).to_a
s = Set.new(nums)
triplets_adding_to_zero = []
{
"auto_complete": true,
"auto_complete_commit_on_tab": true,
"auto_complete_delay": 0,
"auto_complete_selector": "source - comment",
"auto_complete_size_limit": 4194304,
"auto_complete_triggers":
[
{
"characters": "<",
@finbarr
finbarr / git_stats.rb
Created September 27, 2013 16:49
This was a quick hack to find out the aggregate contributions of members of a git repository based on the output of `git log --shortstat`.
file_name = ARGV[0]
puts file_name
def rip_num(part)
part.split(" ").first.to_i
end
File.open(file_name) do |f|
insertions = 0
@finbarr
finbarr / .gemrc
Created September 27, 2013 16:53
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri
alias ll="ls -al"
alias gch="git checkout"
alias gb="git branch"
alias gs="git status"
alias gp="git pull"
alias gf="git fetch"
alias gr="git rebase"
alias gl="git log"
alias gd="git diff"
alias gdo="git diff origin/master"