Skip to content

Instantly share code, notes, and snippets.

View raggi's full-sized avatar

James Tucker raggi

View GitHub Profile
@raggi
raggi / roflscale.txt
Created November 3, 2010 02:05
sekrets of the roflscale sauce
08:58 Defi_: can anyone tell me if there are any obvious disadvantages to patching a blocking library to use fibers at the socket level?
08:58 Defi_: its far too much effort to have to rewrite large chunks of every library just to make it async and fiber-aware
08:59 raggi: if it uses non-stack stored state you could end up with concurrency issues (read: race conditions)
08:59 raggi: fibers as implemented in MRI have limited size stacks (4kb)
09:00 Defi_: hmm alright :/
09:01 raggi: if the library is trying to be thread safe, it can make a real mess too
09:01 raggi: Defi_: just use threads.
09:02 Defi_: raggi: not gonna happen...
09:02 Defi_: even if this was a personal project, i wouldnt use threads
09:03 Defi_: guess ill just have to continue rewriting parts of a bunch of libs as i go
@raggi
raggi / plugins.txt
Created December 23, 2010 16:38
a list of all rubygems_plugin.rb files in the wild as of about 2 months ago
gemmirror/code/a/autobundle-1.0.0.pre1/lib/rubygems_plugin.rb
gemmirror/code/a/autobundle-1.0.0.pre2/lib/rubygems_plugin.rb
gemmirror/code/a/authoxy-1.2.1/lib/rubygems_plugin.rb
gemmirror/code/s/specific_install-0.2.2/lib/rubygems_plugin.rb
gemmirror/code/s/specific_install-0.2.1/lib/rubygems_plugin.rb
gemmirror/code/s/specific_install-0.2.3/lib/rubygems_plugin.rb
gemmirror/code/s/show_gem-0.0.1/lib/rubygems_plugin.rb
gemmirror/code/s/show_gem-0.0.2/lib/rubygems_plugin.rb
gemmirror/code/s/shway-3.0.1/lib/rubygems_plugin.rb
gemmirror/code/s/shway-3.0/lib/rubygems_plugin.rb
@raggi
raggi / gc.c
Created January 10, 2011 06:49
someone's description of gc.c
gc_mark_children()
{
cthulhu:
fthagn()
fthagn!()
goto cthulhu;
}
@raggi
raggi / spec_optimize.rb
Created February 21, 2011 00:15
Optimize your installed gemspecs for rubygems 1.6, can save 4+mb of ram with 500+ gems installed.
require 'rubygems'
globs = Gem.path.map { |path| File.join(path, 'specifications', '*.gemspec') }
updated = 0
Dir["{#{globs.join(',')}}"].each do |f|
spec = Gem::Specification.load(f)
open(f, 'w') do |io|
io.write spec.to_ruby_for_cache
end
@raggi
raggi / rubygems_strings_gc.rb
Created February 21, 2011 00:30
Show the effects of rubygems source_index load on in-memory string size
RAW = true # flip me to make the logs readable, for interests sake.
def write_strings_to fn
open(fn, 'w+') do |f|
ObjectSpace.each_object do |o|
f.send((RAW ? :print : :puts), o) if o.class == String
end
end
end
@raggi
raggi / update_all
Created March 8, 2011 18:06
Tools of the trade. Update all repositories in a subdirectory, with faster github pulls.
#!/usr/bin/env ruby
gc = ARGV.shift if ARGV.first == "-gc"
Dir.chdir ARGV.first || File.expand_path(File.dirname(__FILE__))
io = IO.popen('exec ssh -MNqv git@github.com 2>&1')
waited = 0
until io.readline =~ /Entering interactive session/
sleep 0.01
@raggi
raggi / disk_writer.rb
Created April 2, 2011 18:02
An example to assist someone asking for help on the EM mailinglist. An eventmachine connection class that writes periodically to file.
class DiskWriter < EM::Connection
# A random stab in the dark at somethign that's loosely efficient. Assuming
# you have a larger page size than 4kb, you'll probably still want ruby to
# write a ton of pages at a time to anything resembling a spindle. On most
# systems, this will default to 64kb. It's possible you may get better
# performance going much higher. If you end up GC bound, or other operations
# are causing leak like behavior, then you may find higher tunings become
# less efficient in production over time. It is also worth noting that some
# versions ::Queue do not free their buffer pages.
DEFAULT_THRESHOLD = 16384 * `getconf PAGESIZE`.to_i
@raggi
raggi / launchd.rb
Created April 17, 2011 07:33
A first stab at a launchd provider for chef
class Chef::Provider::Service::Launchd < Chef::Provider::Service::Simple
LAUNCHCTL_FORMAT = /([\d-]+)\s+([\d-]+)\s+([[:print:]]+)/
def initialize(new_resource, run_context)
raise ArgumentError, "run_context cannot be nil" unless run_context
super
run_context.node
end
@raggi
raggi / autotest.rb
Created July 6, 2011 18:04
My oldish .autotest (it's actually .autotest, but gist is teh lame)
module RaggiGrowl
def self.growl title, msg, img = 'alert.png' , pri=0, stick=""
system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{stick}"
false
end
def self.dir; Dir.pwd; end
def self.good; "~/Library/autotest/god.png"; end
def self.bad; "~/Library/autotest/dead.png"; end
SpecResults = /(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/m
@raggi
raggi / rubygems_fuse.rb
Created July 29, 2011 06:16
A FuseFS based RubyGems mirroring spike
require 'fusefs'
require 'net/http/persistent'
require 'dbm'
class Gem::Fuse
VERSION = '1.0.0'
SPECZ = "specs.#{Gem.marshal_version}.gz"
SPECZPATH = '/' + SPECZ
RUBY = 'ruby'
REJECT = %r{^/mach_kernel$|^/Backups.backupdb$}