Skip to content

Instantly share code, notes, and snippets.

Will Langstroth wlangstroth

View GitHub Profile
View keybase.md

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:

View things_controller_test.rb
require_relative '../test_helper'
class ThingsControllerTest < ActionController::TestCase
setup do
@thing = things(:default)
end
def test_index
things = [things(:default)]
View thing_test.rb
require_relative '../test_helper'
class ThingTest < ActiveSupport::TestCase
def test_fixtures
Thing.all.each do |thing|
assert thing.valid?, thing.errors.inspect
end
end
View thing_model.rb
class Thing < ActiveRecord::Base
# == Constants ==========================================================
CONSTANTS = %w[ thing1 thing2 ]
# == Attributes =========================================================
attr_accessor :attribute
@wlangstroth
wlangstroth / thing_controller.rb
Last active Dec 28, 2015
Jack-style controller
View thing_controller.rb
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 Feb 8, 2013
Test of Rule object
View rule_test.rb
require "minitest_helper"
class RuleTest < MiniTest::Unit::TestCase
def setup
end
def teardown
end
def test_stuff
@wlangstroth
wlangstroth / rule.rb
Created Feb 8, 2013
Object under test
View rule.rb
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 Feb 8, 2013
MiniTest helper using mixed formats
View minitest_helper.rb
# 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 Feb 8, 2013
Mixed Testing: MiniTest Unit and Spec
View Rakefile
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 Nov 21, 2012
Quora thread snippets
View shell_games.sh
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
You can’t perform that action at this time.