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 / 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
@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 / 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 / .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 / .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
#
#!/usr/bin/env ruby
require "thor"
require "yaml"
require "open3"
class App < Thor
MAILLOG_REGEX = /^.+:(?<timestamp>\w+\s+\d+ \d\d+:\d\d:\d\d) (?<server>[^\s]+) .+ to=<(?<to>[^>]+)>.+ relay=(?<relay>[^,]+),.+status=(?<status>.+)$/
# other mail analysis-type stuff...
@nbfritz
nbfritz / metaclass_instance_variables.rb
Last active August 29, 2015 14:04
Interesting experimentation with ruby metaclasses
require 'minitest/autorun'
class Monkey
@@m1 = "monkey"
class << self
attr_accessor :m2
end
def self.m1=(m)
@nbfritz
nbfritz / string_timings.rb
Created September 4, 2014 12:22
Using + to spread strings across multiple lines is slower than using \
def timer
start_time = Time.now
1_000_000.times do
yield
end
Time.now - start_time
end
time_a = timer do
x = "this this this this this this this this this this this this this this this " +
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nbfritz
nbfritz / Vagrantfile
Last active August 29, 2015 14:24
Rails Dev Environment vagrant file
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/vivid64"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end