Skip to content

Instantly share code, notes, and snippets.

@ajvargo
ajvargo / gist:6442681
Created September 4, 2013 20:49
Work git config
[user]
name = Andrew J Vargo
email = [email protected]
[alias]
co = checkout
w = whatchanged
br = branch
lo = log --oneline --decorate
ss = status -sb
last = log -n 1
@ajvargo
ajvargo / ar_attributes_with_associations.rb
Created February 25, 2014 16:49
Add in association attributes to model attributes.
# Based on http://stackoverflow.com/questions/2299139/retrieve-all-associations-attributes-of-an-ar-model
# Doesn't spelunk, doesn't name associations for easy consumption back. Good first go though.
# It gives the object attributes with the attributes of first cousin associations.
class ActiveRecord::Base
def attributes_with_associations
association_names = self.class.reflect_on_all_associations.collect { |r| r.name }
me = self.class.find self.id, :include => association_names
pairs = association_names.collect do |association_name|
@ajvargo
ajvargo / payment_calculator.rb
Created March 31, 2014 20:31
Calculate monthly payments to be done in N months
#!/usr/bin/env ruby
# This prints a table showing how much a monthly payment
# would need to be to pay off a loan. It takes a max and
# min loan amount, and how much to jump between them. I
# use it to dream about paying off student loans. It allows
# me to see what my 1 year pay-off payments are as the loan
# gets paid back.
class PaymentCalculator
@ajvargo
ajvargo / gist:447e8e03518a3bdc75c5
Last active August 29, 2015 14:01
Get a summary and ticket number from Jira, based on branch name
;; elisp
(setq jira-base-url "<JIRA BASE URL>"
jira-request-url (concat "https://" jira-base-url "/rest/api/latest/issue/")
jira-username "<USERNAME>"
jira-password "<PASSWORD>"
jira-credentials (base64-encode-string (concat jira-username ":" jira-password))
;; this is a regex to trim things off the branch name
;; as is, removes: dev-, rel-, av-, dev/, rel/, av/
jira-branch-trim-regex "^\\(dev\\|rel\\|\\av\\)\\(-\\|/\\)"
jira-auth-key (concat jira-base-url ":443"))
@ajvargo
ajvargo / line_formatter.rb
Last active August 29, 2015 14:02
A simple RSpec formatter to give you the example file and line, along with a description and status.
require 'rspec/core/formatters/base_text_formatter'
# RSpec 2
# rspec --require <path_to>/line_formatter.rb --format LineFormatter spec/
# ./spec/lib/a_spec.rb:39
# Success Thing#with_thing does thing
#
# ./spec/lib/a_spec.rb:45
# pending Thing#does_other_thing is pending
@ajvargo
ajvargo / loan_payment.rb
Created November 10, 2014 21:48
Calculate payments for getting paid off in a certain time
#!/usr/bin/env ruby
require 'date'
class Repayment
MONTHLY_INTEREST = (<INTEREST (5.00)> / 12 / 100)
def initialize(payment, principal)
@payment, @principal = payment, principal
end
@ajvargo
ajvargo / pre-push
Last active August 29, 2015 14:16
My version of protecting against a force push
#!/usr/bin/env bash
# Prevents force-pushing to certain branches w.o confirmation
# install to <repo>/.git/hooks/
# chmod +x
protected_branches="^(master|production)"
current_branch=`git rev-parse --abbrev-ref HEAD`
push_command=`ps -ocommand= -p $PPID`
force_push="force|delete|-f"

Keybase proof

I hereby claim:

  • I am ajvargo on github.
  • I am vargo (https://keybase.io/vargo) on keybase.
  • I have a public key whose fingerprint is 203A 9F1A 8BA1 CAE1 CF11 1E02 ABFB B502 A5F5 B641

To claim this, I am signing this object:

@ajvargo
ajvargo / interleave.rb
Created April 19, 2016 14:39
Testing different ways to `zip` arrays when the first isn't longest
require "benchmark"
def interleave(*arrays)
result = []
current_positions = Array.new(arrays.length) { 0 }
completed_arrays = Array.new(arrays.length) { false }
while true
arrays.each_with_index do |array, index|
current_position = current_positions[index]
@ajvargo
ajvargo / rspec-mode-bb-overrides.el
Created May 3, 2016 22:35
Get RSpec mode working w/ Vagrant
(defun vagrant-rspec-spec-file-for (orig-fun a-file-name)
"Convert file name from local to vagrant"
(apply orig-fun (list (replace-regexp-in-string "^.+/spec" "/vagrant/spec" a-file-name))))
(with-eval-after-load 'rspec-mode
(setq rspec-spec-command "vrspec"
rspec-command-options "--format=progress --no-profile"
rspec-use-bundler-when-possible nil
rspec-use-opts-file-when-available nil)