Skip to content

Instantly share code, notes, and snippets.

@tyronewilson
tyronewilson / git-funge
Created November 16, 2017 07:41
Squash a bunch of commits into one but keep all the commit messages
#!/bin/bash
# Special thanks to https://stackoverflow.com/a/5201642/1212371
#
# Installation:
# Download and place this file somewhere in your path typically ~/bin/git-funge or /usr/local/bin/git-funge
# make sure it has execute permissions with `sudo chmod +x <path-to-your>/git-funge`
#
# Usage:
#
# `git funge HEAD~3` or
@tyronewilson
tyronewilson / yaml_to_json.rb
Last active March 17, 2020 05:45 — forked from xiaohanyu/yaml_to_json.rb
convert yaml to json in ruby
#!/usr/bin/ruby
# Quick and easy way to convert from yaml to json with pretty format
# Usage:
# Example 1:
#
# # Explicitly give the output filename
# ./yaml_to_json.rb input_file/name.yaml outputfile/name.json
#
# Example 2:
#
@tyronewilson
tyronewilson / debit.rb
Created February 22, 2017 14:18
Example utility class for running a transaction
module Banking
module Processing
class Debit
class << self
def execute(amount, payment_method)
# Do vital checks before doing any work
unless payment_method.registered?
raise Errors::UnregisteredPaymentMethod.new("You can't debit an unregistered payment method")
end
@tyronewilson
tyronewilson / bank_account.rb
Last active February 22, 2017 13:49
example bank account class
module Banking
module PaymentMethods
class BankAccount < ActiveRecord::Base
belongs_to :user
has_many :transactions, class_name: 'Banking::Transaction'
def debit(amount)
Processing::Debit.execute(amount, self)
# Or Processing::Debit.new(amount, self).process! depending on your desired API
end
@tyronewilson
tyronewilson / outline
Last active February 22, 2017 14:26
Simple Banking module
app/
models/
user.rb # ActiveRecord
banking/
payment_methods/
bank_account.rb # ActiveRecord
credit_card.rb # ActiveRecord
registration.rb
processing/
base.rb
rake parallel:create
rake parallel:prepare
rake parallel:spec
Output -------
8 processes for 204 specs, ~ 25 specs per process
/home/tyrone/.rvm/gems/ruby-2.1.5@myproject/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect': FATAL: database "myproject_test<%= ENV['TEST_ENV_NUMBER'] %>" does not exist (ActiveRecord::NoDatabaseError)
Run `$ bin/rake db:create db:migrate` to create your database
@tyronewilson
tyronewilson / bs_helpers.gemspec
Last active August 29, 2015 14:15
haml helpers
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'bs_helpers/version'
Gem::Specification.new do |spec|
spec.name = "bs_helpers"
spec.version = BsHelpers::VERSION
spec.authors = ["Tyrone Wilson"]
spec.email = ["tdubs241083@gmail.com"]