Skip to content

Instantly share code, notes, and snippets.

// 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
aprescott / gist:1705d11ac5091a447311
Created October 31, 2014 18:48
automatically switch Terminal.app to a specific profile before ssh'ing
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
class Symbol
def |(other)
self.to_proc | other
end
end
class Proc
def |(other)
proc { |arg| other.to_proc.call(self.call(arg)) }
end
@aprescott
aprescott / delay_method.rb
Created March 26, 2014 15:04
Slow down an instance method by 1 second.
# Delay Foo#method by 1 second before
# executing its original implementation.
def delay_method(klass, method)
sleeping_giant = Module.new do
define_method(method) do |*args, &block|
sleep 1
super(*args, &block)
end
end
# 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$"
# Demonstration showing that
#
# alias_method :bar, :foo
#
# is not equivalent to
#
# def bar
# foo
# end
@aprescott
aprescott / re_run_friendly_formatter.rb
Last active July 27, 2016 14:18
A re-run friendly formatter for RSpec, to show failed example files as a single rspec command to run.
# 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
aprescott / githubbers.sh
Created October 25, 2013 23:26
* is a GitHubber!
#!/bin/bash
SCRIPT_DIR="$( cd "$(dirname "$0")" ; pwd -P )"
cd "$SCRIPT_DIR"
last_employee_count=$(cat last-employee-count)
last_employee_list="$(cat last-employee-list)"
employee_count=$(curl -s 'https://github.com/about/team' | grep -o '[0-9]* employees' | grep -o '[0-9]*')
employee_list="$(curl -s https://github.com/about/team | grep -e '<div class="employee">' -A 1 | grep -Po '(?<=<a href="/)[^"]+(?=">)')"
# imgur redirecting direct image links from t.co 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 i.imgur.com/foo.jpg link in a tweet.
# 2. Visit it with a redirect through t.co.
# 3. See imgur.com/foo page instead of just the image.
# 4. Visit the same link from (1) again.
# 5. See the regular image at i.imgur.com/foo.jpg, as usual.
@aprescott
aprescott / yoleoreader.com.css
Last active December 18, 2015 08:09
yoleoreader.com user style. You can install it in Stylish manually, or get it from http://userstyles.org/styles/88954/yoleo-reading-tweaks
/*
* Just a user stylesheet for yoleoreader.com. No affiliation.
*
* Author: Adam Prescott (aprescott.com)
* Copyright: CC BY-NC-SA - Creative Commons Attribution-NonCommercial-ShareAlike
*/
.article-contents {
font-family: "Georgia", serif;
font-size: 1.1em;