Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'atomic'
atomic1 = Atomic.new([ -1, 0 ])
atomic2 = Atomic.new(0)
array = []
1000.times do |idx|
module ObjectDiagnostics
extend self
def display(method, options = {})
res = format(method, options)
res.each { |l| puts l }
end
def format(method, options = {})
class KestrelQueueMonitor < Scout::Plugin
OPTIONS=<<-EOS
host:
label: Host
notes: Kestrel host
default: localhost
port:
label: Port
notes: Kestrel admin HTTP port
default: 2223
@eric
eric / lru_generational_hash.rb
Created November 15, 2011 00:18
Generational hash table — useful for in-memory caches
#
# by Eric Lindvall <[email protected]>
#
class LruGenerationalHash
attr_reader :max_size
def initialize(max_size, generations = 2)
@generations = generations.times.collect { Hash.new }
@max_size = max_size
@eric
eric / linux_proc_name.rb
Created November 9, 2011 07:39
Update a process name in linux to change how it shows up in top and lsof
#
# Eric Lindvall <[email protected]>
#
# Update the process name for the process you're running in.
#
# This will allow top, lsof, and killall to see the process as the
# name you specify.
#
# Just use:
#
::Kestrel::Client.class_eval do
add_method_tracer :get, 'Kestrel/get'
add_method_tracer :set, 'Kestrel/set'
end
#!/usr/bin/perl -w
#
# take a 1 second average of bandwidth
# eric lindvall <[email protected]>
#
use strict;
$| = 1;
$ sudo gem install memcached -v 1.3.4
Building native extensions. This could take a while...
ERROR: Error installing memcached:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
Touching aclocal.m4 in libmemcached.
touch -r libmemcached-0.32/m4/visibility.m4 libmemcached-0.32/configure.ac libmemcached-0.32/m4/pandora_have_sasl.m4
Configuring libmemcached.
env CFLAGS='-fPIC -g -O2 -g -O2 ' LDFLAGS='-fPIC -L. -rdynamic -Wl,-export-dynamic -L. -rdynamic -Wl,-export-dynamic -L/usr/lib' ./configure --prefix=/usr/lib/ruby/gems/1.8/gems/memcached-1.3.4/ext --without-memcached --disable-shared --disable-utils --disable-dependency-tracking CC="gcc" 2>&1
$ sudo gem install memcached -v 1.3.4
Fetching: memcached-1.3.4.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing memcached:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
Touching aclocal.m4 in libmemcached.
touch -r libmemcached-0.32/m4/visibility.m4 libmemcached-0.32/configure.ac libmemcached-0.32/m4/pandora_have_sasl.m4
Configuring libmemcached.
irb(main):036:0> Encoding.default_external
=> #<Encoding:UTF-8>
irb(main):037:0> data
=> "one two three 32\xC2\xB0\n\xEE\x80\x8E\xEE\x80\x97\xEE\x91\x81\xEE\x81\x94\n\xFF"
irb(main):038:0> data.encoding
=> #<Encoding:ASCII-8BIT>
irb(main):039:0> data.valid_encoding?
=> true
irb(main):040:0> encoded_data = data.encode('utf-8', :invalid => :replace, :undef => :replace)
=> "one two three 32��\n������������\n�"