Author Archive

June 7, 2010: 6:23 pm: DanGadgets, Software Tools

I recently spent some time as a guest of the Ontario judicial system. No, not as a prisoner, something much more unpleasant: jury duty.

Recommended Reading
Recommended Reading

This is the second time in five years that I’ve “done my duty”, and in both instances the week consisted of 99% waiting around and 1% being rejected out-of-hand by defense counsel. I am, of course, crushed by the repeated rejections, but I managed to get some benefit from the other 99% of my week by reading a software development e-book.

When I went through this five years ago, I did my reading on a Dell Axim running Windows Mobile 5.0. You laugh, but let me tell you that one thing it did really well was copy and paste. You selected the text with the stylus (stop laughing), used a button to toggle to Word and pasted the text in. A task so simple even Windows Mobile could handle it.

Five years later, I’m using an iPhone. In technical terms, the iPhone is a Porsche and the Axim a Yugo. But when it comes to copy and paste, the Porsche is a freaking nightmare to drive.

The problem isn’t so much with the iPhone as with its apps. Very few of e-readers allow you to copy text into the clipboard. It’s bizarre! Do they think we don’t want that feature (we’re too dumb), or do they not trust us to use it responsibly (we’re too dishonest)? Either way, it’s insulting.

However, it’s not all doom and gloom. There are two very, very good apps that do support the clipboard, and a growing number of e-books that are compatible with them.

Stanza - march to a different drummer
Stanza - march to a different drummer

Stanza.   Stanza supports a long list of e-book formats, but unfortunately you are unlikely to encounter most of them when buying e-books. The 3 exceptions are:

  1. eReader – This is a “secure” (piracy-protected) format that is used by Fictionwise and Books on Board for most of their books, and by Barnes and Noble for many of them.
  2. ePub – The ePub format supported by Stanza is not “secure”, which unfortunately makes it harder to find (we’re dishonest, remember).  However, if you’re a computer geek then you’re in luck: O’Reilly and Microsoft Press offer ePub editions of almost all of their publications.
  3. PDF – Support for PDF format documents was added to Stanza last week.  Unfortunately, its copy support is pretty inconsistent, often copying gibberish to the clipboard.
GoodReader - not bad!
GoodReader - not bad!

GoodReader. GoodReader supports just one format, PDF, but that’s still the most commonly used format for technical publications. I’ve raved about this app before, and I’ve grown more and more impressed with it over time. They added clipboard support a couple of releases ago, and while its not the most convenient implementation (you can only copy a full page of text, not selected text), it is fast and reliable, just like the rest of GoodReader. I’ve yet to find a PDF that GoodReader couldn’t handle — amazingly, it loads 100 meg monsters faster than my desktop PC.

Once you’ve filled the iPhone’s clipboard, your options for pasting text are much better.

You might find that the built-in Notes app is good enough for this task. I use Pastebot – a lot of people rave about its advanced formatting features and automatic synchronization (Mac only), but I like the fact that it automatically saves the clipboard contents when you open the app. If you need to format the text after you paste it (change fonts, italics, etc.), you should consider Documents To Go. I’m really impressed with how quickly it manages to bring you back to your last spot in a document without multitasking — the app is ready to paste a couple of seconds after you click the launcher (on an iPhone 3GS).

The new iOS 4 will make the copy-and-paste process somewhat smoother with its support for multitasking and fast app switching: it might even be able to compete with Windows Mobile 5!

One last piece of good news: O’Reilly (and associated publisher, Microsoft Press) continue to make most of their books available as very inexpensive iPhone apps, generally $5 or $6. That’s the full book, pictures and all.

If you’ve bought one of these apps, you were probably disappointed to find that clipboard support was disabled. This seems to be related to the underlying version of Stanza (which their apps bundle with the e-book). For some reason Stanza quietly disabled clipboard support in an update to their app last year, then quietly re-enabled it in the next update. Hmm.

While O’Reilly continues to use the clipboard-disabled version of Stanza, it is easy enough to do the upgrade yourself. Just follow the process described in my earlier post to extract the ePub from the O’Reilly / Microsoft Press book app, then import the ePub into Stanza using their desktop app or a URL link.

I’m pretty sure that O’Reilly is OK with you doing so — as mentioned in my earlier post, it was O’Reilly themselves who originally documented the process. If not, maybe I’ll get yet another opportunity to read e-books as a guest of the Ontario judicial system!

May 28, 2010: 1:16 pm: DanProgramming

Like many developers, I’ve bounced between various relational databases on my coding projects, primarly DB2, SQL Server and Oracle.  If someone asked me if the SQL I write is compatible with all three, I’d sheepishly admit that most of it is.

Sheepishly, because generic, cross-platform SQL tends to be inefficient SQL.  You can get away with it when working with modest amounts of data and users, but it’s still lazy, shoddy work.

Although not obvious from its title, SQL Cookbook is actually a great way to hone your SQL-writing skills, taking advantage of the powerful, vendor-specific features available in each major RDBMS brand.  (The specific types of RDBMS covered by the book are DB2, SQL Server, Oracle, MySQL and PostgreSQL.)

The book’s format is to present a problem, such as creating a pivot table or generating a delimited list, then provide one or two solutions to the problem for each type of RDBMS.  Sometimes the same solution works for multiple RDBMS, but in most cases a particular RDBMS has proprietary functions that result in a shorter or faster piece of SQL.

A notable example are “window functions” (also known as “analytic functions” in Oracle).   They are a relatively new technology, having become an ISO SQL standard in 2003, but all recent versions of the major RDBMS products implement them to some extent.  An example from Oracle is the following, which returns each employee’s department and the # of employees in that department.

select ename,
deptno,
count(*) over (partition by deptno) as cnt
from emp

The generic/lazy way to implement that is with a subquery or joined query that returns the number of employees in each department, such as:

select e.ename,
e.deptno,
(select * from emp where deptno = e.deptno) as cnt
from
(select ename, deptno from emp)

The latter approach works, but it’s more complex and less efficient than using a window function.

If you’ve been writing SQL for more than 10 years, you learned to do it the long way and probably haven’t been forced to change your ways since.  To learn about window functions, Appendix A of SQL Cookbook is a great place to start.

Another example is Oracle’s ability to return an object from a subquery.  I had always thought it was a cardinal rule (and major pain-in-the-ass) of SQL: subqueries can return only 1 field.  I couldn’t tell you how many times I’ve pasted multiple copies of the same subquery into a SQL statement because I needed to return a few different fields from it.  I knew that it would hurt performance, but what option did I have?

It turns out that, when using Oracle, an option is to return those fields in an object.  For example, the following query returns a couple of fields from the department table for each employee:

select
x.deptno,
x.ename,
x.multival.val1 dname,
x.multival.val2 loc,
x.multival.val3 today
from
   (select e.deptno, e.ename, e.sal,
     (select generic_obj(d.dname,d.loc,sysdate+1)
     from dept d
     where e.deptno=d.deptno) multival
   from emp e
   ) x

I also liked the format of SQL Cookbook.  As the title suggests, one way of using the book is as a reference.  If stuck on a SQL coding problem, you can run through the table of contents, looking for a problem description that is similar to your own.

However, I found it worthwhile to read through the book chapter by chapter.  Every piece of SQL is accompanied by a detailed but easy-to-follow narrative describing how and why it works.  By reading these sections you’re sure to add a lot of new tools to your toolbox, even if you don’t need to solve the specific problem covered by that “recipe”.

Also, since the book separates the solutions by RDBMS, you’ll probably find that you can skip at least 50% of the book (for now),  focusing only on the one or two RDBMS systems that you are currently working with.  It’s refreshing to come across a software development book that can realistically be read in a week.

With the emergence of alternative ways of interfacing with databases, like LINQ, CouchDB and the various technologies gathering under the “NoSQL” banner, the day might come when crafting SQL statements is a dying art.  A parallel might be drawn between SQL today and assembly language in the past — increasingly less important as higher level languages and the underlying hardware grow stronger.  However, if this happens the remaining “artists” who’ve mastered SQL will be much in demand.  This book is a good step towards raising your SQL to a higher level — from Betty Crocker to Julia Child, if you will.

May 25, 2010: 5:01 pm: DanGadgets

I was pleasantly surprised to find that the latest iTunes patch, version 9.1.1, fixed a problem with Audible audiobooks on my iPhone and iPod Touch.

Previously, whenever I added new content from Audible I would lose my current place in whatever audiobook I was listening to. The next time I listened to the audiobook it would start playing at the beginning of the book. I know that it seems like a nit, but since I subscribe to a couple of daily Audible “podcasts” (Charlie Rose FTW, w00t!), it was a nit I encountered almost every day.

Nice to get some noticeable value for my 102 megabyte “patch”. Considering that the bug was introduced at about the time OS 3 was released, and OS 4 looms just around the corner, I wonder if I’ve seen the last of this one. Audible announced (well, twittered) a couple of months ago that they were working on supporting wireless downloads on the iPhone — will we finally have an app for that?

September 14, 2009: 7:29 pm: DanProgramming, Software Tools

A few months ago, technology publisher O’Reilly began selling some of their books as iPhone apps [iTunes link] for a surprisingly low price — generally just $5.  These are the full versions of the books, not just an extract.  The apps come bundled with Lexcyle’s Stanza e-reader, which is feature-rich, fast, and stable.  All things considered, these books are quite a bargain.

There is a catch, of course:  for some books, and many humans, the iPhone isn’t the best reading platform.   Books about software development and tools are generally most useful when you are working hands-on at your computer.  Switching from the iPhone to the PC is rather awkward, and copying and pasting code fragments from the iPhone to your computer is pretty much impossible.  (Stanza, unlike Kindle, does support copy and paste of text by way of their annotation feature, but getting that copied text onto your computer is a byzantine  procedure).

Fortunately, O’Reilly chose to package their e-books using the open ePub standard, without ePub’s optional DRM (Digital Rights Management) encryption.  This means that it’s relatively easy to extract the ePub document from the iPhone app, at which point you can read it on whichever platform you choose.  The number of software and hardware e-readers that support ePub is rapidly expanding (with one notable holdout), and it is widely expected that ePub will eventually replace today’s myriad incompatible formats.

The following method for extracting the ePub document from one of O’Reilly’s iPhone apps is based on an article on the excellent TeleRead site.  The packaging of the apps has changed a little since that article was written, so a couple of extra steps are required.  I use a Windows PC, but I’m sure a similar approach would work on a Mac since the only software tool required is one that can read and write .zip files.

  1. Locate the iPhone app file.  The easiest way to do this is to right-click on the app in iTunes, then select “Open in Windows Explorer”.  The example I’m working with is the wonderful Coding4Fun book (which costs $32 when bought as an eBook right now), and its app file is named Code4Fun 1.0.ipa.  Copy the .ipa file to another folder so that you won’t confuse iTunes with the following steps.
  2. Extract the contents of the .ipa file.  Despite the extension, this is a zip-compressed file.  Most zip extraction tools (like 7-Zip in the following screenshot) are quite happy to take a whack at opening the file without knowing what an .ipa is, but if necessary you can rename the file to Code4Fun.zip first.

    A zip in app's clothing
    A zip in app's clothing
  3. The contents of the app should consist of a couple of files and a folder named “Payload”.  If you open Payload you’ll find another folder named Code4Fun.app. Another level down is a folder named “book”, as shown in the following screenshot.  (Incidentally, the parent folder of “book” also contains a file named default.pub.  This is actually a bonus ePub book: The Time Machine by H.G. Wells.  I don’t think you can get at this book from within the Code4Fun iPhone app – it presumably is there as part of the Stanza packaging).

    In the book, is a book
    In the book, is a book
  4. Select the contents of the “book” folder (2 folders and a file) and add them to a new .zip file, as shown below.

    A ePub in zip's clothing
    A ePub in zip's clothing
  5. That .zip file is actually your ePub document, so rename it to something more suitable like Code4Fun.pub.  At this point you should be able to open the .pub file in Adobe Digital Editions, or MobiPocket Reader, or Stanza Reader.  (Mobipocket and Stanza are generally used on mobile devices, such as Blackberry or Windows Mobile smartphones, but both offer a  desktop reader).  My own preference is to keep things simple and flexible by using the browser-based Bookwork reader.

Enjoy, but please, please don’t pass along the .pub file to your friends (or, worse, a Torrent site).  O’Reilly is doing us a great favour by selling these ebooks at such a low price and supporting the open ePub standard.

I’m pretty sure that O’Reilly is OK with you extracting the .pub file for your own use — it was an article on an O’Reilly site where I first came across this procedure.  Other companies would have you believe that DRM-encrusted proprietary standards are the only way to prevent the unwashed masses from pirating ebooks.   Please don’t help them to prove their point.

September 9, 2009: 4:56 pm: DanSoftware Tools

I recently switched browser preferences from Firefox to Google Chrome.  I was forced to make the change by a lack of RAM — the software development tools I use eats up most of my RAM, and Firefox has become so bloated over time that it wants 300M of its own to display a few tabs.

It was hard to give up all of the Firefox plug-ins that I had grown accustomed to, especially XMarks and, ironically, the Google Toolbar.  However, I love the fact that Chrome opens in seconds and uses about 1/3 the RAM of Firefox.  I’ve yet to come across any web pages that Chrome can’t render, and it has never crashed.  I like the concept: a relatively thin, fast and stable platform for web content.

However, having decided to commit to Chrome as my browser I was surprised to find Chrome wouldn’t accept me!  When I tried to set Chrome as my default browser, I saw the following: no “Default Browser” button.

OK.  Now what?
OK. Now what?

This doesn’t seem to be a widespread problem.  I found a reference to a long-fixed incompatibility with Vista (one of the smart things about Chrome is is automatically updates to the latest version), and a suggestion to run Chrome as an administrator if the Default Browser button wasn’t displayed.   However, I am an administrator, and I run XP.   Freaky.

I still don’t know what the problem is, but I stumbled across a solution.  It seems that the Default Browser button is there somewhere, lurking off screen.  You can’t get to it by clicking, but you can by tabbing.  So:

  1. Click the Default search combo so that it has the focus (i.e. it is highlighted in blue, as in the screenshot below).
  2. Press Tab.  The focus should move onto the Manage button.
  3. Press Tab again.  The focus highlight will seemingly disappear.  It’s actually on the Default Browser button.
  4. Press Enter. This will trigger the off-screen button, and you should see the message change to “The default browser is currently Google Chrome”.
Together at last
Together at last

Talk about playing hard to get!