Skip to content

Instantly share code, notes, and snippets.

class NetworkLatency < Scout::Plugin
OPTIONS=<<-EOS
host:
label: Host
notes: The remote host to measure. Defaults to the default gateway if none is specified.
count:
label: Count
notes: Number of samples to take
default: 5
EOS
From 53402e071c7f9d4646bd98c5e5d5e97e69073f3a Mon Sep 17 00:00:00 2001
From: Eric Lindvall <[email protected]>
Date: Fri, 27 May 2011 12:46:00 -0700
Subject: [PATCH] Only deallocate the frame if it isn't NULL.
---
app_swift.c | 40 +++++++++++++++++++++-------------------
1 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/app_swift.c b/app_swift.c
@eric
eric / wtf.rb
Created June 8, 2011 05:11 — forked from dbalatero/wtf.rb
# A little helper from _why
class Object
def metaclass
class << self; self; end
end
end
module A
def self.foo
puts "yes"
@eric
eric / beatport_beta_notifier.rb
Created June 15, 2011 01:01
Find out when a #newbeatport code is available
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
require 'notifo'
class BeatportBetaNotifier
SLEEP_TIMEOUT = 10
BEATPORT_URL = 'http://beta.beatport.com/beta'
@eric
eric / README.md
Created June 20, 2011 23:50 — forked from mheffner/README.md
Setting up syslog logging on Heroku with Sinatra 1.2.x

Setting up syslog logging on Heroku with Sinatra 1.2.x

1. Update your Gemfile to include:

gem 'remote_syslog_logger'

3. Modify your config.ru to match the example one below.

4. Setup REMOTE_SYSLOG_URI environment variable

diff --git a/lib/rollout.rb b/lib/rollout.rb
index 4727b97..fe469f8 100644
--- a/lib/rollout.rb
+++ b/lib/rollout.rb
@@ -1,7 +1,10 @@
class Rollout
- def initialize(redis)
- @redis = redis
- @groups = {"all" => lambda { |user| true }}
+ attr_accessor :population
@eric
eric / hanging.rb
Created July 12, 2011 22:51
Hanging regex found by @jnunemaker
[1 : 0] eric@morizo:/Users/eric > irb
>> regex = /\A(?:%[0-9a-fA-F]{2}|[^%]+)*\z/
=> /\A(?:%[0-9a-fA-F]{2}|[^%]+)*\z/
>> str = "http%3A%2F%2Fwww.google.com%2Furl%3Fsa%3Dt%26source%3Dweb%26cd%3D1%26sqi%3D2%26ved%3D0CCkQFjAA%26url%3Dhttp%253A%252F%252Fnd.edu%252F%26rct%3Dj%"
=> "http%3A%2F%2Fwww.google.com%2Furl%3Fsa%3Dt%26source%3Dweb%26cd%3D1%26sqi%3D2%26ved%3D0CCkQFjAA%26url%3Dhttp%253A%252F%252Fnd.edu%252F%26rct%3Dj%"
>> regex =~ str
@eric
eric / gist:1079424
Created July 12, 2011 23:32 — forked from jnunemaker/fu.md
FUN BUG?!

Posted to the REE Google Group as well: https://groups.google.com/forum/#!topic/emm-ruby/EBkMfFpk40A

A week back I innocently updated Sinatra on an app which in turn updated Rack. Since then, I've had crazy hung passenger processes that just gobble up CPU like it is going out of style.

After spending a few days trying everything I knew to to fix it, today I got help from a friend (Eric Lindvall) and dug in with strace, rbtrace, gdb, and gdb.rb and found the issue. Rack 1.3.0 tests a regex against a URL and it causes things to hang.

class YourThing
def self.connection
@connection ||= Faraday::Connection.new do |b|
b.use Faraday::Request::UrlEncoded
# and all the rest
end
end
def connection
@connection ||= begin
@eric
eric / connection_fix.rb
Created August 3, 2011 23:56 — forked from defunkt/connection_fix.rb
MySQL server has gone away fix
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/