Ben Tsai

Mainly technology.

Jan 22, 2012

Being a Better Programmer

I saw this in my twitter feed:

I watched through the whole thing, and it is indeed an impressive collection of tips to becoming a better programmer. The videos cover a breadth of topics in a short period of time. To give you a taste, the first unit covers managing complexity, the single responsibility principle, separation of concerns, TDD and design patterns. And that's only the first 2 minutes. The total running time is 20 minutes, so you should watch them:

The videos have a strange feel to them, since they use public domain clips overlaid with After Effects-generated titles and effects. The visuals are not crucial and more often than not, result in curious juxtapositions of software wisdom with campy footage. Regardless, the content is great.

Jan 19, 2012

How to retrieve an off-screen window

Currently, I'm working on a bug fix for the case when you've closed our application on a secondary monitor, then disable that monitor (e.g. when undocking a laptop), and then start up the app again. The problem is, we try to restore the window position, and it ends up off-screen and completely hidden from the user.

This happens occasionally with apps that don't behave politely. As a workaround, you can retrieve the window like this:

Alt-Space M <any arrow key>, then use the mouse to move the window.

What this does is open the command window and select the Move option. The arrow key then allows the mouse to take over the move.

Jan 18, 2012

What does the "d" in `git svn dcommit` stand for?

Apparently, it stands for "delta" (via @DaveWilkinsonII). But I like this answer better:

Jan 17, 2012

CSS background opacity

How to adjust the opacity of the background of a div without affecting child elements:

.alpha60 {
    /* Fallback for web browsers that doesn't support RGBa */
    background: rgb(0, 0, 0);
    /* RGBa with 0.6 opacity */
    background: rgba(0, 0, 0, 0.6);
Jan 17, 2012

Reducing friction and Scriptogram's new text editor

I'm really loving how Scriptogram has been pumping out useful, high-quality features. I'm typing this post in the new text editor, which lets you compose a post directly from the browser. When I first saw that this was on the upcoming feature list, my impression was that this shouldn't be a high priority. One major advantage of having posts be synced from Dropbox files is that you can use whatever text editor you want locally.

But what this feature does is reduce the friction of writing posts even more, and that is a powerful idea. Even though the text editor is fairly bare bones (no support for links, no HTML preview, no auto-save), it eliminates the overhead of navigating the file system, creating and naming a new text file, and typing in the proper header. John D. Cook wrote a post explaining this concept that a little simplicity goes a long way:

Sometimes making a task just a little simpler can make a huge difference. Making something 5% easier might make you 20% more productive. Or 100% more productive.

This is a huge reason why I'm so enamored by these blogging services that use Dropbox. There are plenty of blogging tools and services out there that make it easy to blog: Posterous, wordpress, tumblr, etc. Indeed, they've done a remarkable job of lowering the barrier of entry. But why do I like Scriptogram the most? It's a little bit easier and simpler. There may actually be the same number of steps, but another component is the cognitive overload that it reduces. With Scriptogram, I'm simply editing a text file on my computer using Markdown. I'm limited by Markdown's formatting abilities, which is a good thing. That little bit has been the deal-breaker and the reason for more posts as of late.

This also partly touches on why "simple" apps are all the rage and the notion that "less is more." From 37 Signals' Less Software chapter from Getting Real:

  • Less software is easier to manage.
  • Less software reduces your codebase and that means less maintenance busywork (and a happier staff).
  • Less software lowers your cost of change so you can adapt quickly. You can change your mind without having to change boatloads of code.
  • Less software results in fewer bugs.
  • Less software means less support.

Software is incredibly complex. I want to have the minimum possible. It's always a victory to me when I can get rid of code.

Jan 10, 2012

Markdown and Blogging and Dropbox, Oh My!

There are a bunch of new blogging services that have surfaced recently that share quite a few similarities:

  • Use Markdown for the post medium
  • Use Dropbox for syncing and delivery
  • Boast simplicity and ease-of publishing
  • Emphasize clean design

I first heard of Calepin a few months ago. I liked the experience of creating posts locally using Markdown, hitting the "Publish" button, and seeing it live with minimal hassle. I even looked into migrating my wordpress blog to use Calepin exclusively. There was one minor niggle1 I had with the service: there is no way to view all (or recent) posts on one page, nor previous/next links on posts. And no plans for that. I've always preferred to view a blog's content on a single page and found it annoying to manually step articles post by post.

Then, in the past week or so, two new services cropped up: Skrivr and Scriptogram. The former seems to differentiate itself with emmaculate typography and attractive themes. The latter is eerily similar in many ways to Calepin, but plans to support themes. Two things I liked about the newer services is that they do display all your posts on one page.


  • First kid on the block
  • Developer has a specific vision and good design sensibilities
  • Premium plan in the works

I appreciate that Calepin's developer is highly-opinionated and sticks to his guns. He's decided not to allow custom themes or CSS, and each post gets its own page. It's clear he has a vision for his service and a plan to sustain it.


  • Beautiful themes out-of-the-box
  • Quirky method for specifying posts
  • Invite-only
  • Customizable

Skrivr sports good-looking themes and a responsive layout out of the box. Creating a post feels kludgy; you're forced to give every post a category, and metadata is pulled from the filename. The service is currently invite-only, though the owners quickly sent me an invite when I asked. The themes are also very customizable, but to a fault. I don't want to mess with templates.


Just like Calepin, but:

  • Custom CSS
  • All posts on single page
  • Free

When Scriptogram first came out, I ignored it because it seemed like such a rip off of Calepin. The publish page had the same three-column layout and workflow, so I assumed it was some disingenuous script kiddie. But it's become apparent that this is not copycat2. In the past week, the developer has rolled out custom domain support and a nice CSS editor. It's a bit worrisome that he plans to keep the service free. But for now, I like it the best. It's easy to use and just flexible enough for my needs.

  1. Why did I start using this word? 

  2. Though one day, I'd love to hear an explanation for how the publish screen ended up being so similar. 

Jan 10, 2012

Best way to show code snippets in word?

What's the best way to show code snippets in word?

  1. go to "insert" tab, click "object" button (it's on the right)
  2. choose "openDocument Text": it will open a new embedded word document
  3. copy paste your code from Visual Studio / Eclipse inside this embedded word page
  4. save and close

Go upvote this answer right now.

Jan 9, 2012

Internationalization in MFC

For internationalizing an MFC application, it sounds like there are two main approaches:

  1. Compile and deploy resource-only DLLs.
  2. Extract and replace all strings with the localized version.


Jan 9, 2012

Scriptogram Guide



The selector for the h1 in the header is body > h1. Here is how I accomplished adding my avatar:

/* Title */
body > h1 {
  padding-left: 48px;
  height: 40px;
  background-image: url(;
  background-repeat: no-repeat;
  background-size: 40px;

Drafting a post

  • Create a new file in posts entitled ""
  • Set the metadata to be:
Published: false
Title: Post Title
  • Once you're ready to publish, change the metadata to be (remove Published field and add Date:
Date: 2012-01-11
Title: Post Title

Markdown particulars


<blockquote class="twitter-tweet" data-in-reply-to="156382260231290880"><p>@<a href="">bentsai</a> cheers!</p>&mdash; (@scriptogram) <a href="" data-datetime="2012-01-09T14:31:26+00:00">January 9, 2012</a></blockquote>
<script src="//" charset="utf-8"></script>


I'm intending on writing a guide for Scriptogram[^1].

[^1]: But for now, I'm just testing out footnotes.

I'm intending on writing a guide for Scriptogram1.

  1. But for now, I'm just testing out footnotes. 

Dec 23, 2011

Flaky iPhone Home Button Workaround

I recently answered a question on

...I wanted to offer up some useful information that I learned from the Apple Store. The home button on my wife's iPhone 4 was acting flaky, so we brought it in to a technician. After asking whether we've tried a soft, hard and factory reset, he notified us that, barring those solutions, they could replace the phone for $149 (not free since it is out of warranty). But then, he also offered a workaround that I was not aware of: AssistiveTouch.

Basically, this iOS 5 feature allows you to access some system-level functions from an onscreen menu. In particular, this gives you a software home button, and it's baked into the OS! It even responds to double and triple taps. If your home button is flaky or broken, this is a robust workaround. This also comes in handy if any of your other hardware components are broken. You can mute/unmute, do a "shake", adjust volume, and rotate/lock screen from this menu.

To access it, go to Settings->General->Accessibility:

Scroll down to the Physical & Motor and tap AssistiveTouch:

You will get an overlayed touch target, which opens a menu where you can operate the home button, among other things:

Using the Assistive Touch feature, you can also save custom gestures and initiate multi-touching using only one finger, although I haven't found any use for this yet. There isn't much documentation on this feature; it's one of those hidden gems that will prove especially useful with aging hardware.