The device failed to calibrate the laser power level

February 22nd, 2010

So, this happened today:

  1. Mr. Jobs was obviously off the day this made it into OS X.
  2. Never did I ever expect to run into trouble calibrating laser power in the course of daily computing. I am pleasantly surprised.
  3. Compressed air made this go away. Pffft.

Dear Pilsen

February 13th, 2010

Every once in a while, despite your grime, your gang graffiti on every wall, your drunks pissing in alleys, and your abject antipathy to shoveling snow or even putting your trash in actual trash bins, you manage to be quite nice. Thanks for the sunset this evening.

Pilsen sunset

Twitter reactions to the iPad

January 27th, 2010

Since the announcement a few hours ago:

Twitter stream

The Intern

January 25th, 2010

Rufus has been helping out around the home office: providing moral support, slobbering on pant legs, and conducting some thought-leadership workshops (read: napping for hours on end). He’s a real team player.

Fiori di Como

January 24th, 2010

Dale Chihuly:

I’m amazed at what people find in my work, and I don’t like to limit what you see with a title. For me titles are very difficult, and I don’t usually even think in terms of a theme when I’m creating a sculpture. Once it’s finished I’ll come up with a title, but one person might see flowers, another something from the sea or something from a dream. Bellagio was inspired by the hotel on Lake Como, and I wanted to use the lake in the title – it’s so romantic. I used the word fiori (flowers), but everybody sees something different.

HOWTO: Watermarking Images with ImageMagick and attachment_fu

January 14th, 2010

While working on a project for the State Hermitage Museum last year, I had to implement some image watermarking. The basic requirement was that for a certain type of uploaded image, its largest thumbnail should have the museum’s logo tiled across it. I was using attachment_fu to handle the image upload, and ImageMagick/RMagick to process the thumbnails.

After some cursory Googling, I found the ImageMagick Annotating guide, which had this sample watermark command:

 $ convert overlay.png  -fill grey50 -colorize 40  miff:- |\
    composite -dissolve 15 -tile  -  original.jpg watermarked_image.jpg

The dissection of the command:

overlay.png: The source image to overlay

-fill grey50 -colorize 40: Alter the colors of the watermark file

composite: command to overlay the watermark

-dissolve 15 -tile: “dissolve” the overlay at 15%, for good transparency, and tile (repeat) the watermark over the source image.

That’s simple enough, and with these source files:

overlay.png

and dearest Rufus:

rufus.jpg

rufus.jpg

 $ convert overlay.png -fill grey50 -colorize 40 miff:- |\
    composite -dissolve 15 -tile - rufus.jpg result-15.jpg

Produces:

Overlay with 15% dissolve

convert overlay.png -fill grey50 -colorize 40 miff:- |\
  composite -dissolve 50 -tile - rufus.jpg result-50.jpg

Overlay with 50% dissolve

Unfortunately, RMagick’s watermark method doesn’t support tiling. To work around, I had to call the composite_tiled! method on a colorized image. This code is in my Thumbnail model, which includes attachment_fu:

class Thumbnail < ActiveRecord::Base
  has_attachment  :content_type => :image,
   # some settings omitted
   :watermark_overlay => File.join(RAILS_ROOT, '/public/images/watermark-overlay-image.png'),
   :watermarkable_size => "1500>" 
 
  after_attachment_saved do |record|
    if record.respond_to?(:parent_id) and record.parent_id.nil? # the original image, not the smaller thumbnails
      with_image record.full_filename do |img|
        img.composite_tiled!(
          Magick::ImageList.new(attachment_options[:watermark_overlay]).first.colorize(0.4, 0.4, 0.4, 'grey'),   # process and colorize image
          Magick::SoftLightCompositeOp)
        img.write record.full_filename  # save image
      end
    end
  end
end

Now every Thumbnail record will automatically have a watermarked large image.

Gordie, Pretty Bird

January 8th, 2010

This is Gordie, the Gansen family pet bird. He’s been around since 1997, making him 12 years old. Words cannot express how much I love this little guy.

He loves nothing more than to run around and chase pieces of paper. If you tap on the paper, the following will happen:

And sometimes he gets a bit overstimulated and decides to bite everyone, then it’s time to hang out in the cage:

Oh, Gordie. happy new year to you.

you should concentrate on finalizing this transaction rather than responding to negative thoughts

December 22nd, 2009

This junk email wiggled its way through Google’s filtering, much to my delight. After reading it, I felt genuinely touched, as if Deborah was really worried for me, worried that I wouldn’t claim my money.

Oh, Deborah, if I ever make it over to Benin to collect my fifteen thousand United States dollars, I’ll give you a hug.

Email in full:

Fund Beneficiary,
Welcome to ECO BANK Money Gram money transfer Cotonou Benin Plc,
Beneficiary! This is to notify you that we have concluded your payment through Money Gram.

Here is your 3payment MTCN of USD$15,000.00 united state dollars $5,000.00 each, First payment, MTCN 212-314-53 (2) 805-217-78 (3) 968-584-30 and we will give you the sender name to pick up this money immediately you send the activation remittance permit fee which is $188.00 dollars to the name below.

Receiver Name == Augustine Okolo
Address: …. Benin / City Continuo
Test Q…………What?
Ans ……………..Payment.
Amount $188.00

Kindly send the activated remittance permit fee with the given infor…and call for sender name on +22 998 377 738 Urgent,
The grace given to you, is a previledge, not a right, therefore it must not be abused. When i imagine the magnitude of your compensation funds left in our possession,it pains me to see that you are yet to get your transfered.

You should count yourself extremely luck for the fortune that has come your way today . It is one in a life time fortune and you should concentrate on finalizing this transaction rather than responding to negative thoughts.

As a friend, i will not like you to loose this chance which has come up today because not every body in this life has this great chance that has come your way including me.Act fast in remitting the fee and let us finalize this transaction which has already stayed longer than expected. I await your swift response, comply and details

Sir. M. Deborah Utecht
FORIGN OPERATION MANAGER
MONEY GRAM OFFICE BENIN REPUBLIC )

I have purchased but a single song from iTunes.

October 21st, 2009

iTunes

But what a song it is.

HOWTO: Remove Byte-order Mark with Ruby and Iconv

October 19th, 2009

I’m working on a small project that involves loading a UTF-16LE (16-bit Unicode, Little Endian) CSV file, converting it to UTF-8 (normal Unicode, as it may be) with iconv, then parsing the values with FasterCSV. Everything was working fine except for loading the first column of data by the column header value. For example, given data:

First Name Last Name Email
Jimbo Jones jimbo.jones@example.com

I could access column 2 (Last Name) as either row.field("Last Name") or row.field(1). However, if I tried to access the first column using row.field("First Name"), it would return nil. row.field(0), on the other hand, would return the proper value.

Hmmmm.

After some sleuthing, I examined the raw content of the string:

(rdb:1) p row.headers.first.unpack('C*')
[239, 187, 191, 70, 105, 114, 115, 116, 32, 78, 97, 109, 101]

Ah, ha! The first three characters are the byte-order mark, or BOM. Ruby, for whatever reason, does not strip it when reading a file as input, so it’s passed along in the input stream. When loading a file with FasterCSV, it’ll keep those characters in the key name, causing lookups by the first column key name to return nil.

I modified my file conversion code as follows:

  def convert_to_utf8
    # Data files are exported as Little Endian UTF-16. We need to parse as UTF-8
    contents = File.open(@file_name).read      
    begin
      converted = Iconv.iconv('UTF-8', 'UTF-16LE', contents)
      converted.first.gsub!("\xEF\xBB\xBF", '') # strip the BOM (byte order mark) from the first line of input
      output = File.open(@file_name, 'w')
      output.write(converted)
    rescue Iconv::Failure
      puts $!.inspect
    end
  end

And all is well in the world.