rb-appscript is cool

Posted about 7 years back at The Hobo Blog

After a small typo in the Hobo manual was reported in the forum (thanks!), I decided I’d like to automate the process of updating the manual.

I had two awkward bits that I was doing manually - conversion from Markdown to HTML, and conversion from Markdown to PDF.

“Eh?” I hear you cry? Manually converting Markdown to HTML? Have you never heard of BlueCloth? Well, I chose not to use BlueCloth because it, er, didn’t work. It choked on my markup, which looks fine to me, and converts just fine in Textmate. But today I somehow stumbled across Maruku which works great, and even has some nifty markdown extensions which I’m sure I’ll use.

One down, one to go - conversion to PDF. The trick here was that I really wanted a solution that allowed me to customise the style of the generated PDF. I really wanted to get to PDF via HTML+CSS. I thought I’d try and ask Safari to do the job for me via AppleScript. It worked!

Of course, I wouldn’t dream of trying to actually code AppleScript. If you’re on MacOS, go have a play with rb-appscript. It’s good stuff. The cool part is that because it’s all Ruby, you can fire it up in irb and make all your desktop apps jump around at your interactive command.

In order to get Safari to save a PDF at my slightest whim, there was one more trick required - I needed a “PDF File” printer (there’s no way to access the “save a pdf file” feature from AppleScript). I eventually found cups-pdf for Mac which works great. All my apps now see “PDF File” as a virtual printer.

Here’s the Ruby code that gets Safari to do the needful:

require 'rubygems'
require 'appscript'
safari = Appscript.app('Safari')
safari.open_location("file://#{Dir.getwd}/manual.html")
safari.documents[0].print(:with_properties => {:target_printer => "PDF File"})
safari.documents[0].close

That documents[0] looks a bit dodgy, but I couldn’t figure out how to say “the document I just loaded”.

So bring on your typos! I’ve so got it covered.

Episode 8: Layouts and content_for

Posted about 7 years back at Railscasts

If you want to change something in the layout on a per-template basis, content_for is your answer! This allows templates to specify view code that can be placed anywhere in a layout.

Globalizing Mephisto

Posted about 7 years back at Mephisto - Home

Saimon has posted a mephisto_i18n plugin, as well as the first part of a companion tutorial for globalizing your Mephisto site.

New Mephisto Theme Gallery

Posted about 7 years back at Mephisto - Home

Pascal just unleashed another Mephisto Theme Gallery, with a nice new theme ported from Wordpress: Cutline (side note: it’d be nice if we could link to themes directly somehow).

One neat feature is that Pascal provides some of the themes in alternate formats, such as RHTML, Erubis, and HAML. He took a bit of encouragement from me and managed to refactor the Liquid support in the edge version of Mephisto. It now supports custom template renderers in the form of plugins, with renderers for (you guess it, true believer!) RHTML, Erubis, and HAML.

On another note, one of the few original Mephisto themes, Skittlish, gets a Wordpress makeover.

NH Ruby UG Meeting.003 Tonight!

Posted about 7 years back at zerosum dirt(nap) - Home

If you’re in the seacoast New Hampshire area, don’t forget to attend tonight’s NH Ruby User Group meeting. Click on the link for directions.

Brian DeLacey will be speaking on Security and Cryptography in Ruby on Rails, and there will be some free book giveaways from O Reilly.

Episode 7: All About Layouts

Posted about 7 years back at Railscasts

Everything you wanted to know about layouts: global layouts, controller layouts, shared layouts, dynamic layouts and action layouts. Yes, there really are that many ways to specify a layout.

Mod Your Motorola SLVR L6 Using OS X

Posted about 7 years back at schadenfreude

This page is a collection of various modifications for the Motorola SLVR L6.

Mod Your Motorola SLVR L6 Using OS X

Posted about 7 years back at schadenfreude

This page is a collection of various modifications for the Motorola SLVR L6.

Mod Your Motorola SLVR L6 Using OS X

Posted about 7 years back at schadenfreude

This page is a collection of various modifications for the Motorola SLVR L6.

The cost of automation

Posted about 7 years back at The Hobo Blog

Very interesting point over on S/N:

Auto-mode vs. shooting manual

Is Hobo guilty of putting up another layer? Of blurring your vision? The answer can’t be a straightforward “yes”, because that road would lead back to hacking assembly-code by hand.

Many photographers like to develop their film by hand too. If Hillman Curtis did that with his movie, for every frame, he’d definitely get a richer result. He’d also never finish.

I think it comes down to a simple trade-off – every time you flick an “auto” switch off, development time goes up, but quality goes up too - people always do things better than machines. Which switches you flick is a judgement call that has to be made for each switch and for each project.

The interesting thing about Hobo is that it lets you, if you so choose, start with all the switches on. You can then switch them off one by one, gradually replacing the automatic with the hand-crafted.

The cost of automation

Posted about 7 years back at The Hobo Blog

Very interesting point over on S/N:

Auto-mode vs. shooting manual

Is Hobo guilty of putting up another layer? Of blurring your vision? The answer can’t be a straightforward “yes”, because that road would lead back to hacking assembly-code by hand.

Many photographers like to develop their film by hand too. If Hillman Curtis did that with his movie, for every frame, he’d definitely get a richer result. He’d also never finish.

I think it comes down to a simple trade-off – every time you flick an “auto” switch off, development time goes up, but quality goes up too - people always do things better than machines. Which switches you flick is a judgement call that has to be made for each switch and for each project.

The interesting thing about Hobo is that it lets you, if you so choose, start with all the switches on. You can then switch them off one by one, gradually replacing the automatic with the hand-crafted.

Random Numbers in UUIDTools

Posted about 7 years back at Sporkmonger

I wrote the random number generator for UUIDTools awhile ago, but strangely, I’m only just now getting around to verifying that the numbers it generates really are decently random. Previously, I’d just been “eyeballing” it.

~/Projects/Ruby/Components/uuidtools/lib $ irb
UUIDTools environment loaded.
>> output = File.new("random.txt", "w")
=> #<File:random.txt>
>> 10000.times do
?>   output.write(UUID.true_random)
>> end
=> 10000
>> output.close
=> nil
>> exit

~/Projects/Ruby/Components/uuidtools/lib $ ent < random.txt
Entropy = 7.998801 bits per byte.

Optimum compression would reduce the size
of this 160000 byte file by 0 percent.

Chi square distribution for 160000 samples is 266.64, and randomly
would exceed this value 50.00 percent of the times.

Arithmetic mean value of data bytes is 127.1241 (127.5 = random).
Monte Carlo value for Pi is 3.146778669 (error 0.17 percent).
Serial correlation coefficient is -0.000714 (totally uncorrelated = 0.0).

I’m reasonably satisfied with that I think.

By comparison, the builtin rand method in ruby gets:

~/Projects/Ruby/Components/uuidtools/lib $ rm random.txt
~/Projects/Ruby/Components/uuidtools/lib $ irb
UUIDTools environment loaded.
>> output = File.new("random.txt", "w")
=> #<File:random.txt>
>> 160000.times do
?>   output.write(rand(256).chr)
>> end
=> 160000
>> output.close
=> nil
>> exit

~/Projects/Ruby/Components/uuidtools/lib $ ent < random.txt 
Entropy = 7.998954 bits per byte.

Optimum compression would reduce the size
of this 160000 byte file by 0 percent.

Chi square distribution for 160000 samples is 231.72, and randomly
would exceed this value 75.00 percent of the times.

Arithmetic mean value of data bytes is 127.6154 (127.5 = random).
Monte Carlo value for Pi is 3.150228756 (error 0.27 percent).
Serial correlation coefficient is -0.000933 (totally uncorrelated = 0.0).

And random.org gets:

Entropy = 7.999805 bits per character.

Optimum compression would reduce the size
of this 1048576 character file by 0 percent.

Chi square distribution for 1048576 samples is 283.61, and randomly
would exceed this value 25.00 percent of the times.

Arithmetic mean value of data bytes is 127.46 (127.5 = random).
Monte Carlo value for PI is 3.138961792 (error 0.08 percent).
Serial correlation coefficient is 0.000417 (totally uncorrelated = 0.0).

Dan Webb - Ruby on Rails Podcast

Posted about 7 years back at Ruby on Rails Podcast

The stylishly sneakered leading proponent of unobtrusive Javascript gives advice about Rails freelancing and standards-based website development.
Also mentioned:

In Praise of Slowness

Posted about 7 years back at The Hobo Blog

I had to create a new category for this post – ‘Off Topic’. Hope you don’t mind but I just had to share this with anyone that’s listening. Everyone in the Western world needs to watch this video. Twice. No, Really.

Once upon a time, a book of “One-Minute Bedtime Stories” provided the wake-up call for Carl Honore, who considered time efficiency to be more important than reading to his son. He realized that he was speeding his way through life to the detriment of his health, productivity and relationships. As in his book, “In Praise of Slowness”, Honore shares examples of how we can make more of life by doing less and getting in touch with our “inner tortoise.” (Recorded July 2005 in Oxford, UK. Duration: 20:00)

Watch video

(I just got a link from a friend recommending the TED Talks and this was the first one I watched – looks like a gold mine!)

In Praise of Slowness

Posted about 7 years back at The Hobo Blog

I had to create a new category for this post – ‘Off Topic’. Hope you don’t mind but I just had to share this with anyone that’s listening. Everyone in the Western world needs to watch this video. Twice. No, Really.

Once upon a time, a book of “One-Minute Bedtime Stories” provided the wake-up call for Carl Honore, who considered time efficiency to be more important than reading to his son. He realized that he was speeding his way through life to the detriment of his health, productivity and relationships. As in his book, “In Praise of Slowness”, Honore shares examples of how we can make more of life by doing less and getting in touch with our “inner tortoise.” (Recorded July 2005 in Oxford, UK. Duration: 20:00)

Watch video

(I just got a link from a friend recommending the TED Talks and this was the first one I watched – looks like a gold mine!)