Skip to content

Instantly share code, notes, and snippets.

@myronmarston
myronmarston / observer.md
Created November 5, 2015 23:26 — forked from pnc/observer.md
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
require "sequel"
# Connect to the DB to make sequel happy. It expects a DB connection when you subclass Sequel::Model
DB = Sequel.sqlite
# Use the module to avoid naming collisions with other specs.
module LearnSequelModelSpec
# Where can I safely declare this class without specifying
# the database for it?!
@myronmarston
myronmarston / queues.rb
Last active January 4, 2016 01:39 — forked from dlecocq/queues.rb
➜ 8549841 git:(master) ✗ ruby queues.rb
Popping before put
popped job:
popped job:
popped job:
popped job:
popped job:
popped job:
popped job:
popped job:
# A sample Gemfile
source "http://rubygems.org"
gem 'vcr'
gem 'fakefs'
gem 'typhoeus'
gem 'fakeweb'
gem 'rspec'
gem 'rr'
@myronmarston
myronmarston / test_it.rb
Created August 7, 2012 02:18 — forked from jrochkind/test_it.rb
VCR, WebMock, HTTPClient weirdness
require 'httpclient'
require 'vcr'
require 'webmock'
require 'test/unit'
# To allow us to do real HTTP requests in a VCR.turned_off, we
# have to tell webmock to let us.
WebMock.allow_net_connect!
VCR.configure do |c|
@myronmarston
myronmarston / triangle.rb
Created June 29, 2012 17:59 — forked from brenfrow/triangle.rb
triangle
TriangleError = Class.new(ArgumentError)
Triangle = Struct.new(:x, :y, :z) do
def initialize(*args)
super
validate
end
def type
TYPES.fetch(uniq_side_lengths)
@myronmarston
myronmarston / some_spec.rb
Created April 16, 2012 15:00 — forked from tommeier/some_spec.rb
VCR with placeholders
use_vcr_cassette 'some/cassette', :tag => :bad_staging_api
@myronmarston
myronmarston / some_spec.rb
Created March 20, 2012 23:40 — forked from stevenharman/some_spec.rb
Using Rspec's "let" inside an "it" block. Crazy? Yes. Useful? Occasionally.
describe "#mentions_story?" do
subject { described_class.new(file) }
let(:file) { "COMMIT_EDITMSG" }
def set_file_contents(text)
File.stub(:read).with(file) { example_commit_message(text) }
end
context "commit message contains the special Pivotal Tracker story syntax" do
@myronmarston
myronmarston / my_class_spec.rb
Created March 4, 2012 22:44 — forked from pat/gist:1947369
Using rspec-fire?
# My normal approach:
require './path/to/my_class'
describe MyClass do
let(:my_class) { MyClass.new }
describe '#add_widget' do
it "makes a widget using OtherClass" do
other_class = fire_replaced_class_double("OtherClass")
other_class.should_receive(:make_widget!)
@myronmarston
myronmarston / gist:1684632
Created January 26, 2012 19:42 — forked from justinko/gist:1684051
Methods to aid in testing without loading the Rails environment
def stub_model(model_name)
stub_class model_name, ActiveRecord::Base
end
def stub_class(class_name, super_class = Object)
stub_module class_name, Class.new(super_class)
end
def stub_module(module_name, object = Module.new)
module_name = module_name.to_s.camelize