Skip to content

Instantly share code, notes, and snippets.

View musical_era.rb
class Range
def overlap(other)
[self.begin, other.begin].max .. [self.end, other.end].min
end
end
def musical_era_alive_in(start_life, end_life)
[
['Medieval', 476..1400],
['Renaissance', 1400..1600],
View -
commit 604fd2cb227d92bed1b738e71feb4ff5360f4491
Author: Matthew Draper <matthew@trebex.net>
Date: Fri Feb 19 07:50:42 2016 +1030
Use a semaphore to signal message availability
The Event hack was too much of a hack: on actually thinking about it,
there's a rather obvious race.
diff --git a/actioncable/test/client_test.rb b/actioncable/test/client_test.rb
View -
diff --git a/actioncable/test/client_test.rb b/actioncable/test/client_test.rb
index d30c381..2662921 100644
--- a/actioncable/test/client_test.rb
+++ b/actioncable/test/client_test.rb
@@ -54,7 +54,7 @@ def initialize(port)
@ws = Faye::WebSocket::Client.new("ws://127.0.0.1:#{port}/")
@messages = Queue.new
@closed = Concurrent::Event.new
- @has_messages = Concurrent::Event.new
+ @has_messages = Concurrent::Semaphore.new(0)
View -
diff --git a/lib/sprockets/manifest.rb b/lib/sprockets/manifest.rb
index e514ebb..9797575 100644
--- a/lib/sprockets/manifest.rb
+++ b/lib/sprockets/manifest.rb
@@ -165,6 +165,8 @@ def compile(*args)
concurrent_compressors = []
concurrent_writers = []
+ pool = Concurrent::FixedThreadPool.new(5)
+
@matthewd
matthewd / fallout.rb
Last active Apr 4, 2019 — forked from tenderlove/fallout.rb
hack fallout terminals
View fallout.rb
##
# Program to help you hack terminals in Fallout
#
# Usage:
#
# Run this program with a '/' separated list of possible words, and
# (once you've made a guess) another '/' separated list of words and
# scores where the word and score are separated by a ':'
#
# In this example, the words shown in my terminal were:
View use-controller.diff
diff --git a/spec/helpers/application_helper/toolbar_builder_spec.rb b/spec/helpers/application_helper/toolbar_builder_spec.rb
index 546ce2b..81ce5f3 100644
--- a/spec/helpers/application_helper/toolbar_builder_spec.rb
+++ b/spec/helpers/application_helper/toolbar_builder_spec.rb
@@ -3,11 +3,14 @@
describe ApplicationHelper do
before do
controller.send(:extend, ApplicationHelper)
- self.class.send(:include, ApplicationHelper)
end
View -
diff --git a/vmdb/lib/acts_as_ar_model.rb b/vmdb/lib/acts_as_ar_model.rb
index e23a20f..d6838a8 100644
--- a/vmdb/lib/acts_as_ar_model.rb
+++ b/vmdb/lib/acts_as_ar_model.rb
@@ -1,16 +1,3 @@
-class ActsAsArModelColumn < ActiveRecord::ConnectionAdapters::Column
- attr_reader :options
-
- def initialize(name, options)
- type = options.kind_of?(Symbol) ? options : options[:type]
@matthewd
matthewd / post-checkout.sh
Created Jun 14, 2014
Per-branch Gemfile.lock
View post-checkout.sh
#!/bin/bash
if [ "$3" = 1 ]; then
old_branch="`git name-rev --name-only --no-undefined "$1" | cut -d'~' -f1`"
new_branch="`git name-rev --name-only --no-undefined "$2" | cut -d'~' -f1`"
if [ "$old_branch" != "$new_branch" ]; then
mv -f "Gemfile.lock" ".Gemfile/lock.$old_branch"
if [ -f ".Gemfile/lock.$new_branch" ]; then
mv -f ".Gemfile/lock.$new_branch" "Gemfile.lock"
@matthewd
matthewd / gist:b74b0de5244b2a95952b
Last active Aug 29, 2015
gsub forwarding with $1
View gist:b74b0de5244b2a95952b
class X < String
def evil_call(meth, args, block, &wrap_block)
block.binding.eval(<<-END, __FILE__, __LINE__+1).call(to_str, meth, args, wrap_block)
lambda do |str, meth, args, block|
str.send(meth, *args, &block)
end
END
end
def gsub(*args, &block)
View keybase.md

Keybase proof

I hereby claim:

  • I am matthewd on github.
  • I am matthewd (https://keybase.io/matthewd) on keybase.
  • I have a public key whose fingerprint is 4BBC 6089 979B 399C AD3C 246D 9C0D 2BE6 590D 2B86

To claim this, I am signing this object:

You can’t perform that action at this time.