Archive

Archive for February, 2010

Yes, You Can Applescript “Unscriptable” Applications (like Preview)… A Little

February 13th, 2010 No comments

Even though Preview doesn’t advertise scriptability, it at least responds to events needed by GUI applications in Mac OS X, including open…

From Mac Dev Center:

Apple Events Sent by the Mac OS
The Mac OS takes advantage of Apple events to communicate with applications, such as to notify an application that it has been launched or should open or print a list of documents. Applications that present a graphical user interface must be able to respond to whichever of these events make sense for the application. For example, all such applications can be launched and quit, but some may not be able to open or print documents.

So you can just say, for example:

tell application "Preview" to open POSIX file "/path/to/file.jpg"
Categories: Uncategorized Tags:

Premature optimization – wait, I learned that 10 years ago

February 12th, 2010 No comments

In reading Refactoring: Ruby Edition, I’m “learning” a lot of things that I already know, lol.

Optimization vs. Clarity

For instance… how many times have I heard “avoid premature optimization?” Yep, check, got that one; I would never do that.  Except I do!  I mean, I won’t go out of my way to optimize at first.  But I’m in this loop, and I want to record this other information that has nothing to do with what I’m doing right now… Let me just throw it in this temporary variable to use later.

Judges (Fowler, Beck, et al.).  Buuuuzzzzzzz, wrong answer.  Their advice (and you may not believe this, but I actually feel free now that it’s sunk in): don’t optimize with that temporary variable now, just code for clarity and repeat the loop as many times as it takes to get the info you need.  “Holy crap,” I thought.  “I’m not going to repeat that loop three times – that’s so inefficient!”  But luckily, the authors could sense me squirming in my seat, and added that I shouldn’t worry because, although this idea frequently causes “angst” in their presentation audiences

almost all the time extra method calls won’t matter; in the rare cases they do, they can be dealt with later

This is great, Kent Beck gave me permission to repeat loops over and over if the code is cleaner!

Categories: Programming Tags:

A Small but Effective Tweak to Vim’s snipMate plugin

February 6th, 2010 No comments

Already awesome

If you haven’t tried snipMate, you have to give it a test-drive.  If you want to define a new ruby class in Vim, type “cla<tab>” and you’re presented with your choice of class templates:

Enter a number, and the code is automagically generated for you.

The tweak

By default, hitting enter at the menu cancels the snippet.  However, a user can already easily cancel using escape, and this probably won’t happen all that often anyway (I don’t think ever for me).  So I altered the code to choose the first (most common) snippet if no number is entered.  This saves me a non-home-row keystroke in almost 100% of my usage.

The code

In plugin/snipMate.vim, comment out the last line of the s:ChooseSnippet function and add two lines in it’s place:

fun s:ChooseSnippet(scope, trigger)
  [snip...]
  " Original last line (which cancels on enter) commented out
  "return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1]

  " Two lines added to choose first snippet if none are selected
  let snip_to_return = num == -1 ? 0 : num
  return s:multi_snips[a:scope][a:trigger][snip_to_return][1]
endf

Pretty simple, huh? Oh, just remember to save a copy of the changed lines somewhere.  When you update the plugin, your changes will be erased and you’ll have to re-paste them.

Categories: Programming Tags:

windows 7 product key

windows 7 product key

windows 7 key generator

windows 7 key generator

free winrar download

free winrar download

winzip activation code

winzip activation code

free winrar

free winrar

winzip free download

winzip free download

winrar free download

winrar free download

winrar download free

winrar download free

winzip free download full version

winzip free download full version

windows 7 activation crack

windows7 activation crack

windows 7 crack

windows 7 crack

free winzip

free winzip
\n