Skip to content

Instantly share code, notes, and snippets.

View kstevens715's full-sized avatar

Kyle Stevens kstevens715

View GitHub Profile
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 / 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 / .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
}
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 / 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
@kstevens715
kstevens715 / irc.sh
Created November 9, 2013 13:45
Route IRC around VPN (Freenode doesn't like VPN).
sudo route add -host irc.freenode.net gw 192.168.1.1
@kstevens715
kstevens715 / swap.sh
Created November 6, 2013 20:41
Create swap space of 2GB.
#!/usr/bin/env bash
# Exit on any error (non-zero return code)
set -e
# Create swapfile of 2GB with block size 1MB
/bin/dd if=/dev/zero of=/swapfile bs=1024 count=2097152
# Set up the swap file
/sbin/mkswap /swapfile
@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 / mfcj835dw.sh
Created April 28, 2013 01:31
Script to install an MFC-J835DW printer on a 64-bit instal of Ubuntu 13.04. Should be compatible with earlier versions as well.
#!/usr/bin/env bash
# Step 5b. (for Network Connection) Configure your printer on the cups web interface
# 5b-1. Open a web browser and go to "http://localhost:631/printers".
# 5b-2. Click "Modify Printer" and set following parameters.
#
# - "LPD/LPR Host or Printer" or "AppSocket/HP JetDirect" for Device
# - lpd://192.168.1.8/binary_p1 for Device URI
# - Brother for Make/Manufacturer Selection
# - Your printer's name for Model/Driver Selection
@kstevens715
kstevens715 / throttle.sh
Created January 22, 2013 20:51
Throttle your loopback interface in Linux to test low bandwith. I was testing an AJAX file upload progress bar and found this helpful.
# Throttle LO interface
sudo tc qdisc add dev lo root handle 1: htb default 12
sudo tc class add dev lo parent 1:1 classid 1:12 htb rate 20kbps ceil 20kbps
sudo tc qdisc add dev lo parent 1:12 netem delay 1000ms
# Go back to the way things were.
sudo tc qdisc del dev lo root