»
S
I
D
E
B
A
R
«
Quick & Painless PDF Watermark
May 9th, 2007 by Bill

For my part-time gig I needed an elegent way to nudge an absent minded customer of his past due account balance. I typically invoice via an emailed PDF which I thought would be cool because one day I could create a “second notice” version by placing an appropriate watermark behind the original invoice. That at least was the plan…

Well, after months of forgetting to play with this idea, or playing with it on and off, I stumbled upon this. Now, thanks to Colin, and especially the creator(s) of pdftk the process of creating my second notice invoices is a simple as this:

pdftk invoice.pdf background notice.pdf output notice_invoice.pdf

What’s even better is that pdftk is available for Linux, OS X, FreeBSD, Solaris, and Windoze.

Ruby Code Camp
May 5th, 2007 by Bill

Greetings from Ruby Code Camp in Columbus, OH and thanks to the Columbus Ruby Brigade for spreading the word and to all the sponsors, especially Agile Consulting and EdgeCase. Here’s what I’ve learned…

Beside many other brilliant things he said, Rob Stevenson demonstrated the
following (figurative – not literal) gem that will display all methods to which an
object will respond:

>> 1.methods.each { |i| printf "Method name: %s\n", i.to_s }
Method name: %
Method name: inspect
Method name: <<
Method name: singleton_method_added
Method name: &
Method name: clone
Method name: >>
Method name: method
Method name: round
Method name: rpower
Method name: public_methods
...

As Rob Biedenharn was setting up for the next session he had the contents
of his .irbrc file which among other things contained the following:

IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:AUTO_INDENT] = true
require 'rubygems'
def clear
  system "clear"
end
alias :cls :clear

Setting the irb prompt to simple removes everything but the two
“greater than” characters. The auto indent feature indents your
input automatically (duh!) according to Ruby code conventions which is
something Jim Weirich apparently didn’t know and although I would love to be
able to tell folks that I taught Jim something about Ruby i only learned it
by googling it two minutes prior to showing Jim. Since I use rubygems a lot
I add those in by default, and since I like to keep my screen clean so I
stole, eh…, I mean re-used Rob’s “clean” method setting an alias for called
“cls”. I combined this knowledge to create the following means to output a
sorted list of all methods to which a given object will respond:

def pretty_methods obj
  obj.methods.sort.each { |i| printf "%s\n", i.to_s }
end

alias :pm :pretty_methods

During the second hour of Ruby Introduction taught by Ron McCamish and coded by Rob Biedenharn I learned a new thing or three as the case may be about quickly getting at regular expression match data:

irb
>> b = /v(olly)?ball/
=> /v(olly)?ball/
>> str = "My vollyball is Tachikara"
=> "My vollyball is Tachikara"
>> str =~ b
=> 3
>> $`
=> "My "
>> $&
=> "vollyball"
>> $'
=> " is Tachikara"

Finally, I learned that I need to better understand closures, the difference between “detect” and “select”, and that I will never be able to code as well as Jim Weirich.

»  Substance: WordPress   »  Style: Ahren Ahimsa