Skip to content

Instantly share code, notes, and snippets.

[2 : 0] eric@morizo:/Users/eric > cat > 'this is a test.sh'
#!/bin/sh
echo "we are so cool"
[3 : 0] eric@morizo:/Users/eric > chmod 755 'this is a test.sh'
[4 : 0] eric@morizo:/Users/eric > irb
>> system "this is a test.sh"
=> false
>> system ["this is a test.sh", "this is a test.sh"]
we are so cool
namespace :test do
task :populate_testopts do
if ENV['TESTNAME'].present?
ENV['TESTOPTS'] = ENV['TESTOPTS'] ? "#{ENV['TESTOPTS']} " : ''
ENV['TESTOPTS'] += "--name=#{ENV['TESTNAME'].inspect}"
end
end
end
%w(test:units test:functionals test:integration).each do |task_name|
@eric
eric / .gitconfig
Created January 11, 2010 22:14 — forked from kneath/._what.md
[alias]
up = !sh -c 'git pull && git --no-pager log --pretty=format:\"%Cred%ae %Creset- %C(yellow)%s %Creset(%ar)\" HEAD@{1}.. && echo'
@eric
eric / gist:265204
Created December 29, 2009 07:50
The important changes that fixed the memory leaks in god
diff --git a/lib/god.rb b/lib/god.rb
index 388179a..df39592 100644
--- a/lib/god.rb
+++ b/lib/god.rb
@@ -534,6 +531,9 @@ module God
watches = self.pending_watches.dup
self.pending_watches.clear
self.pending_watch_states.clear
+
+ # make sure we quit capturing when we're done
@eric
eric / require_tracking.rb
Created December 28, 2009 02:18
A simple tool to gather memory usage when files are required. More info at: http://bitmonkey.net/post/308322913
#
# Created by Eric Lindvall <[email protected]>
#
# WHAT: Provides a simple overview of memory allocation occuring during a
# require.
#
# For a longer explanation, see my post at:
#
# http://bitmonkey.net/post/308322913/tracking-initial-memory-usage-by-file-in-ruby
#
> gdb --batch -ex 'disasrb_gc_force_recycle' ruby
Using host libthread_db library "/lib/libthread_db.so.1".
Undefined command: "disasrb_gc_force_recycle". Try "help".
CRYPT [22 : 0] eric@vox4:/home/eric > gdb --batch -ex 'disas rb_gc_force_recycle' ruby
Using host libthread_db library "/lib/libthread_db.so.1".
Dump of assembler code for function rb_gc_force_recycle:
0x08069ed2 <rb_gc_force_recycle+0>: push %ebp
0x08069ed3 <rb_gc_force_recycle+1>: mov %esp,%ebp
0x08069ed5 <rb_gc_force_recycle+3>: push %ebx
0x08069ed6 <rb_gc_force_recycle+4>: sub $0x10,%esp
> ruby spec/memprof_spec.rb
Memprof
- should print stats to a file [FAILED]
- should allow calling ::stats multiple times [FAILED]
- should clear stats after ::stats! [FAILED]
- should collect stats via ::track
- should dump objects as json
- should raise error when calling ::stats or ::dump without ::start
spec/memprof_spec.rb:76: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux], MBARI 0x8770, Ruby Enterprise Edition 2009.10
# Would be nice to be part of scout internals
def counter(name, value, options = {})
current_time = Time.now
if data = memory(name)
last_time, last_value = data[:time], data[:value]
elapsed_seconds = current_time - last_time
# We won't log it if the value has wrapped or enough time hasn't
# elapsed
(gdb) ruby objects classes
1 God::Registry
1 God::Socket
1 ActiveSupport::Inflector::Inflections
1 REXML::XMLDecl
1 Resolv::DNS::Config
1 Resolv::DNS
1 Resolv::Hosts
1 Resolv
1 Gem::CommandManager
#!/usr/bin/env ruby
def fork_test(command)
pid = Kernel.fork do
exec command
end
puts "parent sees pid: #{pid}"
Process.waitpid(pid)
end