Skip to content

Instantly share code, notes, and snippets.

View kstevens715's full-sized avatar

Kyle Stevens kstevens715

View GitHub Profile
@kstevens715
kstevens715 / test_helper.rb
Created February 17, 2014 01:05
Make Factory Girl's `create` method give the name of the class that raises ActiveRecord::RecordInvalid. Useful when you have nested factories whose models have attributes with similar names ex. `name`.
include FactoryGirl::Syntax::Methods
def create_with_info(*args, &block)
create_without_info(*args, &block)
rescue => e
raise unless e.is_a? ActiveRecord::RecordInvalid
raise $!, "#{e.message} (Class #{e.record.class.name})", $!.backtrace
end
surround_test_suite { invoke1 }
surround_test_suite { invoke2 }
surround_test_suite { invoke3 }
def surround_test_suite(&block)
block.call
rescue => e
puts e
end
@kstevens715
kstevens715 / .bash_profile
Last active August 29, 2015 14:14
pair will start a new tmux session named pair, or if you're already in one with another name it'll rename it to pair. It would also be nice to go a step further and have a way to toggle it back off again. This is meant to be used in conjunction with the pairing setup shown in this blog article: http://collectiveidea.com/blog/archives/2014/02/18/…
alias getmyip='dig +short myip.opendns.com @resolver1.opendns.com'
function pair() {
if [ "$TMUX" = "" ]; then
tmux new-session -s pair \; set-option display-time 4000\; display-message "Pairing Enabled: ssh pair@`getmyip`"
else
tmux rename-session pair \; set-option display-time 4000\; display-message "Pairing Enabled: ssh pair@`getmyip`"
fi
}
@kstevens715
kstevens715 / partial_stage.md
Last active August 29, 2015 14:23
This shows how to partially stage a HUGE file, one piece at a time.

This shows how to partially stage a HUGE file, one piece at a time. git add -p also does this, but sometimes doesn't show enough context and if the file is big enough, regex searching doesn't seem to always work.

  1. This requires Vim, with the Fugitive plugin installed (see reference links).
  2. Open the file in Vim, and type :Gdiff. The screen will split in two, with the left hand side showing the indexed version of the file (what will be committed), and the right hand side showing the current working copy.
  3. Move the cursor to the right-side pane, and find the hunk you're interested in.
  4. With the cursor in the hunk, type :diffput. The hunk will disappear from the right hand side, and the left hand side will get a "+" in the status bar indicating unsaved changes.
  5. Complete steps 2-3 until everything is staged.
  6. When done, move the cursor to the left pane and save it to stage the files.

References

@kstevens715
kstevens715 / address_controller.rb
Created June 2, 2012 01:03
CoffeeScript file for working with Twitter Bootstrap forms.
# This is just a basic sample of a controller needed to work with popups.js
class AddressesController < ApplicationController
before_filter :load_addressable
def new
@address = @addressable.addresses.build(:name => params[:name])
render :partial => 'form'
end
@kstevens715
kstevens715 / active_record.rb
Created June 20, 2012 14:34
A monkey patch for Rails to fix SchemaDumper to not include table_name_prefix. Will probably be fixed in Rails soon, but needed this now. Based on PR: https://github.com/kennyj/rails/commit/211dcdeaa922c74ac20d274308fb5d41ad490194
# config/initializers/active_record.rb
# Loads the monkey patch.
require 'active_record'
require 'active_record/schema_dumper'
require 'schema_dumper'
ActiveRecord::SchemaDumper.class_eval do
include Nepco::SchemaDumper
end
windows:
- name: vim
root: ~/code/transformer
layout: even-horizontal
panes:
- vim ~/code/transformer/spec/samples/schema_validated/tjcas.xml
- name: rabbitmq
root: ~/code/webadmit
layout: even-horizontal
panes:
@kstevens715
kstevens715 / pagination_view.js.coffee
Created December 25, 2012 03:08
Ember.js AJAX table pagination helper using Twitter Bootstrap. Assumes an ArrayController is in place that implements refreshData(page_num). Replace `Nepco` with [YOURAPPNAME], and in the view with your table add `{{view [YOURAPPNAME].PaginationView}}`. Lots of work to be done still. Plan on having this just be one component in a generic Datatab…
###
Twitter Bootstrap compatible pagination view.
Relies on an ArrayController being in place that implements
refreshData(page_num)
###
# Names of previous and next buttons can be adjusted:
PREV = "Prev"
NEXT = "Next"
@kstevens715
kstevens715 / route.sh
Created November 2, 2013 12:52
Access IRC while on VPN
sudo route add -host irc.freenode.net gw 192.168.1.1
@kstevens715
kstevens715 / quantum_view.xml
Created November 21, 2012 13:41
Shows how to use the QVNOption in Worldship to use Quantum View notifications. For my future reference.
<ShipmentInformation>
<ShipperNumber>#####</ShipperNumber>
<ServiceType>GND</ServiceType>
<NumberOfPackages>1</NumberOfPackages>
<BillingOption>PP</BillingOption>
<QVNOption>
<QVNRecipientAndNotificationTypes>
<EMailAddress>example@example.com</EMailAddress>
<Ship>Y</Ship>
<Exception>Y</Exception>