Skip to content

Instantly share code, notes, and snippets.


Adam Prescott aprescott

View GitHub Profile
View depth-first-partition.js
// Iterative depth-first search traversal as a partition.
// Start from startingPoint, and iteratively follow all neighbors.
// If inclusionCondition is true for a neighbor, include it,
// otherwise, exclude it. At the end, return two arrays:
// One for the included neighbors, another for the remaining
// neighbors.
// Example: Say you have a grid which contains certain points
// which are all adjacent-connected:
aprescott / gist:1705d11ac5091a447311
Created Oct 31, 2014
automatically switch to a specific profile before ssh'ing
View gist:1705d11ac5091a447311
function prodssh { osascript -e 'tell application "Terminal" to set current settings of selected tab of window 1 to settings set "Red Sands"' && ssh "$@"; }
# prodssh yourserver
View unix.rb
class Symbol
def |(other)
self.to_proc | other
class Proc
def |(other)
proc { |arg| }
aprescott / delay_method.rb
Created Mar 26, 2014
Slow down an instance method by 1 second.
View delay_method.rb
# Delay Foo#method by 1 second before
# executing its original implementation.
def delay_method(klass, method)
sleeping_giant = do
define_method(method) do |*args, &block|
sleep 1
super(*args, &block)
View gist:9353408
# Collect _spec.rb and .feature files under spec/ that are relevant to current work, one per line. Good for pipes.
# 1. Modified, staged git files.
# 2. Modified, unstaged git files.
# 3. Changes in any commits since master.
# 4. New, untracked files.
# $ specs | xargs rspec
cat <(git diff --name-only) <(git diff --staged --name-only) <(git diff master..@ --name-only) <(git ls-files --others --exclude-standard) | uniq | grep -e "^spec/" | grep -E "_spec\.rb$|\.feature$"
View alias_method_is_not_def.rb
# Demonstration showing that
# alias_method :bar, :foo
# is not equivalent to
# def bar
# foo
# end
aprescott / re_run_friendly_formatter.rb
Last active Jul 27, 2016
A re-run friendly formatter for RSpec, to show failed example files as a single rspec command to run.
View re_run_friendly_formatter.rb
# place the contents of this file in, e.g., spec/re_run_friendly_formatter.rb
# and in .rspec:
# --format ReRunFriendlyFormatter
require "rspec/core/formatters/progress_formatter"
class ReRunFriendlyFormatter < RSpec::Core::Formatters::ProgressFormatter
RSpec::Core::Formatters.register self, :dump_summary
aprescott /
Created Oct 25, 2013
* is a GitHubber!
SCRIPT_DIR="$( cd "$(dirname "$0")" ; pwd -P )"
last_employee_count=$(cat last-employee-count)
last_employee_list="$(cat last-employee-list)"
employee_count=$(curl -s '' | grep -o '[0-9]* employees' | grep -o '[0-9]*')
employee_list="$(curl -s | grep -e '<div class="employee">' -A 1 | grep -Po '(?<=<a href="/)[^"]+(?=">)')"
View gist:6175861
# imgur redirecting direct image links from on the first click ?
# A subsequent visit in the same browser seems to work fine, so maybe
# they remember it via the cookie.
# 1. See link in a tweet.
# 2. Visit it with a redirect through
# 3. See page instead of just the image.
# 4. Visit the same link from (1) again.
# 5. See the regular image at, as usual.
aprescott /
Last active Dec 18, 2015 user style. You can install it in Stylish manually, or get it from
* Just a user stylesheet for No affiliation.
* Author: Adam Prescott (
* Copyright: CC BY-NC-SA - Creative Commons Attribution-NonCommercial-ShareAlike
.article-contents {
font-family: "Georgia", serif;
font-size: 1.1em;
You can’t perform that action at this time.