Skip to content

Instantly share code, notes, and snippets.

View jgarber's full-sized avatar

Jason Garber jgarber

View GitHub Profile
@jgarber
jgarber / gist:3007310
Created June 27, 2012 22:30
Use Tmux with iTerm2 across users
brew uninstall tmux
brew install https://raw.github.com/adamv/homebrew-alt/master/other/tmux-iterm2.rb
tmux -S /tmp/pair -C new -s session_name
chmod 777 /tmp/pair
tmux -S /tmp/pair -C attach -t session_name
@jgarber
jgarber / private.xml
Created August 28, 2012 01:59
KeyRemap4MacBook setup to pair program with one Dvorak - Qwerty ⌘ typist and one Qwerty typist
<?xml version="1.0"?>
<root>
<deviceproductdef>
<productname>APPLE_INTERNAL_KEYBOARD_TRACKPAD_0x024c</productname>
<productid>0x024c</productid>
</deviceproductdef>
<deviceproductdef>
<productname>APPLE_WIRELESS_KEYBOARD_0x22c</productname>
<productid>0x22c</productid>
</deviceproductdef>
@jgarber
jgarber / big_decimal_to_digits.rb
Created October 3, 2012 17:56
BigDecimal#to_digits without trailing zero
class BigDecimalWithoutTrailingZeroes < BigDecimal
def to_digits
_, significant_digits, _, exponent = split
if zero?
'0'
elsif exponent >= significant_digits.size
to_i.to_s
else
to_s('F')
end
@jgarber
jgarber / gist:4095047
Created November 17, 2012 11:20
Aliases to help count lines of code in a ruby+ember project
alias loc-files='git ls-files **/*.(rb|ru|coffee|scss|handlebars) script bin'
alias loc='loc-files | xargs cat | ruby -ne '\''print unless $_ =~ /^\s*#|^\s*$/'\'' | wc -l'
@jgarber
jgarber / wrs.rb
Last active November 11, 2015 00:34
Weighted random sample talk notes
pond = {salmon:1, crucian:3, carp:4, herring:6, sturgeon:8, gudgeon:10, minnow:50}
pond.map { |_, weight| 0.01 ** (1.0 / weight) }
# Fractional exponents are the same as a radical, so
# crucian is the cube-root of 0.01, carp is the 4th-root of 0.01...
# https://www.desmos.com/calculator/zjgygztibi
pond.map { |_, weight| 0.99 ** (1.0 / weight) }
# crucian is the cube-root of 0.99, carp is the 4th-root of 0.99...
@jgarber
jgarber / gist:4598274
Last active December 11, 2015 12:08
Manually start sidekiq workers
pkill -f god
pkill -f sidekiq
sudo service boocx-app-web stop
sudo service boocx-api stop
cd /home/boocx
cd boocx-api
git pull
bundle
git submodule update --init
@jgarber
jgarber / clean_up_duplicates.rb
Created January 23, 2013 20:14
Get rid of duplicate BalanceComputations in the main queue
count = 25
name = "main"
starting = 0
ending = starting + count
key = "queue:#{name}"
total_size = 0
keep = {}
loop do
@jgarber
jgarber / gist:4998894
Created February 20, 2013 19:58
Finding duplicates
->(klass){ names = klass.all.map(&:name); names.detect {|e| names.count(e) > 1 } }.call Tag
# Up arrow and change to Amenity, Usage, etc. ^
@jgarber
jgarber / gist:5698080
Created June 3, 2013 13:16
Work-in-progress: Democratic rebuttal to "Welcome to the Republican Party"
The original:
Father-Daughter Talk
A young woman was about to finish her first year of college. Like so many others her age, she considered herself to be a very liberal Democrat, and was very much in favor of the redistribution of wealth. She was deeply ashamed that her father was a rather staunch Republican, a feeling she openly expressed. Based on the lectures that she had participated in, and the occasional chat with a professor, she felt that her father had for years harbored an evil, selfish desire to keep what he thought should be his.
One day she was challenging her father on his opposition to higher taxes on the rich and the addition of more government welfare programs. The self-professed objectivity proclaimed by her professors had to be the truth and she indicated so to her father. He responded by asking how she was doing in school. Taken aback, she answered rather haughtily that she had a 4.0 GPA, and let him know that it was tough to maintain, insisting that she was taking a very difficult cours
@jgarber
jgarber / gist:5893179
Last active December 19, 2015 03:49
Setting up motion with a raspberry pi camera
ssh-copy-id pi@192.168.X.X
# on the pi
sudo su -
cat <<EOF >> /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="Your SSID Here"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP