Skip to content

Instantly share code, notes, and snippets.

pete higgins phiggins

Block or report user

Report or block phiggins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:9602569
for i in app/models/*.rb ; do sed "s/\s\+def \(self\.\)\?\([^( ]*\).*\|\s\+scope :\([^,]*\).*/\2\3/;tx;d;:x" $i | while read j ; do echo $(grep -R $j app/ lib/ config/ | wc -l) $j ; done ; done | sort -rn
View gist:8964349
> class Taco
> def self.delicious? ; true ; end
> singleton_class.send :alias_method, :yummy?, :delicious?
> end
=> #<Class:Taco>
> Taco.yummy?
=> true
@phiggins
phiggins / gist:8681048
Created Jan 29, 2014
Nand2Tetris from the commandline
View gist:8681048
pete@balloon:~/projects/nand2tetris/phiggins/01$ pwd
/home/pete/projects/nand2tetris/phiggins/01
pete@balloon:~/projects/nand2tetris/phiggins/01$ ../../tools/HardwareSimulator.sh ~/projects/nand2tetris/phiggins/01/Mux4Way16.tst
End of script - Comparison ended successfully
pete@balloon:~/projects/nand2tetris/phiggins/01$
View gist:8511474
require 'spec_helper'
describe User do
it "should blow up" do
expect(User).to receive(:create!).and_raise(ActiveRecord::RecordNotUnique)
end
end
=begin
Fails with:
View gist:8511373
Failure/Error: expect(View).to receive(:create!).and_raise(ActiveRecord::RecordNotUnique)
ArgumentError:
wrong number of arguments (0 for 2)
View defs.rb
module Kernel
def method_a
:foo
end
end
def method_b
:bar
end
@phiggins
phiggins / gist:6691237
Created Sep 24, 2013
Kernel require monkeypatch
View gist:6691237
module Kernel
def required(arg=nil)
method = caller_locations(1,1)[0].label
raise ArgumentError.new("required parameter #{arg.to_sym.inspect + ' ' if arg}not passed to method #{method}")
end
end
View json_dump.rb
require 'net/http'
require 'json'
require 'uri'
require 'pp'
uri = URI(ARGV[0])
pp JSON.parse(Net::HTTP.get_response(uri).body)
@phiggins
phiggins / ar_inverse_of_test.rb
Last active Dec 16, 2015
AR inverse_of doesn't work after creation of associated things.
View ar_inverse_of_test.rb
require 'active_record'
require 'sqlite3'
require 'minitest/autorun'
puts "ActiveRecord: #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => ":memory:"
)
@phiggins
phiggins / gist:5357237
Created Apr 10, 2013
rdoc's rake newb without kpeg
View gist:5357237
[11:30:26 rdoc (master u=)]$ gem list
*** LOCAL GEMS ***
bundler (1.3.5, 1.1.5, 1.1.3)
hoe (3.5.3)
rake (10.0.4, 0.9.2.2)
rubygems-bundler (1.1.1, 1.0.7, 1.0.1, 1.0.0)
rvm (1.11.3.5)
[11:30:29 rdoc (master u=)]$ rake newb
You can’t perform that action at this time.