Skip to content

Instantly share code, notes, and snippets.

View msaffitz's full-sized avatar

Mike Saffitz msaffitz

View GitHub Profile
@msaffitz
msaffitz / boat.rb
Created September 14, 2020 23:43
Monte Carlo Dock Capacity Planning
#!/bin/ruby
BOAT_SIZES = [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
BOAT_COUNTS = [ 3, 3, 3, 4, 5, 6, 7, 5, 4, 4, 4, 4]
ALL_BOATS = BOAT_SIZES.zip(BOAT_COUNTS).map { |s,c| Array.new(c, s) }.flatten
BUFFER = 3 # Spacing between boats
MAX_SIZES = 23.upto(34) # Maximum length overall permitted to moore
ITERATIONS = 5000
@msaffitz
msaffitz / 0_reuse_code.js
Created April 17, 2016 18:48
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@msaffitz
msaffitz / mongodb.repo
Created November 30, 2013 02:11
mongo repository config
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
@msaffitz
msaffitz / gist:5818291
Last active December 18, 2015 17:28
Fix custom data for Mikandi
App.find('4f53c660fab0b800010000a5').conversations.where(record_id: {'$exists' => 1}).each do |c|
record = Record.find(c[:record_id])
next if record.data.blank? || c.person.blank?
c.person.custom_data ||= {}
c.person.custom_data.reverse_merge!(record.data)
c.person.save
end
@msaffitz
msaffitz / gist:2267068
Created March 31, 2012 17:46
Read current Bundler lockfile
IO.read(Bundler.default_lockfile)
@msaffitz
msaffitz / all_s3_objects.rb
Created December 7, 2011 20:34
Emit all objects in an S3 account
require 'aws-sdk'
puts "Connecting to S3 ... "
start_time = Time.now
s3 = AWS::S3.new(access_key_id: (ARGV[0] || ENV['S3_ACCESS_KEY']),
secret_access_key: (ARGV[1] || ENV['S3_SECRET_KEY']) )
s3.buckets.each do |bucket|
@msaffitz
msaffitz / extract_otz_images.rb
Created December 1, 2011 00:50
Extract OTZ images from a PG database and create them in the filesystem
require 'rubygems'
require 'pg'
require 'FileUtils'
def write_file(data, path, name)
return if data.nil? or data.empty?
return if File.exists?("#{path}/#{name}")
FileUtils.mkdir_p path
f = File.new("#{path}/#{name}", 'w')
f.write(PGconn.unescape_bytea(data))
@msaffitz
msaffitz / notifier.js
Created August 1, 2011 20:37
Hoptoad Notifier JS
var Hoptoad = {
VERSION : '0.1.0',
NOTICE_XML : '<?xml version="1.0" encoding="UTF-8"?><notice version="2.0"><api-key></api-key><notifier><name>hoptoad_notifier_js</name><version>0.1.0</version><url>http://hoptoadapp.com</url></notifier><error><class>EXCEPTION_CLASS</class><message>EXCEPTION_MESSAGE</message><backtrace>BACKTRACE_LINES</backtrace></error><request><url>REQUEST_URL</url><component>REQUEST_COMPONENT</component><action>REQUEST_ACTION</action></request><server-environment><project-root>PROJECT_ROOT</project-root><environment-name>production</environment-name></server-environment></notice>',
ROOT : window.location.protocol + '//' + window.location.host,
BACKTRACE_MATCHER : /^(.*)\@(.*)\:(\d+)$/,
backtrace_filters : [/notifier\.js/],
notify: function(error) {
var xml = escape(Hoptoad.generateXML(error));
var host = Hoptoad.host || 'hoptoadapp.com';