Skip to content

Instantly share code, notes, and snippets.

View netshade's full-sized avatar
🧛

Chris Zelenak netshade

🧛
View GitHub Profile
@netshade
netshade / exception_reporter_middleware.rb
Last active December 15, 2015 01:09
Capture Exceptions with Instrumental (tested in Rails 3.2.11)
# lib/instrumental/exception_reporter_middleware.rb
module Instrumental
class ExceptionReporterMiddleware
def initialize(app)
@app = app
end
def call(env)
@app.call(env)
@netshade
netshade / gist:5161832
Created March 14, 2013 14:34
JRuby Timeout / IO.select bug
# ruby -v => jruby 1.7.3 (1.9.3p385) 2013-02-21 dac429b on OpenJDK 64-Bit Server VM 1.7.0-u10-b06-20120912 [darwin-x86_64]
r, w = IO.pipe
require 'timeout'
Timeout::timeout(1) { IO.select([r]) } # does not timeout, blocks indefinitely
# No clue how to report an issue using their JIRA reporter, so...
@netshade
netshade / gist:3707866
Created September 12, 2012 16:25
JRuby 1.6.7.2 cext build on Mountain Lion not working through RVM
diff --git a/cext/src/Makefile b/cext/src/Makefile
index 1622165..5f9ff3e 100644
--- a/cext/src/Makefile
+++ b/cext/src/Makefile
@@ -154,7 +154,7 @@ endif
ifeq ($(OS), darwin)
PLATFORM = Darwin
- MACSDK = $(firstword $(filter-out %/MacOSX10.4u.sdk, $(wildcard /Developer/SDKs/MacOSX*.sdk)))
+ MACSDK = $(lastword $(filter-out %/MacOSX10.4u.sdk, $(shell find $(shell xcode-select -print-path) -name 'MacOSX10.*.sdk')))
@netshade
netshade / gist:2931088
Created June 14, 2012 15:47
Silly base 93 numbers
module CompactUnsignedInt
ASCII_RANGE = 33..126
ASCII_LENGTH = ASCII_RANGE.last - ASCII_RANGE.first
module InstanceMethods
def to_compact_int
base = to_i
raise "Negative numbers will not convert" if base < 0
@netshade
netshade / app.js
Created May 16, 2012 17:30
console.log to your node app
// In your connect middleware setup in development mode
app.use(require("./lib/console.log.remote/middleware")());
// Your pages will have to include /console.log.js to override console.log
netshade@chris-zelenak-2 [03:11:27] [~/.rvm/src/ruby-1.8.7-p352]
-> % ./ruby crash.rb
85317
85318
crash.rb:6: [BUG] Segmentation fault
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.3.0]
netshade@chris-zelenak-2 [03:11:34] [~/.rvm/src/ruby-1.8.7-p352]
-> % gdb ./ruby
GNU gdb 6.3.50-20050815 (Apple version gdb-1752) (Sat Jan 28 03:02:46 UTC 2012)
@netshade
netshade / gist:1725469
Created February 2, 2012 20:07
Agent fork test
#!/usr/bin/env ruby
require 'rubygems'
require 'logger'
require 'instrumental_agent'
Instrumental::Agent.logger = Logger.new(STDOUT)
a = Instrumental::Agent.new('YOUR_API_KEY')
t = Time.now.to_i
forked = nil
a.increment("fork.start")
@netshade
netshade / gist:1725305
Created February 2, 2012 19:36
Track Nginx Proc Count
while :; do (ps -o command -U YOUR_APP_USER | awk "/Rack:/ {print $1 $2}" | wc -l | { read procs; echo "hello version 1.0\nauthenticate YOUR_API_KEY\ngauge nginx.proc.num $procs `date +%s`\n" } ) | nc instrumentalapp.com 8000; sleep 60; done
@netshade
netshade / gist:1566141
Created January 5, 2012 17:04
metrics from stdin to instrumental
#!/usr/bin/env ruby
# Provide data over STDIN to Instrumental
# Format of data:
# <metric name> <value> <unix timestamp>
# or
# <metric name> <value>
#
# Second form will assume that the time the
# metric is reported is when the event occurred.
#
@netshade
netshade / gist:1424924
Created December 2, 2011 21:33
Compile libdispatch on Ubuntu from source
sudo apt-get install clang subversion autogen libtool pkg-config
svn co svn://mark.heily.com/libBlocksRuntime/trunk libBlocksRuntime
cd libBlocksRunTime
CC=clang ./configure
make
sudo cp libBlocksRuntime.so /usr/local/lib/
sudo cp Block*.h /usr/local/include/
cd ..
svn checkout svn://mark.heily.com/libkqueue/trunk libkqueue
cd libkqueue