Author Archive
Update: I've refactored the code significantly and introduced the ability to explicitly unguard methods from within specs.
One problem I find myself having when writing tests is ensuring that no execution ever leaves my little test sandbox. For example, when writing tests for github-gem I keep looking through the code to find every place a function ends up `shelling out` and it's tiresome and error-prone. I finally decided I was going about this backwards. Testing is supposed to find problems for me, right? So why not raise an error whenever `` or Kernel#system() is called and let the tests tell me what else I need to mock?
Put the following code in your spec_helper.rb file and an exception will be raised whenever `` or Kernel#system() is called during a test:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
| class Module
def metaclass
class << self;self;end
end
end
module Spec::Example::ExampleGroupSubclassMethods
def add_guard(klass, name, is_class = false)
guarded = nil # define variable now for scoping
target = (is_class ? klass.metaclass : klass)
sep = (is_class ? "." : "#")
target.class_eval do
guarded = instance_method(name)
define_method name do |*args|
raise "Testing guards violated: Cannot call #{klass}#{sep}#{name}"
end
end
@guards ||= []
@guards << [klass, name, is_class, guarded]
end
def add_class_guard(klass, name)
add_guard(klass, name, true)
end
def unguard(klass, name, is_class = false)
row = @guards.find { |(k,n,i)| k == klass and n == name and i == is_class }
raise "#{klass}#{is_class ? '.' : '#'}#{name} is not guarded" if row.nil?
(is_class ? klass.metaclass : klass).class_eval do
define_method name, row.last
end
@guards.delete row
end
def class_unguard(klass, name)
unguard(klass, name, true)
end
def unguard_all
@guards ||= []
@guards.each do |klass, name, is_class, guarded|
(is_class ? klass.metaclass : klass).class_eval do
define_method name, guarded
end
end
@guards.clear
end
end
Spec::Runner.configure do |configuration|
configuration.prepend_before(:all) do
self.class.send :include, Spec::Example::ExampleGroupSubclassMethods
end
configuration.prepend_before(:each) do
add_guard Kernel, :'`'
add_guard Kernel, :system
add_class_guard Process, :fork
add_class_guard Open3, :popen3 if defined? Open3
end
configuration.append_after(:each) do
unguard_all
end
end |
Note: if you want, you can write :` instead of :'`', but my syntax highlighter here doesn't like that.
Comments Off
I just picked up a new Flip Video and was dismayed to find out that it used a custom app to import its movies, and that this custom app was PPC. I was also dismayed to find out that iMovie ‘08 refuses to import AVIs even if you have the appropriate codec installed. So after some hacking, I put together an Automator workflow that will convert all your Flip videos into DV and import them into iMovie. You can download it here.
Update: I’ve put up a new version of the importer that has a much longer timeout when waiting for Quicktime to export each movie.
27 Comments »
Recently I was contracted to write some software, and it’s just now been released. It’s called GrabUp. Basically, the whole purpose here is for zero-click sharing of screenshots. GrabUp is a daemon that sits in the background and waits for you to take a screenshot, then it instantly uploads it to the GrabUp servers and puts the URL on your clipboard. It has a nice status item to let you know when it’s done. If you have GrabUp running and you want to share an image, just take the screenshot and then paste the URL anywhere. So far, GrabUp has been seen in TUAW and we also got a rather nice blog post reviewing it.
3 Comments »
I’ve just pushed a new version of SafariSource out the door which is once again compatible with Safari Tidy. Please let me know if you have any problems. You can download it here.
Note that this requires version 0.2.5 of Safari Tidy, which was just released today.
Comments Off
Big news for Mac gaming today. Return to Dark Castle has finally been released for OS X! This game has been in development for about 7 years now, and it should be very familiar to anybody who played Mac games 15-20 years ago. Heck, I’m only 22 and I remember Beyond Dark Castle.
Comments Off
For those interested, I am currently maintaining git mirrors of the MacPorts and TextMate Bundles svn repositories on GitHub. I update these periodically, but at the moment only the master branch is published.
1 Comment »
Well, after about 5 hours of hacking, I got a ruby script together to migrate all my data from Typo 4.11 to WordPress, so the site is back from the dead, and now running on an engine that DreamHost is actually happy with.
Update: The conversion script is now available at GitHub.
Comments Off

Can anybody explain what’s going on with that memory usage? I’ve been seeing this for a few months now. These days I tend to restart a handful of apps at least once a day (sometimes more often) to combat this apparent memory problem. I’ve tried just ignoring it, but my system also tends to become less responsive over time, especially when accessing apps that I haven’t used in the last few minutes, so I can only assume that apps are getting paged out frequently. Running sysctl vm.swapusage seems to bear that out as well, at the moment I’m using 1.6GiB and when I checked 2 days ago (before a reboot) I was using close to 3GiB (quitting apps brought that down to about 2.2GiB). Unfortunately I can’t seem to get anywhere on figuring out what’s going on with all this memory. If I run vmmap on one of these processes I just see a lot of malloc blocks.
Comments Off
Lately every day when I come home from work I notice a handful of applications taking up a surprisingly high amount of Real Memory. These apps tend to be Quicksilver, Safari, iScrobbler, NetNewsWire, and GrowlHelperApp. Every day I end up quitting at least 3 apps to free up some memory and it happens all over again.
Right now Quicksilver is using roughly 235MB of Real Memory. Running vmmap on it tells me that almost all of that memory is in the malloc zone, and the vast majority of that malloced memory are freed blocks. So my question is why are my multitudes of freed MALLOC_TINY pages not being reclaimed by the system?
11 Comments »
I picked up an iPhone on friday and I’ll try and remember to write up my thoughts later, but for now I have a quick tip.
For those of you who are like me and listen to full albums and lament the lack of a Compilations preference for the iPhone, learn to love the CoverFlow view. Since this view is album-centric it handles compilations properly. The only real flaw with this view is it’s ugly if you don’t have album art.
Comments Off
|