Skip to content

Instantly share code, notes, and snippets.

// Given an interface (IFactory<> in this example), find everything that
// implements the interface and put it in a map.
//
// Usage:
// public interface IFactory<T> { ... }
// public class AppleFactory : IFactory<Apple> { ... }
// public class BananaFactory : IFactory<Banana> { ... }
// public class ChocolateFactory : IFactory<Chocolate> { ... }
//
// var m = new FactoryManager(); // Automatically scans this assembly for suitable implementations
require 'tempfile'
t = Tempfile.new('test-data')
t.open
t.sync = true
t << "apples"
t.puts "bananas"
# prints "contents are [] (14 bytes)"
puts "contents are [#{t.read}] (#{t.size} bytes)
[johnf@genesis][2010/06/12|17:53:00]
[/tmp]> mkdir foo
[johnf@genesis][2010/06/12|17:53:36]
[/tmp]> cd foo
[johnf@genesis][2010/06/12|17:53:39]
[/tmp/foo]> git init
Initialized empty Git repository in /tmp/foo/.git/
[johnf@genesis][2010/06/12|17:53:40]
@fj
fj / gist:436706
Created June 13, 2010 14:36
Patch for misleading #rvm message when using 'system' instead of '--system'.
diff --git a/scripts/cli b/scripts/cli
index b4cd70e..496d322 100644
--- a/scripts/cli
+++ b/scripts/cli
@@ -280,6 +280,7 @@ __rvm_parse_args() {
;;
system|default)
+ echo "Reverting to predefined interpreter '${rvm_token}'."
rvm_action=${rvm_action:-use}
@fj
fj / gist:436763
Created June 13, 2010 15:50
Helping someone who asked in #ruby about recursively replacing Array elements.
b = lambda { |e| e.kind_of?(Array) ? e.map(&b) : (e.nil? ? "" : e) }
# => #<Proc:0x0000000104d908@(irb):1 (lambda)>
arr = [5, 6, 7, nil, [nil], [6, 8, nil], [[194, 48, nil], [nil]]]
# => [5, 6, 7, nil, [nil], [6, 8, nil], [[194, 48, nil], [nil]]]
arr.map(&b)
# => [5, 6, 7, "", [""], [6, 8, ""], [[194, 48, ""], [""]]]
@fj
fj / false-positive.rb
Created June 18, 2010 19:34
Found a bug in RSpec.
#RSpec 1.3.0, #Ruby 1.9.1
describe "Simple class" do
before :each do
@c = Class.new do
attr_accessor :apple
end.new
@c.apple = []
end
# in <project_root>/bin/magicwand
MagicWand::Configuration::Initializer.new(...)
# in <project_root>/data/root.yaml
---
apple: 100
banana: 200
coconut: 300
# ----------------------------------
(master)[johnf@dev-dzb-genesis-lambda][2010/07/06|16:00:24]
[~/dev/project-194/www]> gem install resque
Building native extensions. This could take a while...
Successfully installed redis-2.0.3
Successfully installed redis-namespace-0.5.1
Successfully installed vegas-0.1.7
Successfully installed sinatra-1.0
Successfully installed json-1.4.3
Successfully installed resque-1.9.5
6 gems installed
"Everyone thinks they’re writing the most performance-critical code
in the world, but in reality maybe one in twenty programmers are
writing code where anything short of the most egregious bloat and
carelessness will affect the performance of the system overall.
Unfortunately, egregious bloat and carelessness are quite common."
-- Jeff Darcy writing at http://pl.atyp.us/wordpress/?p=2947
lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)
require 'constructify/version'
Gem::Specification.new do |s|
s.name = "constructify"
s.version = Constructify::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["John Feminella"]