Skip to content

Instantly share code, notes, and snippets.

View nbfritz's full-sized avatar

Nathan Fritz nbfritz

  • Spring Hill, TN
View GitHub Profile
@nbfritz
nbfritz / .slate
Last active December 29, 2015 02:39
My configuration for https://github.com/jigish/slate
# Configuration file for the slate window management tool for OS X.
# For more information see: https://github.com/jigish/slate
#
# Config by Nathan Fritz. Updated 2014-01.
# settings {{{
#
# instruct slate to base nudges and resizes on current screensize and to
# use an 8x8 grid for the layout popup
#
@nbfritz
nbfritz / .go_shortcuts
Last active December 27, 2015 00:09
Simple go-tool clone for pure bash. Great for when I want easy directory jump capabilities without wanting to install python.
# put the following function into .bash_profile or .bashrc to evaluate this file
# function go { `awk -v val=^$1$ '$1!~/^[:space:]*#/ && $1~val { print "cd "$2 }' ~/.go_shortcuts`; }
sample /some/deep/directory/to/link/to
@nbfritz
nbfritz / tapper.rb
Created April 13, 2013 11:12
Scary awesome.
class Tapper
attr_reader :eavesdroppers
def initialize(source, *eavesdroppers)
@source = source
@eavesdroppers = eavesdroppers
end
def method_missing(method, *args)
if @source.respond_to?(method)
@nbfritz
nbfritz / random_number_spec.rb
Last active December 16, 2015 02:29
This test should fail every time. But note the random numbers it fails with when running standalone and through spork.
require 'spec_helper'
describe 'Random numbers' do
it 'fails every time' do
numbers = 10.times.map { rand(100) }
numbers.join(', ').should eq 'the Tardis'
end
end
@nbfritz
nbfritz / ordered_spec.rb
Last active December 16, 2015 01:19
This is a horribly contrived example of a set of specs that only pass if run in the order they're presented. They'll fail if run in the opposite order.
require 'spec_helper'
describe 'unintended sequence' do
before(:all) do
@x = {a: 1, b: 2}
end
it 'modifies the array' do
@x[:a] = 2
@x[:a].should eq 2
# settings {{{
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
alias gridSize 8,8
alias c (screenSizeX/8)
alias r (screenSizeY/8)
#}}}
@nbfritz
nbfritz / hash_post_2_b.rb
Created December 14, 2012 15:37
Ruby Hash Post - Part 2: ranges CAN work as keys
STATUS_TYPES = Hash.new {|this_hash,missing_key|
found_key = this_hash.keys.find {|this_key| this_key.class == Range && this_key.include?(missing_key) }
found_key ? this_hash[missing_key] = this_hash[found_key] : :undefined
}.merge({
200..208 => :success,
500..511 => :server_error
})
STATUS_TYPES.keys # => [200..208, 500..511]
STATUS_TYPES[200] # => :success
@nbfritz
nbfritz / hash_post_2_a.rb
Created December 14, 2012 15:36
Ruby Hash Post - Part 2: ranges as keys don't work
STATUS_TYPES = {
200..208 => :success,
500..511 => :server_error
}
STATUS_TYPES[200] # => nil
@nbfritz
nbfritz / hash_post_1_f.rb
Created December 14, 2012 15:28
Ruby Hash Post - Part 1: better message lookup
STATUS_MESSAGES = Hash.new(:undefined).merge({
200 => :ok,
201 => :created,
202 => :accepted
}
STATUS_MESSAGES[200] # => :ok
STATUS_MESSAGES[999] # => :undefined
@nbfritz
nbfritz / hash_post_1_e.rb
Created December 14, 2012 15:27
Ruby Hash Post - Part 1: pretty good status lookup
STATUS_MESSAGES = {
200 => :ok,
201 => :created,
202 => :accepted
}
STATUS_MESSAGES[200] # => :ok
STATUS_MESSAGES[999] # => nil