Skip to content

Instantly share code, notes, and snippets.

module Hamster
def self.vector(*args)
Vector.new(args)
end
class Vector < ::Array
alias add <<
end
end
require 'yaml'
class X
def self.y
YAML.load_file("abc")
end
end
RSpec.describe X do
it 'works' do
@myronmarston
myronmarston / spec_helper.rb
Created May 28, 2017 18:29
How to make RSpec fail if anything outputs
RSpec::Matchers.define_negated_matcher :avoid_outputting, :output
RSpec.configure do |config|
config.around do |ex|
expect(&ex).to avoid_outputting.to_stdout.and avoid_outputting.to_stderr
end
end
@myronmarston
myronmarston / subscription.rb
Created March 8, 2012 18:17
How we do migrations with Ripple
require 'versionable'
class Subscription
include Ripple::Document
include Versionable
current_schema_version 2
migrate_schema do |data|
self.schema_version = 2
@myronmarston
myronmarston / stack_overflow_debugger.rb
Created June 1, 2015 22:51
Stack overflow debugger (since Ruby doesn't provide the whole stack in this case)
max_stack_frames = 500
TooManyStackFrames = Class.new(StandardError)
TracePoint.new(:call) do |tp|
if caller.size >= max_stack_frames
raise TooManyStackFrames, "Stack has exceeded #{max_stack_frames} frames"
end
end.enable
@myronmarston
myronmarston / bundle-standalone-repro.sh
Created January 31, 2014 22:07
Repro script for bundle install --standalone failure
#!/bin/bash
set -ex
mkdir -p /tmp/repro-bundle-standalone-failure
cd /tmp/repro-bundle-standalone-failure
bundle env
# Bundler 1.5.2
# Ruby 1.9.3 (2013-06-27 patchlevel 448) [x86_64-darwin12.4.0]
@myronmarston
myronmarston / use_httpclient.rb
Created June 4, 2012 20:09
Demonstrating of why HTTPClient response headers are serialized as base64 strings when using psych
require 'httpclient'
client = HTTPClient.new
response = client.request(:get, "http://google.com/", nil, '', {})
puts "Headers:"
response.headers.each do |key, value|
puts "#{key} (#{key.encoding.name}): #{value} (#{value.encoding.name})"
end
require 'yaml'
string = "a string".force_encoding("ASCII-8BIT")
puts YAML.dump(string)
@myronmarston
myronmarston / cancel_all_failed.rb
Created June 25, 2014 20:32
Cancel all failed jobs in qless
def cancel_all_failed_jobs(redis)
qless = Qless::Client.new(redis: redis)
qless.jobs.failed.each do |key, count|
puts "#{key}: #{count}"
while (jobs = qless.jobs.failed(key, 0, 1000).fetch("jobs")).any?
qless.bulk_cancel(jobs.map(&:jid))
end
end
end
From ff210553f1a66db745a32224ff69b57073f953c6 Mon Sep 17 00:00:00 2001
From: Myron Marston <myron.marston@gmail.com>
Date: Mon, 27 Feb 2017 15:01:27 -0800
Subject: [PATCH] WIP: add monitor statements.
---
lib/mix/lib/mix/dep/converger.ex | 120 ++++++++++++++++++++++-----------------
1 file changed, 67 insertions(+), 53 deletions(-)
diff --git a/lib/mix/lib/mix/dep/converger.ex b/lib/mix/lib/mix/dep/converger.ex