tobym’s posterous

Git merging branches

With git, to pull in changes from another branch but not commit them, you'd think running 'git merge --no-commit ' would do the trick. Well, you'd be wrong because "merge" is an overloaded word. It's specific meaning in git is to combine histories, not working files. If there were no commits on the original branch, then it just fast-forwards and --no-commit still commits - a bit counterintuitive. Solution is to run 'git merge --no-ff --no-commit '.

Loading mentions Retweet

Comments [0]

Website speed benchmarking from command line

I wanted to test the speed difference of a Wordpress blog before and after WP-Supercache was set up. Here's how I did it, using just bash, curl, sed and awk: 

Basically, time how long it takes to get the website about 100 times, and get the average. For my non-cached site on a low end Linode VPS this took between 0.8 and 1.3 seconds. After setting up WP-Supercache, the average time dropped to under 0.5 seconds -- a 40-60% improvement in pure speed. So, WP-Supercache works!

Bonus: I ran the same script to load the page 100 times while running top on the server and eyeballing the numbers. The results were impressive - with no caching there were 2-5 apache processes running, each taking about 5% memory and 8% cpu. That is a recipe for disaster and the site would probably last about 2 seconds before dying under the Digg effect. With WP-Supercache fully enabled, there was only a single apache process running, consuming 5% memory and virtually no cpu.

If you're interested in more detail about how the command line stuff works, here is a brief explanation. The first loop runs 100 times, piping the output of time to a text file. The curl command itself (the one being timed) is executed in a subshell and its output is discarded). The second loop is identical, just saving to a different file to record the new speeds.

The last line is meant to be saved as an executable file so it is convenient for reuse. It takes two arguments, a file and the type of time you want the average of (from the time command; you want "real"). So the script prints out the file with cat, separates the actual time value nicely with a search-and-replace regular expression with sed, then uses awk to find the average by looking at the correct times (real/user/sys), counting those lines and summing the total, and dumping the average when complete.

It took me longer to write this brief post than it did to come up with that script. There must be commercial or free benchmarking software for websites that exists, but this worked for me and didn't require any wasted time searching and evaluating other options.

 

Loading mentions Retweet

Comments [0]

vim - insert date and time directly

I always used to insert date/time into vim by running

:r!date 

which inserts the full date in its own line. Well and good, but if you want to insert on the current line it would take you a few keystrokes. And if you want just the time inserted...well text expansion is a perfect candidate for this. The following code lets you type 'ptime' in insert mode and it gets replaced with the current time (e.g. 3:28 PM). Cool.

Loading mentions Retweet

Comments [0]

ctags and javascript

Exuberant ctags isn't very good at JavaScript by default, and misses a lot of function definitions. Put this in your .ctags file for much better parsing:

(via http://weblogs.asp.net/george_v_reilly/archive/2009/03/24/exuberant-ctags-and-javascript.aspx)

Loading mentions Retweet

Comments [0]

Remap Caps Lock to Ctrl on WinXP

Best way to remap your Caps Lock key on Windows XP is to copy this into a text file called "CapsLockToCtrl.reg":

REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00

Save it, double-click to add to the registry, and restart. Voila! Your caps-lock key is now another Control key. 

(I say this is the "best" way, because the first registry edit I made also disabled the Windows key, which was an undesired side-effect.)

Loading mentions Retweet
Filed under  //   capslock   productivity   remap   winxp  

Comments [0]

Bill Gates on Chinese Piracy - smart guy

Bill Gates didn’t crack down much on Chinese piracy because they were a developing country. they much rather would have people pirate their software than other peoples’ software, and Gates believed that they would pay later because of the then-majority of software being Microsoft. and—they did pay later and is now a huge market for Microsoft

(via YCombinator's 2009 Startup School presentation from Chris Anderson, summary from http://journal.markbao.com/2009/10/startup-school-2009-summary/)

Loading mentions Retweet

Comments [0]

Can't Log in to Drupal with Internet Explorer? Fix your domain name.

I was testing a near-completion Drupal website today, and noticed that I could not log in with Internet Explorer (8). Firefox worked, Chrome worked, Safari worked...so what was the problem? Turns out there was an underscore in the domain name, and that gave IE fits. I changed the subdomain to use a dash instead, and the login worked.

Loading mentions Retweet
Filed under  //   drupal   ie   ie8   login  

Comments [0]

Web Ads should all have forward/back buttons

Sometimes I see an ad that I actually want to look at, but lose it because the ad spot refreshed and put something new in its place. Ad spots should really have forward/back buttons. Google does this with Web Clips in Gmail, and the text block ads have this as well (not sure if they all do, or just sometimes, but I have seen it).

The benefits are obvious - if a user clicks a forward or back button, then their engagement is pretty strong and the impressions per page skyrocket. Also, those buttons could really turbocharge analytics for "best performing ad" in a sector.

Loading mentions Retweet
Filed under  //   advertising   idea  

Comments [0]

Goodbye, TechCrunch

A week or two ago, I removed TechCrunch and some similar sites from my feed reader. I'm a voracious consumer of RSS feeds, but recently decided there was a serious need to fix the signal-to-noise ratio. Since I started reading TechCrunch, it changed from a stream of interesting tech business news to a fountain of sensationalist headlines. Some of the content is great, but the noise is too much. My theory was that even if I never directly read TechCrunch, the best of the bunch will get to me anyway through Twitter or Digg. So far that theory has proved unequivocally correct.

Other sites to get the axe were New York Times and (tragically) Wired Top Stories. I tried filtering the feeds through Postrank to view only the higher post-ranked entries, but "popular" as defined by Postrank doesn't necessarily capture "interesting". I would also guess that it might end up selecting the silly, sensationalist, and controversial articles that drove me away from TechCrunch in the first place, because by their nature of being controversial, there would be lots of activity on the page. Postrank is a neat idea though, and I've played around with my own algorithm to accomplish a similar goal; maybe I will release it at some point.

Loading mentions Retweet
Filed under  //   rss  

Comments [0]

Make Apple Mail.app work nicely with Gmail

Gmail's web interface has suffered some downtime recently, no doubt sparking panic among many users. However, the IMAP connection has stayed up, meaning that if you use a 3rd party email program (like Mail.app or Outlook), then you could have used Gmail without interruption. You may not even have noticed the downtime if it wasn't for the thousands of tweets lamenting the outage!

Here is a guide on how I use Gmail and Apple's Mail.app interchangeably. 

Gmail Strategy
I archive all messages after they have been dealt with to keep my actual Inbox down to a reasonable level (i.e. less than 25). "Dealt with" means either:
  • responded to
  • read (no response needed)
  • labeled TODO (sometimes I leave messages read and in my inbox as a pseudo-todo item since I know they aren't done until they are archived and out of the inbox)
Emails are also categorized with with labels. All work emails get a generic "work" label, and specific "project name" labels.

This enables me to reduce clutter almost entirely. I find emails through labels, or through searching directly. My "to-do" list is my actual inbox, plus emails labeled "todo". I can always narrow that list down by searching something like the following -> "label:todo label:acme_project" which quite obviously will turn up only todo items that are for my Acme project. 

Mail.app Strategy
I want it to be synchronized with my Gmail inbox, and I want the ability to archive mail. I do not want a full copy of all my archived mail. It takes up too much space, and I'm satisfied with Gmail doing the bulk of the storage. For important emails that need a backup, I make a mailbox in Mail.app (Mailbox -> New Mailbox) and save a copy there. 

IMAP and Labs to the rescue!
Set up Gmail:
  1. Enable IMAP. (Gmail Settings, then "Forwarding and POP/IMAP", click "Enable IMAP", then click "Save Changes.)
  2. Enable Advanced IMAP Controls (Gmail Settings, then "Labs", then click "Enable" next to "Advanced IMAP Controls")
  3. Go back to "Forwarding and POP/IMAP" and set the following:
    1.  "Auto-Expunge" to "Immediately expunge messages when I mark them deleted in IMAP"
    2. "Archive the message" when a message is expunged from the last visible IMAP folder.
    3. Save changes!
  4. Select only pertinent labels/folder. 
    1. Go to "Labels" in Gmail settings, where you will now see a checkbox next to each label which says "Show in IMAP".
    2. In "System labels", uncheck Chats, All Mail, and Spam. Check Inbox, Starred, Sent Mail, Drafts, and Trash.
    3. In "Labels", check [Gmail]Trash, [Imap]Drafts, [Imap]Sent, [Imap]Trash, and any labels that you want quick access to through Mail.app (I have my current work projects checked, and my "todo" label). 

Set up Mail.app:
  1. Add your Gmail (IMAP) account if you haven't already by going to Preferences, Accounts, and click the + button. Enter your account information, and be sure to select IMAP (not POP) and use incoming mail server "imap.gmail.com". (Outoing is "smtp.gmail.com").
  2. Select that account, then go to Mailbox behaviors, and UNCHECK "store deleted messages on the server". ("Move deleted messages to the Trash folder" should be checked).

What does this get you?
Primarily, two things. First, when you delete a message from your Mail.app inbox, Gmail archives it. This leaves your inbox nice and clean, and the message is still accessible. Second, Mail.app does not try to synchronize thousands and thousands of irrelevant messages. 

Also, flagging/unflagging a message in Mail.app is synchronous with starring/unstarring a message in Gmail. Also, moving a message in Mail.app to the imap folder "todo" is the same as labeling the message "todo" and then archiving it, so you can use the exact same workflow in Mail.app as you do with the Gmail web interface.

Weaknesses
Obviously, you don't have access to all your labels in Mail.app. For me, this is not a big problem as the 80/20 principle applies here -- most of the time I don't need to access most labels. The majority of my incoming emails are auto-labeled already with filters, so archiving them is the only action I need to take. For the rare email to which I want to add a different label before archiving, I just leave it in my inbox and get to it then next time I'm on the web interface. If that bothers you, make a label called "to_label" and show it in IMAP; then you can move the email out of your inbox and into a "needs categorization" bucket that you can get to when you have time.  

EDIT:
In Mail.app's preferences, select the gmail account, go to Mailbox Behaviors, and un-check "Store draft messages on the server". This will prevent strange half-written drafts from being displayed in your Gmail conversation thread. From Gmail, there's no way to tell if that half-written draft was sent or not (and it looks like it was sent). 

Loading mentions Retweet
Filed under  //   gmail   mail   mail.app  

Comments [0]