Skip to content

Instantly share code, notes, and snippets.

module EngineControllerPatch
def self.included(base)
@http_methods ||= [ :get, :post, :put, :patch, :delete ]
@http_methods.each { |http_method| patch_http_method http_method }
end
def self.patch_http_method(http_method)
define_method(http_method) do |action, parameters = nil, session = nil, flash = nil|
process_action(action, parameters, session, flash, http_method.to_s.upcase)
end
@backus
backus / 01_test.rb
Created May 17, 2015 02:56
Surprising return from `parent_name`
require 'active_support'
require 'active_support/core_ext'
require 'active_record'
require 'test/unit'
# Setup
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => ":memory:"
require 'factory_girl'
require 'faker'
class JsonStrategy # From http://git.io/vT8kC
def initialize
@strategy = FactoryGirl.strategy_by_name(:create).new
end
delegate :association, to: :@strategy
@backus
backus / Gemfile
Created July 11, 2015 07:06
Guard critics
source 'https://rubygems.org'
ruby '2.2.2'
group :development do
# Handle file system changes and run things
gem 'guard', '~> 2.12.4'
# Intelligently Autorun Tests
gem 'guard-rspec', '~> 4.2.0'
@backus
backus / rubocop.yml
Created July 27, 2015 03:35
Some of my rubocop preferences
AllCops:
Include:
- "**/*.rake"
- "**/Gemfile"
- "**/Rakefile"
Exclude:
- "vendor/**/*"
- "db/**/*"
DisplayCopNames: true
RunRailsCops: true
@backus
backus / reek-rubyspec.txt
Created September 30, 2015 05:58
reek + rubyspec
$ reek -v
reek 3.5.0
$ tree -d
.
├── command_line
│   ├── fixtures
│   └── shared
├── core
│   ├── argf
│   │   ├── fixtures
$ CI=true be mutant -j1 -I . -r mutant-freezer --use rspec 'Foo*'Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions: [Foo*]>
Integration: Mutant::Integration::Rspec
Expect Coverage: 100.00%
Jobs: 1
Includes: ["."]
Requires: ["mutant-freezer"]
(00/08) 100% - killtime: 0.00s runtime: 0.00s overhead: 0.00s
(07/08) 87% - killtime: 0.18s runtime: 1.01s overhead: 0.83s
Foo#bar:/Users/johnbackus/Dropbox/coding/gists/mutant-freezer.rb:13
@backus
backus / HackerSpace-Hackathon-p2.py
Created November 24, 2012 02:31
HackerSpace Hackathon Problem #2 - Retrieve Reddit’s top cat pictures from today, yesterday, the day before yesterday, and n days ago.
import urllib2
import json
import datetime
'''Constants'''
catSubreddits = ['cat','catpictures','cats','flyingcats','catgifs','lolcats']
''' Prompt for num days back '''
nDaysSet=False
while nDaysSet is not True:
---
Style/BarePercentLiterals:
EnforcedStyle: percent_q
SupportedStyles:
- percent_q
- bare_percent
@backus
backus / example.rb
Created November 18, 2015 03:24
Shoulda matchers `allow_value` bug
require 'active_model'
class Example
include ActiveModel::Model
validates :foo, inclusion: [1]
attr_accessor :foo
end