Skip to content

Instantly share code, notes, and snippets.

View wlangstroth's full-sized avatar

Will Langstroth wlangstroth

View GitHub Profile
@wlangstroth
wlangstroth / keybase.md
Created January 15, 2015 20:45
keybase

Keybase proof

I hereby claim:

  • I am wlangstroth on github.
  • I am wlangstroth (https://keybase.io/wlangstroth) on keybase.
  • I have a public key whose fingerprint is E2F2 215B AA83 1547 A87E E85F 69DF E208 FA87 7968

To claim this, I am signing this object:

require_relative '../test_helper'
class ThingsControllerTest < ActionController::TestCase
setup do
@thing = things(:default)
end
def test_index
things = [things(:default)]
require_relative '../test_helper'
class ThingTest < ActiveSupport::TestCase
def test_fixtures
Thing.all.each do |thing|
assert thing.valid?, thing.errors.inspect
end
end
class Thing < ActiveRecord::Base
# == Constants ==========================================================
CONSTANTS = %w[ thing1 thing2 ]
# == Attributes =========================================================
attr_accessor :attribute
@wlangstroth
wlangstroth / thing_controller.rb
Last active December 28, 2015 16:58
Jack-style controller
class ThingsController < ActiveController
before_action :build_thing, only: [:new, :create]
before_action :load_thing, only: [:show, :edit, :update, :destroy]
def index
@thing = Thing.page(params[:page])
end
def show
render
@wlangstroth
wlangstroth / rule_test.rb
Created February 8, 2013 04:03
Test of Rule object
require "minitest_helper"
class RuleTest < MiniTest::Unit::TestCase
def setup
end
def teardown
end
def test_stuff
@wlangstroth
wlangstroth / rule.rb
Created February 8, 2013 04:03
Object under test
class Rule
def self.setters(*method_names)
method_names.each do |name|
send :define_method, name do |data|
instance_variable_set "@#{name}".to_sym, data.
end
end
end
@wlangstroth
wlangstroth / minitest_helper.rb
Created February 8, 2013 04:01
MiniTest helper using mixed formats
# test/minitest_helper.rb
require "turn/autorun"
require "minitest/spec"
require "minitest/autorun"
Turn.config do |c|
c.format = :pretty
end
@wlangstroth
wlangstroth / Rakefile
Created February 8, 2013 02:06
Mixed Testing: MiniTest Unit and Spec
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << "lib"
t.libs << "test"
t.pattern = "test/*_test.rb"
end
@wlangstroth
wlangstroth / shell_games.sh
Created November 21, 2012 13:20
Quora thread snippets
cat a b | sort | uniq > c # c is a union b
cat a b | sort | uniq -d > c # c is a intersect b
cat a b b | sort | uniq -u > c # c is set difference a - b
find . -type f -ls
find . -name \*.py | xargs grep some_function
cat hosts | xargs -I{} ssh root@{} hostname
cat access.log | egrep -o 'acct_id=[0-9]+' | cut -d= -f2 | sort | uniq -c | sort -rn