Skip to content

Instantly share code, notes, and snippets.

View yaauie's full-sized avatar

Ry Biesemeyer yaauie

View GitHub Profile

Keybase proof

I hereby claim:

  • I am yaauie on github.
  • I am yaauie (https://keybase.io/yaauie) on keybase.
  • I have a public key whose fingerprint is 0FA5 1969 4D7F 08F0 083F A1B6 CF2C 1D14 E392 052D

To claim this, I am signing this object:

    # @return [Proc]
    def nested_around_hooks
      final_hook = lambda { perform_job }
      hooks[:around].reverse.inject(final_hook) do |last_hook, hook|
        lambda { perform_hook(hook) { last_hook.call } }
      end
    end
export PATH=$HOME/.bin:$PATH
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="auto"
PS1=' \u@\h \W$(__git_ps1 " (%s)") '
PS1="\n╭ <\e[1;34m\]$PS1\[\e[0m>\n╰ $ "
# load bash_completion
if [ -f $(brew --prefix)/etc/bash_completion ]; then
@yaauie
yaauie / gist:80770b162ad095a6e1e0
Created May 8, 2014 23:28
DataMapper InMemoryAddapter that respects your keys.
module DataMapper
module Adapters
# DataMapper.setup(:default, 'in_memory_with_keys::')
class InMemoryWithKeysAdapter < InMemoryAdapter
def create(resources)
records = records_for(resources.first.model)
resources.each do |resource|
key_names = resource.model.properties(self.name).select(&:key?).map(&:name).map(&:to_s)
# Get reasonable CLI confirmation before continuing.
#
# @param text [String] - the descriptive text
# @param options [Hash{Symbol=>Object}]
# @option options [Boolean] :default - the default action (false)
# @option options [#puts] :out - the IO on which to puts output ($stderr)
# @option options [#readline] :in - the IO on which to readline input ($stdin)
# @option options [String] :prompt - the prompt string ("ok?")
#
# @example
@yaauie
yaauie / sleepy.rb
Created May 21, 2014 07:05
The following demonstrates that Thread#wakeup can be used in a signal trap to wake up the thread that had control when the signal was raised. I have verified same behaviour in MRI (1.8.7, 1.9.3, 2.0.1, 2.1.1), JRuby (1.7.4, 1.9 mode), Rubinius (2.2.1), but testing signals is hard and I'm unsure how to verify this programatically.
$ ruby ~/Desktop/sleepy.rb
signals registered.
^CCAUGHT INT!
4
# encoding: utf-8
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Ryan Biesemeyer <wtf@yaauie.com>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
@yaauie
yaauie / yaauie-semaphore.rb
Last active August 29, 2015 14:05
A quick spike on a one-size-fits-all semaphore in ruby; ordering is *not* guaranteed when write locks are released.
require 'thread' # Mutex
require 'monitor' # MonitorMixin::ConditionVariable
# A semaphore that supports Read Locks, Write Locks, and Sized Semaphores
class Yaauie::Semaphore
INFINITY = Float::INFINITY
# @param options [Hash{Symbol=>Object}]
# @option options [Integer, INFINITY] :readers_max (INFINITY)
def initialize(options = {})
def time_thread_contention(options = {})
thread_count = options.fetch(:threads, 10)
iterations = options.fetch(:iterations, 10)
start_time = Time.now
iterations.times.each_slice(thread_count).to_a.transpose.map do |idxs|
Thread.new do
idxs.each do |idx|
yield
Thread.pass if idx.odd?
@yaauie
yaauie / resque-scheduler-find-delayed-job.rb
Last active August 29, 2015 14:05
Scan through all Resque Scheduler delayed jobs and emit the timestamps and payload of all matching jobs.
# @param search [String, Regexp]
# @yieldparam time [Time]
# @yieldparam payload [String]
# @yieldreurn [void]
# @return [void]
def find_delayed_jobs(search)
return enum_for(__method__, search) unless block_given?
min = 0
max = '+inf'