Skip to content

Instantly share code, notes, and snippets.

Avatar

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
aprescott / gist:1705d11ac5091a447311
Created Oct 31, 2014
automatically switch Terminal.app 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
end
end
class Proc
def |(other)
proc { |arg| other.to_proc.call(self.call(arg)) }
end
@aprescott
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 = Module.new do
define_method(method) do |*args, &block|
sleep 1
super(*args, &block)
end
end
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
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
aprescott / githubbers.sh
Created Oct 25, 2013
* is a GitHubber!
View githubbers.sh
#!/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="/)[^"]+(?=">)')"
View gist:6175861
# 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 Dec 18, 2015
yoleoreader.com user style. You can install it in Stylish manually, or get it from http://userstyles.org/styles/88954/yoleo-reading-tweaks
View yoleoreader.com.css
/*
* 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;
You can’t perform that action at this time.