Skip to content

Instantly share code, notes, and snippets.

@floehopper
floehopper / README.markdown
Created December 3, 2010 18:12
Generate, send, receive, and parse a multipart/related HTTP POST request in Ruby

Setup Apache to listen on a port and log incoming HTTP requests including body

terminal 1

$ cat /etc/apache2/sites-enabled/mms-test 
Listen 50690
LogLevel debug
DumpIOInput On
# DumpIOOutput On

$ sudo tail -f /var/log/apache2/error.log | grep "mod_dumpio.c(74)" | sed "s/.*HEAP.: //"

.bundle
db/*.sqlite3
log/*.log
tmp/**/*
@floehopper
floehopper / test.rb
Created January 30, 2011 17:08 — forked from benpickles/test.rb
require 'test/unit'
require 'rubygems'
require 'mocha'
class Foo
def self.say_hello_to(name)
Bar.hello(name)
end
end
@floehopper
floehopper / code-closure.sh
Created February 1, 2011 11:05
Hacked together script to measure the closure of code (may well not be robust)
git log --pretty=format: --numstat | sed '/files changed/d' | sed '/^$/d' | cut -f3 | sort | uniq -c | sort
@floehopper
floehopper / ninety-day-reminder-sms.rb
Created February 9, 2011 16:03
We deleted these 90-day reminder SMSes from production
def Resque.next_delayed_timestamp
timestamp = redis.zrangebyscore(:delayed_queue_schedule, '-inf', 100.days.from_now.to_i, 'limit', 0, 1).first
timestamp.to_i unless timestamp.nil?
end
jobs = (0..99).map do |index|
timestamp = Resque.next_delayed_timestamp
if timestamp
Resque.next_item_for_timestamp(timestamp)
end
@floehopper
floehopper / irb-utf8.sh
Created February 15, 2011 20:09
Install Ruby Enterprise Edition with an IRB that displays UTF-8 characters sensibly
rvm install ree-1.8.7-2010.02 -C --enable-shared,--with-readline-dir=`brew --prefix`
@floehopper
floehopper / leakygems.rb
Created March 14, 2011 10:56
Detects changes made by an arbitrary chunk of Ruby code that may leak into surrounding code with unpleasant consequences
RUBY_PATH = File.expand_path('../../lib/ruby/1.8', `which ruby`)
module Leakygems
class << self
def method_metadata(method)
begin
file = method.__file__
line = method.__line__
if File.expand_path(file).include?(RUBY_PATH)
type = "ruby"
class Jobs::IncomingMessage
class << self
def encode(content)
content = content.gsub(/\215./) { |match| GSM_ESCAPED_CHARACTERS[match[1]] }
content = Iconv.conv("UTF-8", "HP-ROMAN8", content)
content.gsub!(EURO_TOKEN, "\342\202\254")
content
end
def decode(content)
@floehopper
floehopper / eastcoast-train-positions.html
Created April 25, 2011 08:22
East Coast Train Positions
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map = null;
function initializeMap() {
$.getJSON("http://www.ombord.info/api/jsonp/position/?callback=?", function(gpsData) {
var currentPosition = new google.maps.LatLng(gpsData.latitude, gpsData.longitude);
map = new google.maps.Map(document.getElementById("map_canvas"), {
@floehopper
floehopper / attempt-to-reproduce-problem.txt
Created April 28, 2011 16:14
Attempt to reproduce problem mentioned by Marc Love in Mocha Issue #18
$ ruby -v # => ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.4.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02
$ rails -v # => Rails 3.0.7
$ cd /tmp
$ rails new mocha-issue-18
$ cd mocha-issue-18
$ cat <<EOF >>Gemfile
group :test do
gem 'mocha', :require => false