Skip to content

Instantly share code, notes, and snippets.

View jgarber's full-sized avatar

Jason Garber jgarber

View GitHub Profile
@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: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 / 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 / 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 / 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
$ rails c
1.9.2p320 :007 > ActiveRecord::Base.connection.send :postgresql_version
=> 90102
$ rake staging console
ActiveRecord::Base.connection.send :postgresql_version
=> 80311
$ rake production console
ActiveRecord::Base.connection.send :postgresql_version
@jgarber
jgarber / wtf-commerce.php
Created May 4, 2012 23:02
ODEARGODSAVEMEFROMTHISINSANITY!!!!
<script>
function hightlightPaymentMethodLogo(payment_method_id) {
if(payment_method_id > 0) {
var payment_method_logo_id = 'payment_method_logo_' + payment_method_id;
var obj = document.getElementById(payment_method_logo_id);
obj.style['border-style'] = "solid";
obj.style['border-width'] = "2px";
obj.style['-moz-border-radius'] = "6px";
obj.style['-webkit-border-radius'] = "6px";
obj.style['border-color'] = "#00ff00";
@jgarber
jgarber / gist:2349973
Created April 10, 2012 09:56
Spec for a tagging front-end Rails plugin or jQuery library

Need a Rails plugin that can also be used as just a jQuery library.

  • Written in CoffeeScript
  • Has Jasmine tests
  • Only requires jQuery — not jQuery UI
  • Based off of and styles itself after a single text form field
  • Can be downloaded with a minified JS version ready to go
  • Rails form helper for creating the field
  • SimpleForm detection and helper as well
  • Can specify separator characters like Tag-it
@jgarber
jgarber / gist:1993171
Created March 7, 2012 13:38
Remove default field sizes in Rails 3.2.2
class ActionView::Helpers::InstanceTag
DEFAULT_FIELD_OPTIONS.delete("size")
DEFAULT_TEXT_AREA_OPTIONS.delete("rows")
DEFAULT_TEXT_AREA_OPTIONS.delete("cols")
end
class HtmlTag < Parslet::Parser
root(:tag)
rule(:tag) do
( open_tag | close_tag | self_closing_tag ).as(:html_tag)
end
rule(:self_closing_tag) { str("<") >> tag_name >> attributes? >> (spaces? >> str("/")) >> str(">") }
rule(:open_tag) { str("<") >> tag_name >> attributes? >> str(">") }
rule(:close_tag) { str("</") >> tag_name >> str(">") }