Skip to content

Instantly share code, notes, and snippets.

View joeyates's full-sized avatar

Joe Yates joeyates

View GitHub Profile
@joeyates
joeyates / custom_argument_matchers.rb
Last active August 29, 2015 14:00
hash_matching: an RSpec arguments matcher like hash_including, but which handles Regexps
# spec/support/custom_argument_matchers.rb
module CustomArgumentMatchers
class HashMatching
attr_reader :expected
def initialize(expected)
@expected = expected
end
def ==(target)
@joeyates
joeyates / ruby_hash_jsonify.vim
Created June 15, 2014 16:43
Convert to new-style Ruby Hashes
function! SubstituteInLine(linenumber, regexp, replacement)
let line = getline(a:linenumber)
let changed = substitute(line, a:regexp, a:replacement, 'g')
call setline(a:linenumber, changed)
endfunction
" Converts
" 'abc' => 1
" to
" :abc => 1
@joeyates
joeyates / foo_spec.rb
Created June 18, 2014 13:22
Test rake tasks with rspec
require 'spec_helper'
require 'rake'
describe 'foo tasks' do
before :all do
Rake::Task.clear
Rake.application.rake_require 'tasks/foo'
Rake::Task.define_task(:environment)
end
@joeyates
joeyates / git-deinit-submodule.md
Last active August 29, 2015 14:04
Removing submodules
@joeyates
joeyates / form_encode.ex
Created October 3, 2015 08:59
Do object-scoped from encoding of HTTP parameters
defmodule FormEncode do
def form_encode(params) when is_map(params) do
form_encode([], params)
end
def form_encode(nesting, value) when is_map(value) do
Enum.map_join(value, "&", fn({k, v}) ->
n1 = Enum.reverse(Enum.reverse(nesting), [k])
form_encode(n1, v)
end)
@joeyates
joeyates / uniq-path-bash3.sh
Created September 17, 2012 21:51
Pure bash scripts for removing duplicates from PATH
#!/bin/bash
# A pure-bash (3.x+) function for removing duplicates from PATH
# Use:
# $ export PATH=`uniq-path-bash3.sh`
# Separate on ':'
OLD_IFS=$IFS
IFS=":"
# Collect unique items in NEW_PATH
@joeyates
joeyates / f.sh
Last active December 10, 2015 01:58
This is my go to find command. It searches for files and directories with partial matches of the first parameter.
# f - everyday find
# usage:
# f filename_fragment [path]
# skips whatever you list in _exclude_matches
_exclude_matches=(bundle .git *.pyc)
_excludes=''
for _match in $_exclude_matches; do
_excludes="${_excludes}-name '$_match' -prune -o "
done
@joeyates
joeyates / rbenv_local_ruby.sh
Created July 3, 2016 11:13
Build Ruby from Local Sources and add to RBenv
#!/usr/bin/env sh
# Usage:
# $ sh rbenv_local_ruby.sh {VERSION}
# If VERSION is missing, builds and installs 'local-ruby'
VERSION=${1:-local-ruby};
echo $VERSION
./configure --prefix=~/.rbenv/versions/$VERSION
make
# Set up a bash function to cd to a Rails app's current directory and set the prompt
rails_app ()
{
cd "$APP_PATH/current";
export PS1="(\$APP_NAME:\$RAILS_ENV)\w>"
}
my_rails_app ()
{
@joeyates
joeyates / nth-commit
Created October 30, 2013 12:09
Check out the nth commit to master in a git repository. This command can be used during presentation to skip through the history of a repo.
#!/bin/bash
git checkout master
SHA1=`git rev-list HEAD | tail -n $1 | head -n 1`
git checkout $SHA1