Skip to content

Instantly share code, notes, and snippets.

@jwhiteman
jwhiteman / renting_zero.rb
Last active March 14, 2017 04:23
quick connection pool example
require "thread"
require "connection_pool"
require "pp"
NUM_CLIENTS = 9
MAX_AT_A_TIME = 3
TIMEOUT = 10
JOB_TIME = 3
# we'll let people lease access to zero
@jwhiteman
jwhiteman / condvar_broadcast.rb
Created March 18, 2017 01:19
ruby condition variable and broadcast
m = Mutex.new
c = ConditionVariable.new
tg = ThreadGroup.new
t = 5.times.map do |n|
tg.add(Thread.new do
print "starting #{n}\n"
m.synchronize do
@jwhiteman
jwhiteman / di.rb
Created December 3, 2017 22:16
Dumb DI container
class DIContainer
def configure
yield self
end
def method_missing(key, val)
if key =~ /=$/
key = key.to_s.chop
(class << self; self; end).class_eval do
attr_accessor key
@jwhiteman
jwhiteman / acl2.lisp
Created January 26, 2024 19:25
Code from Paul Graham's ANSI Common Lisp
; The code in this file was mechanically extracted from the TeX
; source files of _Ansi Common Lisp_, except for bst-remove and
; bst-delete and their subroutines, which replace broken versions
; in the book.
; If you have questions or comments about this code, or you want
; something I didn't include, send mail to lispcode@paulgraham.com.
; This code is copyright 1995 by Paul Graham, but anyone who wants
; to use it is free to do so.