Skip to content

Instantly share code, notes, and snippets.

require "tmpdir"
require "securerandom"
require "set"
REPO = ARGV[0] || raise("need repo")
EMAILS = ARGV[1...]
EMAIL_MAP = {
"old-email@example.com" => "new-email@example.com"
}
@dan-manges
dan-manges / _pub_sub.md
Last active April 12, 2023 13:45
in process pub sub implementation in Ruby

Ruby Pub/Sub

This is an implementation of in-process pub/sub in Ruby with type checking at runtime.

It only allows subscribing to events with jobs to ensure that the subscriber blocks are fully asynchronous and cannot cause runtime exceptions.

This is the approach we use in production at rwx

@dan-manges
dan-manges / passenger_status.rb
Created October 28, 2008 07:10
munin plugin for passenger
#!/usr/bin/env ruby
def output_config
puts <<-END
graph_category App
graph_title passenger status
graph_vlabel count
sessions.label sessions
max.label max processes

Testing

def foo
end
@dan-manges
dan-manges / app.coffee
Created June 9, 2011 04:15
mongrel2 timeout handler
http = require 'http'
m2node = require 'm2node'
server = http.createServer((req, res) ->
console.log("#{req.method} #{req.url}")
sendResponse = ->
res.writeHead(200, {'Content-Type': 'text/plain'})
res.end('Hello World\n')
match = req.url.match(/sleep.(\d+)/)
if match
def fib(n)
if n <= 2
1
else
fib(n-1) + fib(n-2)
end
end
def fibsum(n)
sum = 0
def mask(x)x[0,6]+'*'*(x.size-10)+x[-4..-1]end
def self.luhn_valid?(number)
return false unless number.to_s =~ /\A\d+\z/
digits = number.scan(/\d/).map(&:to_i).reverse
digits.each_with_index do |digit, index|
if index.odd?
digits[index] = (digit >= 5 ? digit * 2 - 9 : digit * 2)
end
end
digits.sum % 10 == 0
end
def luhn?(number)
digits = number.scan(/\d/).map { |d| d.to_i }.reverse
digits.each_with_index do |digit, index|
if index % 2 == 1
digits[index] = (digit >= 5 ? digit * 2 - 9 : digit * 2)
end
end
digits.inject(0) { |a,b| a + b } % 10 == 0
end
def luhn10?(number)
return false unless number.to_s =~ /\A\d+\z/
digits = number.scan(/\d/).map(&:to_i).reverse
digits.each_with_index do |digit, index|
if index.odd?
digits[index] = (digit >= 5 ? digit * 2 - 9 : digit * 2)
end
end
digits.sum % 10 == 0
end