Skip to content

Instantly share code, notes, and snippets.

Avatar

Pete Yandell notahat

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am notahat on github.
  • I am notahat (https://keybase.io/notahat) on keybase.
  • I have a public key ASBqO0GTuXC19c1Vf9IeExNNmrbDfTmw47SxvTu6G-P3BAo

To claim this, I am signing this object:

View gist:7324a2b0f8e40bfd71a3
$ ping 111.118.175.56
PING 111.118.175.56 (111.118.175.56): 56 data bytes
64 bytes from 111.118.175.56: icmp_seq=0 ttl=55 time=15.581 ms
64 bytes from 111.118.175.56: icmp_seq=1 ttl=55 time=17.552 ms
64 bytes from 111.118.175.56: icmp_seq=2 ttl=55 time=17.283 ms
^C
--- 111.118.175.56 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 15.581/16.805/17.552/0.873 ms
@notahat
notahat / gist:c72cee07f9a74e61a2d0
Last active Aug 29, 2015
Private classes in Ruby, version 2
View gist:c72cee07f9a74e61a2d0
module PrivateClass
def self.included(mod)
*parent, child = mod.name.split("::")
Object.const_get(parent.join("::")).private_constant(child)
end
end
module Container
class PublicThing
def hello
View keybase.md

Keybase proof

I hereby claim:

  • I am notahat on github.
  • I am notahat (https://keybase.io/notahat) on keybase.
  • I have a public key whose fingerprint is A466 A52F 204A DE5E 9F85 8F1B C009 0778 6D7E E91A

To claim this, I am signing this object:

View gist:c84e1784893d31f4e594
module Container
class PublicThing
def hello
PrivateThing.new.hello
end
end
class PrivateThing
def hello
"Hello, world!"
View agent-setup.sh
# On a new ubuntu 14.04 box, as root, with the following variables
# export BUILDBOX_AGENT_NAME="buildbox-agent-N"
# export BUILDBOX_AGENT_ACCESS_TOKEN="<your token here>"
# export BUILDBOX_AGENT_SSH_PRIVATE_KEY="<an ssh private key>"
# export BUILDBOX_AGENT_SSH_PUBLIC_KEY="<an ssh public key>"
# Make tmp totally in memory
echo "none /tmp tmpfs size=4g 0 0" >> /etc/fstab
mount /tmp
View gist:5166594
class PagingEnumerator < Enumerator
def initialize(&block)
super do |yielder|
page = 0
loop do
items = block.call(page)
break if items.empty?
items.each {|item| yielder.yield(item) }
page += 1
@notahat
notahat / valid.rb
Created Oct 11, 2012
Testing fail?
View valid.rb
# I have a class that delegates functionality to a couple of objects that it
# constructs. I want to test this in isolation. I want to make sure that the
# objects are constructed with the right arguments. I also want to make sure
# that the results from the objects are handled correctly.
#
# I'm finding it hard to structure the code and test in a way that isn't
# cumbersome. What's below works, but it feels like a lot of stubbing and setup
# for something the should be simpler.
#
# Anyone got a better approach for this?
View this_should_fail.rb
class Dependency
def self.foo
puts "Foo"
end
def self.bar
puts "Bar"
end
end
@notahat
notahat / capybara_support.rb
Created May 24, 2011
Make RSpec and Capybara give backtraces for controller exceptions
View capybara_support.rb
# Put this in spec/support
# Make sure we get stack traces for controller and view exceptions.
ActionController::Base.class_eval do
def rescue_action_without_handler(exception)
raise exception
end
end