Skip to content

Instantly share code, notes, and snippets.

View joeyates's full-sized avatar

Joe Yates joeyates

View GitHub Profile
@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 / 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
@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-copy-file-history.sh
Last active February 23, 2023 17:34
Copy a commits from one Git repo to another
# Copy all modifications to a file from one repo to another
for c in `git --git-dir=../path/to/repo/.git log --reverse --pretty=tformat:"%H" -- path/to/file`; do
git --git-dir=../path/to/repo/.git format-patch --keep-subject -1 --stdout $c | git am --3way --keep;
done
@joeyates
joeyates / git-deinit-submodule.md
Last active August 29, 2015 14:04
Removing submodules
@joeyates
joeyates / run_ruby_tests.sh
Last active January 23, 2017 09:44
Running MRI Ruby Tests
# While modifying Ruby source, it's handy to only run the tests on the file you're modifying.
# See:
# * doc/contributing.rdoc in Ruby source,
# * https://bugs.ruby-lang.org/projects/ruby/wiki/DeveloperHowto
# Run core tests:
make test
# Run all tests:
@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)