tungwaiyip.info

 

home

about me

links

my software

Media

Yucatán Photos

St Lucia Photos

Photo Album

Videos

Blog

< June 2005 >
SuMoTuWeThFrSa
    1 2 3 4
5 6 7 8 91011
12131415161718
19202122232425
2627282930  

past articles »

Click for San Francisco, California Forecast

San Francisco, USA

 

Google map scale

It always frustrate me to find maps don't come with scale. It is particular important if you try to judge whether a route is within walking distance. Google map is an incredible tool. But it needs to show the scale too!

So I have decided to make my measurements and come up with some reasonable estimate. I will use the zoom control as the scale. Up to 9 zoom levels were measured with level 1 being the most detail. The distance between the center of + mark and the - mark, is shown below. Beware that the projected images near the poles (e.g. Helsinki,Finland) seems significantly distorted.

LevelDistance
1230m
2450m
3870m
41.7km
53.3km
66.4km
712km
824km
947km

2005.06.24 [] - comments (4)

 

Python's half open index notation

Beginner programmers often wonder about Python's sequence indexing and slicing notation. Array index starts from 0. Slicing uses half open notations, where L[a:b] is a subsequence with index x where a <= x < b.

Why is the endpoint excluded? Isn't it more intuitive if array index starts from 1 and the endpoint is included, so that a 3 elements array is referenced as L[1:3] with items L[1], L[2], L[3]?

It turns out this notation is an elegant and deliberate design and it has some excellent properties.

We write programs to operate on arrays, to find their length, traverse the subsequences, split them or join them. The half open notation always show a simple pattern. But the inclusive notation often requires adding 1 or substracting 1 to the indexes in many operations. Thus it is more vulnerable to off-by-one-error. This article One True Way of array indexing discuss this at length. I have reproduce its example (with corrections) below:

Operation Half open Inclusive
length of a slice L[a:b] b-a (b-a+1)
first n characters of L L[:n] L[1:n]
last n characters of L L[-n:] L[len(L)-n+1:]
The identity slice L == L[0:len(L)] == L[:] L[1:len(L)]
The empty slice L[a:a] is empty for any a. perhaps L[a:a-1]?
A slice of length n, from point a L[a:a+n] L[a:a+n-1]
Split L[a:b] at index c L[a:b] == L[a:c]+L[c:b] L[a:c-1]+L[c:b]

Another important property is an empty sequence can be expressed by L[a:a], while there is no natural way to express an empty sequence with the inclusive notation. But do we really need to care about a special case? Absolutely! In fact failure to account for empty input is one of the most common error. Just like zero is a fundamental concept in mathematics, always think how you program can handle null input. An inferior approach is to represent empty sequence by None or null pointer. This creates a special case so that a variable need to be tested before dereferencing. Failure to do so contributes to unexpected exceptions. It is an elegant design that L[a:b] can also represent sequences with 0 length.

C++'s STL also choose this notation to represent a range. According to the literature this is crucial because "algorithms that operate on n things frequently require n+1 positions. Linear search, for example (find) must be able to return some value to indicate that the search was unsuccessful." I have seen so many people flunked link list or data structure exercises because they have trouble dealing with the end of a list. Often a good solution is shift the focus beyond the n concrete objects to the n+1 positions around them. I hope this help to make sense of the half open notation.

2005.06.16 [, ] - comments (0)

 

Mac goes Intel

This is my observation on Jobs' speech in the WWDC 05 Keynote.


Thanks Daniel for your coverage on the keynote. Reading this is as if I were there.

Jobs has made a very diplomatic presentation. Going Intel is so touchy that they have to introduce this with great care and sensitivity. The humor and cheerleading that is routine in this kind of event are markedly subdue. In place of it are lot more solemn and contemplative atmosphere. Making light joke on the bunny man on fire commercial and have the two CEOs embrace in front of the audience is a ritual for the past foes to make up. I think the ability to change without getting too entrenched or too religious is especially important for Apple to survive and to thrive.

Perhaps this can be a lesson for political adversaries too?

2005.06.15 [] - comments (0)

 

past articles »

 

BBC News

 

EU 'nearing' Greece bail-out deal (13 Mar 2010)

 

Suicide bomb hits Pakistan's Swat (13 Mar 2010)

 

Moon move dismays Apollo men (13 Mar 2010)

 

Three freed in Irish 'Vilks plot' (13 Mar 2010)

 

Alaska wolves 'killed' US teacher (13 Mar 2010)

 

Clinton rebuke over Israel homes (12 Mar 2010)

 

Ivory and tuna top wildlife talks (13 Mar 2010)

 

Sarkozy and Brown attack US deal (13 Mar 2010)

 

Obese drinkers face 'double whammy' (13 Mar 2010)

 

Cell for cell: Georgian prisoners can swap jail time for monastery (13 Mar 2010)

more »

 

Slashdot News for nerds, stuff that matters

 

Digg Says Yes To NoSQL Cassandra DB, Bye To MySQL (2010-03-13T02:47:00+00:00)

 

Hunting Disease Origins By Whole-Genome Sequencing (2010-03-13T00:04:00+00:00)

 

Nearby Star Forecast To Skirt Solar System (2010-03-12T23:36:00+00:00)

 

Texas Approves Conservative Curriculum (2010-03-12T23:17:00+00:00)

 

Court Rules Against Vaccine-Autism Claims Again (2010-03-12T22:36:00+00:00)

 

Scientists Need Volunteers To Look At the Sun (2010-03-12T21:55:00+00:00)

 

Here Come the Linux iPad Clones (2010-03-12T21:13:00+00:00)

 

DR Congo Ring May Be Giant Impact Crater (2010-03-12T20:48:00+00:00)

more »

 

TechPsychic Tech Rumors and Invented News

 

TechPsychic: Apple Unveils The UC Berkeley or Twitter looks like FriendFeed. (13 Mar 2010)

 

TechPsychic: It's fairly simple Way To social network information in Clearwire and Firefox Add-On according to. (12 Mar 2010)

 

TechPsychic: Make money changed hand, Google Nexus One event. (12 Mar 2010)

 

TechPsychic: Microsoft Bing's Twitter. (12 Mar 2010)

 

TechPsychic: Apple's iPad Comes to say about Google Chrome Release. (12 Mar 2010)

 

TechPsychic: Opera Mini Stats Tell Google Chrome Release Adds Support high-definition video. (12 Mar 2010)

 

TechPsychic: MySpace recently launched Android On Twitter 1 Million Downloads A job applicant are alive, Facebook? (11 Mar 2010)

 

TechPsychic: Android Apps. (11 Mar 2010)

more »

 

SF Gate

 

Photos may show more victims of serial killer (2010-03-12T13:41:35UTC)

 

2 convicted in San Jose baseball bat killing (2010-03-12T21:00:40UTC)

 

Suspect's family sues police over his death (2010-03-12T17:58:41UTC)

 

Oakland skills center given stimulus boost (2010-03-12T13:09:12UTC)

 

Special session ends, state deficit unresolved (2010-03-12T08:00:19UTC)

 

Oakland's Kaplan could be long-term force (2010-03-12T13:17:51UTC)

 

Experts say even Obama getting too many med tests (2010-03-12T21:30:57UTC)

 

State transit projects may be U.S. models (2010-03-12T08:07:31UTC)

 

Roethlisberger's lawyer hires private investigator (2010-03-12T22:55:51UTC)

 

Business Highlights (2010-03-12T22:55:50UTC)

 

Presented By: (12 Mar 2010)

 

Quinn wants to borrow nearly billion _ but how? (2010-03-12T22:53:50UTC)

 

Tri-Continental declares 1Q dividend (2010-03-12T22:48:49UTC)

 

Rates trade in tight range on uneven economic data (2010-03-12T22:47:48UTC)

more »

 

Asia Times Online

 

AN ATOL SPECIAL REPORT : Iran's spies show how it's done (Fri 12 Mar 2010 19:00:00 +0700)

 

The demise of a 'good-for-nothing bandit' (Fri 12 Mar 2010 19:00:00 +0700)

 

A titanic power struggle in Kabul\ (Fri 12 Mar 2010 19:00:00 +0700)

 

Israel puts US on notice (Fri 12 Mar 2010 19:00:00 +0700)

 

When the Mekong runs dry (Fri 12 Mar 2010 19:00:00 +0700)

 

US, China struggle with mid-life crisis (Fri 12 Mar 2010 19:00:00 +0700)

 

South Korea reluctant to take command (Fri 12 Mar 2010 19:00:00 +0700)

 

BOOK REVIEW : Healing invisible wounds (Fri 12 Mar 2010 19:00:00 +0700)

 

Medvedev plays down power role (Fri 12 Mar 2010 19:00:00 +0700)

 

MARKET RAP : Buyers beware (Fri 12 Mar 2010 19:00:00 +0700)

 

IT WORLD : Browser beaten (Fri 12 Mar 2010 19:00:00 +0700)

 

THE MOGAMBO GURU : A debtor's dream (Fri 12 Mar 2010 19:00:00 +0700)

more »

 


Site feed Updated: 2010-Mar-12 21:15