2007-10-06 @ 21:55

Ruby Bleach

I’ve been a fan of Damian Conway for a while now. One of my favorite modules he’s written is Acme::Bleach. I thought I’d try writing my own in ruby, and this is what I came up with:

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
module Acme
  class Bleach
    TIE = " \t" * 8
    def initialize(file)
      @shirt = File.open(@file = file, 'rb') { |f|
        f.read
      }.gsub("require 'bleach'\n", '')
    end

    def dirty?; @shirt =~ /\S/; end
    def dress?; @shirt =~ /^#{TIE}/; end

    def whiten
      TIE + @shirt.unpack('b*')[0].tr('01', " \t").gsub(/(.{9})/, '\1'+"\n")
    end

    def brighten
      @shirt = [@shirt.gsub(/^#{TIE}|[^ \t]/, '').tr(" \t", '01')].pack('b*')
    end

    def fold
      File.open(@file, 'wb') { |f| f.puts "require 'bleach'"; f.write whiten }
    end
  end
end

shirt = Acme::Bleach.new($0)
eval(shirt.brighten) unless shirt.dirty? && !shirt.dress?
shirt.fold

Store that in a file named “bleach.rb”. Then in another file do something like this:

1
2
3
require 'bleach'

puts "hello world"

After you run it, your program will be bleached! yay! Thanks Damian!

read more »

2007-10-11 @ 15:06

ANTM Makeover Episode

Last night was the ANTM makeover episode. The makeover episode is my favorite from each cycle. Saleisha got a makeover, and now I think she looks kind of like the Peter Pan Guy.

Check this out:

Peter Pan and Saleisha

I’ve also been thinking about adding a logo to my site. What do you guys think?

tl-20071010-133834

read more »