Skip to content

Instantly share code, notes, and snippets.

:'<,'>!pbcopy & pbpaste
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@mgamba
mgamba / gist:5490154
Last active December 16, 2015 20:09
iterate backwards from today to $DATE
d=0
until [ $DATE = `date -d "-$d days" +%Y/%m/%d` ]; do
let d+=1
if [ 2011/07/14 = `date -d "-$d days" +%Y/%m/%d` ]; then
echo "fail - date $DATE_STRING not in acceptable range (2012/07/15-current)" >&2
exit -1
fi
done
for days_back in {1..4}; do
@mgamba
mgamba / gist:5322639
Last active December 15, 2015 20:59
How to write a simple UDF in Hive

Create a simple java app that adds two ints

// Plusser.java
package org.apache.hadoop.hive.contrib.udf.example;

import org.apache.hadoop.hive.ql.exec.UDF;

public class Plusser extends UDF{

  public Integer evaluate(Integer a, Integer b){
@mgamba
mgamba / gist:5222454
Last active December 15, 2015 07:19
run rspec on current line from vim using `<leader>r`
map <leader>r :exec "!bundle exec rspec %\:".line('.')<cr>
@mgamba
mgamba / gist:5120453
Created March 8, 2013 22:31
get all keys of a hash, good for diffing hashes that are equivalent regardless of values
def nested_keys(h)
th = {"keys" => h.keys.sort}
h.each{|k,v| th[k] = nested_keys(h[k]) if h[k].class == Hash }
th
end
nested_keys(h1).diff(nested_keys(h2))
@mgamba
mgamba / gist:5060809
Created February 28, 2013 22:48
branches dates people stufff
for branch in `git branch -r | grep -Ev 'origin/master|origin/staging|heroku/'`; do echo;echo $branch && git log --pretty='%C(white)%h%C(green) %ad %C(yellow)%aN' --date=short $branch -1; done
@mgamba
mgamba / gist:5057535
Created February 28, 2013 15:26
Joe's Gemfile hashrocket bug fix
I had this same issue this morning. I was able to fix it by deleting all my gems, and then running bundle config path 'vendor/bundle' so it installs the gems inside your app directory (since rbenv has no gemsets), bundle install again, a quick rbenv rehash, and then everything seemed to work again with the newer syntax. I think rbenv for some reason was running my powder gem out of another ruby version and not the current one. I do admit, it was a pretty weird issue, but I was able to get it working.