Skip to content

Instantly share code, notes, and snippets.

View rahearn's full-sized avatar

Ryan Ahearn rahearn

  • 18F (work) + personal projects
  • Baltimore, MD
View GitHub Profile
@rahearn
rahearn / optional_pipe.swift
Created September 19, 2016 18:43
Custom pipe operator to conditionally call a method if optional is present
infix operator |?
func |?<I,O>(left: I?, pipeFunc: ((I) -> O?)) -> O? {
guard let value = left else { return nil }
return pipeFunc(value)
}
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.timeZone = NSTimeZone.local
@rahearn
rahearn / translate.rb
Created July 8, 2016 14:42
translate pipe-delimited files to CSV
require 'csv'
path = ARGV[0]
fail "path required" if path.nil?
csv = CSV.open "#{path}.csv", "w"
begin
File.open(path).each do |line|
line = line.strip.force_encoding('iso-8859-1').encode 'UTF-8'
csv << line.split('|', -1)
@rahearn
rahearn / gist:9038f84d7b68f07880ae
Created December 15, 2014 20:57
selenium chromedriver error
[11860:11860:1215/155347:ERROR:browser_main_loop.cc(162)] Running without the SUID sandbox! See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
Xlib: extension "RANDR" missing on display ":99".
[11860:11860:1215/155347:ERROR:browser_main_loop.cc(208)] GLib-GObject: Attempt to add property GtkSettings::gtk-label-select-on-focus after class was initialised
[11860:11860:1215/155347:ERROR:browser_main_loop.cc(208)] GLib-GObject: Attempt to add property GtkSettings::gtk-entry-select-on-focus after class was initialised
[11860:11860:1215/155347:ERROR:browser_main_loop.cc(208)] GLib-GObject: Attempt to add property GtkSettings::gtk-entry-password-hint-timeout after class was initialised
@rahearn
rahearn / keybase.md
Created April 18, 2014 18:40
Keybase.io profile proof

Keybase proof

I hereby claim:

  • I am rahearn on github.
  • I am rcahearn (https://keybase.io/rcahearn) on keybase.
  • I have a public key whose fingerprint is 534E F500 3A4E F71E 1F71 AA8C 1BDA 847E 8098 0ABB

To claim this, I am signing this object:

@rahearn
rahearn / Gemfile
Created March 26, 2014 14:43
Skynet deploy details
source "https://rubygems.org"
gem 'skynet-deploy', '~> 1.3'
# jekyll deps
gem 'kramdown', '~> 1.3'
gem 'RedCloth', '~> 4.2'
gem 'gsl', '~> 1.14'
@rahearn
rahearn / Vagrantfile
Last active December 30, 2015 03:28
wordpress dev Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "wordpress"
config.vm.box_url = "https://dl.dropboxusercontent.com/s/nkzyze6gb7mvam9/wordpress.box"
@rahearn
rahearn / activeadmin-cancan.rb
Last active December 12, 2015 06:58
ActiveAdmin & CanCan integration. Works with `check_authorization` in ApplicationController
# blog post:
# Before using this initializer, you must set up Cancan. First, add the gem to your Gemfile:
#
# gem 'cancan'
#
# Next, generate and edit an Ability class:
#
# rails generate cancan:ability
#
@rahearn
rahearn / spec.rb
Created November 13, 2012 22:03
RSpec subject & let block load order example
context "outer" do
subject { puts "subject"; "subject" }
let(:expected) { puts "expected"; "subject" }
let!(:bang) { puts "bang"; "bang" }
context "inner" do
let!(:inner) { puts "inner"; "inner" }
it "should print bang, inner, test, subject, expected" do
puts "test"
@rahearn
rahearn / gist:3868151
Created October 10, 2012 20:18
Recovery steps for messed up rebase
Recovering from a botched rebase:
1) mess up a rebase
2) `git reflog` and find the last commit before the rebase started
3) `git reset --hard <<that commit>>`
4) rebase again and try not to mess up this time
@rahearn
rahearn / find_in_jar.sh
Created September 13, 2012 14:08
Search through a directory of jar files for a class
#!/bin/sh
if [ $# -eq 0 ]; then
search_for="."
else
search_for=$1
fi
for file in `find . -type f -name "*.jar"`; do
echo "Scanning $file..."