Jay McGavren's Journal

2008-09-22

Think our world is all SOA and web-service-enabled?

Think again. I just got an e-mail from a major travel industry vendor (one you’ve probably heard of), detailing changes to the procedure for manually downloading and unzipping the monthly data file they send us. This is the third vendor in the past year to pull something like this. (Actually the biggest one can’t seem to send us the same format month to month.)

“The future is already here - it is just unevenly distributed.” –William Gibson

Read more...
2008-09-19

No parking ticket. (whew!) But this was amusing, since I was wearing my “Do Not Want!” shirt:

FAIL

Read more...
2008-09-17

More experiments with objects that do weird crap when placed in ordinary situations…

This one lets you wrap an object so that its apparent value changes over time.

class ValueProxy
	self.instance_methods.reject{|m| m.to_str == '__id__' or m.to_str == '__send__'}.each do |method|
		undef_method(method)
	end
	def initialize(value)
		@value = value
	end
	def method_missing(method, *arguments)
		value.send(method, *arguments)
	end
end

Then we subclass it to do various things with @value

class ReverseProxy < ValueProxy
	def value
		@value.reverse
	end
end

And ordinary calls like this suddenly get weird.

string = ReverseProxy.new('foobar')
puts string
string2 = string + 'baz'
puts string2
puts ReverseProxy.new([1, 2, 3])

Output:

raboof
raboofbaz
3
2
1

Read more...
2008-09-10

A before_filter equivalent for general Ruby...

I’ve been able to wrap individual methods in other calls via alias_method for a while now, but I’ve always done it by hand; been meaning to write something up to do it generically… Well, I came across an ugly but effective bit of code from Tadayoshi Funaba in Programming Ruby that was easily adapted to do just what I need.

require 'logger'
require 'utility'

class Test
	def initialize
		@logger = Logger.new(STDOUT)
	end
	def bar(baz, glarch)
		puts [baz, glarch].join('/')
	end
	def log(*args)
		@logger.info(args)
	end
	before :bar, :log ###Here's the magic line!
end

test = Test.new
test.bar(1, 2)

Outputs:

$ ruby test.rb
I, [2008-09-10T09:44:07.371000 #3292]  INFO -- : [1, 2]
1/2

…Thanks to that “before :bar, :log”, log() automatically got called before bar() with the same arguments.

Here’s the alteration to Module that does it:

class Module
	private
		def before(wrapped_method, pre_method)
			module_eval <<-EOD
				alias_method :__#{wrapped_method.to_i}__, :#{wrapped_method.to_s}
				private :__#{wrapped_method.to_i}__
				def #{wrapped_method.to_s}(*args, &block)
					#{pre_method.to_s}(*args, &block)
					__#{wrapped_method.to_i}__(*args, &block)
				end
			EOD
		end
end

Module#after() should work similarly.

Read more...
2008-09-02

Well, it sounds like Google Chrome could offer a substantial speed increase to AJAX apps. The Javascript VM that compiles down to native instructions is interesting if nothing else is. And hey, if Ben Goodger is on board, it can’t be any worse than Firefox, right?

Google Chrome for Dummies

Update 2008-09-02 13:20:21: No noticeable speed increase on GMail or Reader in Google Chrome over Firefox 3 on XP. Rest of experience is different but decent.

Read more...