Technology

Setting the timezone

I’ve gotten pretty careful about keeping time in UTC and then converting it to localtime for the user to understand. For the first time, I actually had to find the localtime in a non-local timezone. It’s ugly. It seems you have to mess with the TZ environment variable. Here’s what I wrote:

#include 

And here’s a code fragment that uses it:

std::string oldzone = changeTimeZone("US/Pacific");
time_t  seconds = ::time(0);
struct tm   tm_time;
localtime_r (&seconds, tm_time);
changeTimeZone(oldzone);
Technology

Cars and Batteries

Fascinating profile of
Shai Agassi who’s introducing replaceable batteries for the auto industry. Part of his theory is that selling the “energy” is very profitable.
>But Agassi realized he needed one more breakthrough: some way to rapidly charge a vehicle. No drivers, he knew, will tolerate a two-hour wait to recharge when they’re on a 500-mile haul. Then one day, he and an automotive engineer were chewing over an impractical method for quickly replenishing batteries. The engineer wondered aloud: Wouldn’t the fastest way to charge an electric car be to simply replace the battery?

4C6C9BC9-7284-4EB2-910B-F0AB01834593.jpg
NYC · Politics · Technology

A new car?

Maybe I can finally buy a new car?:

The Schumer-Israel approach would provide vouchers worth up to $4,000 to drivers who turn in an older car that gets 18 miles per gallon or worse and buys a new or used car that exceeds the corporate average fuel economy for vehicles in its class by 25 percent. Taken together, these two requirements guarantee considerable oil savings and significant reductions in carbon dioxide.

Technology

Google Voice/Grand Central vs. Skype

I decided to give Skype a try, again, after I started working with a few people that use it for chat, teleconference and video conferencing.
Contrary to what some people are saying, it seems like a complementary offering to Google Voice. I spend a lot of time in front of my computer and there’s a certain benefit to being able to call and be called from it. But I’m not about to give out my skype phone number for people to call — I don’t always have a computer on.
On the other hand, if I add my Skype phone number to Google Voice and gave out the Google Voice phone number, than rather I wanted to answer a call from my computer, my cell phone, or my home phone becomes irrelevant.
From NY Times: Google Voice May Threaten Other Phone Services:

Google Voice allows users to route all their calls through a single number that can ring their home, work and mobile phones simultaneously. It also gives users a single and easy-to-manage voice mail system for multiple phone lines. And it lets users make calls, routed via the Internet, free in the United States and for a small fee internationally.

Technology

Qt Labs Blogs » Lightning-fast JavaScript

Here are the performance numbers about Qt4.5’s improvement in JavaScript performance that I mentioned in yesterday’s post. It offers about a seven times performance improvement on ix86 processors. From Lightning-fast JavaScript:

For Qt 4.5, the JavaScript engine is powered by a new bytecode interpreter, along with optional JIT (just-in-time) compile support. They are often referred as SquirrelFish and SquirrelFish Extreme, respectively. This interpreter has been developed by Apple engineers working on WebKit in order to speed-up JavaScriptCore, the backbone of WebKit’s JavaScript engine. The interpreter makes its first appearance in the recent Safari 4 Public Beta, where it is dubbed as Nitro JavaScript Engine.

Longer is better:
44F6492C-A237-484F-86AF-8A6038ACC285.jpg
96FB80DE-1DC1-449C-803E-98AC6C88CDFE.jpg

Technology

Thunderbird and Gmail

In my quest for the ultimate email, rss, and newsreader I’m giving Thunderbird 3.0b2 a try. Check out this post for a few more details. So far, decent for email, decent for news, but it’s weak for rss.
First, read these two tutorials:

Then, you ned to figure out keyboard shortcuts
If you are curious about how messages get retrieved, check out this tidbit on IMAP and the “IDLE” command from Entire message fetched when opening a IMAP message:

mail.imap.fetch_by_chunks controls whether Thunderbird tries to fetch a message body (or any other MIME body part) in chunks. mail.imap.chunk_size controls the size of the chunk. It currently defaults to 10240 bytes. If you set the chunk size too big, it defeats any attempt to fetch just the message body. One problem with enabling fetching by chunks is it breaks the optimizations built into the TCP/IP protocols, and adds extra overhead as each chunk has to be acknowledged. If tweaking the “MIME Parts On Demand” preferences doesn’t help, or if it works but you get poor performance, try disabling fetching by chunks.

Technology

Suse 11.1, NFS, exportfs

I tried to mount an NFS volume on my MacBook at home and it was failing. I hadn’t accesed my NFS in a month since I updated to OpenSuse 11.1 or changed some network parameters.
Checking the logs on the server (/var/log/messages) showed this error:

mount request from unknown host

but the IP address seemed good. I checked the exported filesystems:

$ sudo exportfs
/home           192.168.13.*

and everything looked fine. Checked the exports(5) man page:

$ man 5 exports

and realized the “*” is meaningless in that context. Changed /etc/exports to use the /24 address for my network:

/home   192.168.13.0/24(fsid=0,root_squash,sync,no_subtree_check)

and re-exported:

$ sudo exportfs -ra
Technology

IMAP IDLE

Setting up my iPhone and various other clients to access my email via IMAP (Internet Message Access Protocol) I’d been reading about how Google finally supported the “IDLE” command and how this made “push” work a lot better. I finally got around to looking up some details. In a nutshell, the client keeps the TCP connection open; sends the “IDLE” command; and eventually the server responds when there’s a message.
From IMAP IDLE: The best approach for ‘push’ email:

How IDLE Works
IMAP works by the software on the mobile device (the client) issuing commands to the server. An IMAP server provides two things in response to a client command:

  1. An answer to the request.
  2. Information on any new messages.

This means that where a client is actively doing things with an IMAP server, it will > be told immediately about new messages. The client can then get summary information on the message to present to the user, and can (automatically) download the message when appropriate.
This means that an active client will always be kept up to date. The IDLE command deals with the situation where the client has no more requests to make. The server responds to the idle command when there is a new message (or messages) which indicates to the client that there are new messages.

Technology

Qt 4.5 released

License

Qt is now released under the Lesser General Public License meaning it can be freely linked into commercial applications.

New

Read What’s New or a more detailed description to see what’s changed since Qt 4.4 (released in May, 2008).

  • If you haven’t upgraded to Qt4, here’s what changed since Qt 3.3.4 in June, 2005.

  • Latest WebKit (aka the html display used by Apple’s Safari browser) including support for Netscape plug in so, for example, Flash can be embedded. Includes HTML 5 and CSS animation.

  • XSLT support (XML translation)

  • QtCreator is a Visual Studio like editor that works cross platform and incorporates debuging support and Qt Designer (a layout editor).

  • Mac OS X Cocoa support (latest Mac graphics library). Enables 64-bit support.

Performance

Read either Improved Performance or a white paper with more details and it requires registration so they can email it to you.

  • FileDialog is significantly faster (60x in one case)
    9CC977A0-0ED8-4046-8A9B-C1BEC82E7F69.jpg

  • QGraphicsView optimized
    E5BA610E-4C90-40A3-90EB-134156E13E68.jpg

  • Clipping sped up.

  • Added SquirrelFish javascript engine which is much, much faster.

  • Added QtBenchLib to make application performance testing easier.

Noteworthy

A few other noteworthy changes:

Technology

Trivial subset sum problem

I was asked in a telephone interview how to find out if there are two numbers in
a list that sum to a certain value. I did an O(N^2) algorithm, then refined it to an O(n lg n) algorithm. Unfortunately, there’s an O(n) algorithm which I didn’t think of on the phone but came up with after the fact:

def somePair(values, Z):
    """
    Given a list of numbers and value Z, are there any pair of numbers such that X+Y = Z?
    This does this in O(N) time looking at each value, val, and checking if Z-val is
    already in a lookup table.
    """
    lookup = set()         # Store the values
    for val in values:
        diff = Z - val
        if diff in lookup:
            return True
        else:
            lookup.add(val)
    return False
if __name__ == '__main__':
    assert somePair([], 4) == False
    assert somePair([4], 4) == False
    assert somePair([1,2,3,4], 1) == False
    assert somePair([1,2,3,4], 2) == False
    assert somePair([-8, 12], 4)
    assert somePair([1,2,3,4], 3)
    assert somePair([1,2,3,4, 4], 3)
    assert somePair([1,2,3,4], 4)