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

 

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

 

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

 

past articles »

 

Kontagent

Kontagent is hiring software engineers

BBC News

 

West deplores UN Syria vote veto (05 Feb 2012)

 

Mitt Romney wins Nevada caucuses (05 Feb 2012)

 

Transport hit as snow sweeps in (05 Feb 2012)

 

Fidel Castro launches his memoirs (04 Feb 2012)

 

Thousands in rival Moscow marches (04 Feb 2012)

 

Europe 'at risk of early grave' (04 Feb 2012)

 

William starts Falklands duties (04 Feb 2012)

 

ANC youth leader appeal dismissed (04 Feb 2012)

 

Afghan civilian death toll rises (04 Feb 2012)

 

VIDEO: BBC team smuggled into Homs (04 Feb 2012)

more »

 

Slashdot News for nerds, stuff that matters

 

New Hampshire Passes 'Open Source Bill' (2012-02-05T01:25:00+00:00)

 

Text Message Brands Quebec Man a Terror Suspect (2012-02-05T00:21:00+00:00)

 

Apple Overturns Motorola's German iPad and iPhone Sales Bans (2012-02-04T23:10:00+00:00)

 

LibreOffice Developer Community Increasingly Robust (2012-02-04T22:09:00+00:00)

 

Canada's Massive Public Traffic Surveillance System (2012-02-04T21:01:00+00:00)

 

German Government Endorses Chrome As Most Secure Browser (2012-02-04T19:54:00+00:00)

 

Milky Way Magnetic Fields Charted (2012-02-04T18:50:00+00:00)

 

New Book Helps You Start Contributing To Open Source (2012-02-04T17:45:00+00:00)

more »

 

TechPsychic Tech Rumors and Invented News

 

TechPsychic: AT&T: more money, says it's disruptive in funding from. (08 May 2010)

 

TechPsychic: I know that Apple is close to Apple Dominates, Hires ex-Googler - Yes, Android phones. (08 May 2010)

 

TechPsychic: AT&T says: Facebook Connect. (08 May 2010)

 

TechPsychic: Google's Nexus One of Google Chrome Release Adds Support subscriptions accounted for Amazon: Apple. (08 May 2010)

 

TechPsychic: Another stat: Twitter's Design of this is giving rise of BlackBerry Foursquare Map App store end. (07 May 2010)

 

TechPsychic: Like educational sales Up around Apple iPad makes money Plan costs half an Apple. (07 May 2010)

 

TechPsychic: Instead added extensions, social Networks than double, everyone jumps in Silicon Valley? (07 May 2010)

 

TechPsychic: So why iTunes App lets Social Networks Verizon Wireless Internet. (07 May 2010)

more »

 

SF Gate

 

University High's Reynolds inspires NY Giants (2012-02-04T22:16:03PST)

 

New Mid-Market businesses boost foot traffic (2012-02-04T22:16:03PST)

 

GOP candidates shy away from Nevada housing crisis (2012-02-04T22:16:03PST)

 

Nevada GOP caucuses include unusual rules (2012-02-04T22:16:03PST)

 

Rwandan teen to return home with new smile (2012-02-04T22:16:03PST)

 

Presented By: (04 Feb 2012)

 

Protests spur park service to rethink dog policies (2012-02-04T22:16:03PST)

 

10 Super Bowl storylines (2012-02-04T22:16:03PST)

 

Jobs report lifts Dow to highest mark since '08 (2012-02-04T22:02:20PST)

 

Hiring surges in January; jobless rate at 8.3 pct. (2012-02-04T22:02:20PST)

 

Presented By: (03 Feb 2012)

 

US service industry growth surges in January (2012-02-04T22:02:20PST)

 

S.F.'s Metreon ready for its 2nd act (2012-02-04T22:02:20PST)

 

SF Bay Area restaurants rebound along with economy (2012-02-04T22:02:20PST)

more »

 

Asia Times Online

 

AN ASIA TIMES ONLINE EXCLUSIVE : Taliban eat into Afghanistan's core (3 Feb 2012)

 

Rants and raves for new US pullout plan (3 Feb 2012)

 

THE ROVING EYE : Exposed: The Arab agenda in Syria (3 Feb 2012)

 

Question time for North Korea (3 Feb 2012)

 

From sex to shame, a guru's legacy (3 Feb 2012)

 

Hidden hand, clean hand in Russian politics (3 Feb 2012)

 

Nightmare at Narita (3 Feb 2012)

 

BOOK REVIEW : LeT: Terror incorporated (3 Feb 2012)

 

SPEAKING FREELY : Lest we forget in Myanmar (3 Feb 2012)

 

bn shale-gas deal sweetens Beijing trip by Canada's Harper (3 Feb 2012)

 

Factory owners mourn Mazar-e-Sharif clean-up (3 Feb 2012)

 

IT WORLD : Facebook heads for IPO (3 Feb 2012)

more »

 


Site feed Updated: 2012-Feb-05 00:00