All posts by Jack Kozik

Cable Car Turntable

Nob Hill Walk Cable Car Loop — San Francisco

Background on my Nob Hill Walk:  I was in San Francisco on business.  My hotel and meetings were on Nob Hill.  On my first day of meetings, I did an early morning walk and a late evening Cable Car excursion, looping the city.  A beautiful day.

Nob Hill Walk – Down California, Cable Car Back

California StreetNewhall Building

I was in San Francisco for business meetings. Early in the morning on the second day of my visit I decided to go for a walk from my hotel on Nob Hill heading East down California Street.  My walk ended at Market Street; from there, I caught the California Line Cable Car to take me back.

For this nice little walk, I walked past buildings mostly in the Financial District:  Transamerica Pyramid, 650 California Street / Hartford Building, Old St. Mary’s Church, Omni San Francisco Hotel, Alvinza Hayward Building, Union Bank / Bank of California, and the terraced gardens of the 101 California Building.

The cable car terminus at California and Market/Drumm Streets was all torn up.  At first, I thought I couldn’t board here because of the construction, but after awhile several people started queuing up so I knew this was still a good pick up point. The workers there were making sure that people were queuing for the cable car in a safe spot.

Heading back, I saw the Sing Fat Building, Mark Hopkins Hotel, Ritz-Carlton, Fairmont Hotel, and the Pacific-Union Club — Nob Hill is a nice place to visit!

Cable Car Ride: Union Square on Powell/Mason line to Embarcadero Streetcar South to California Line back to Nob Hill

Bay Bridge

After a full day of meetings and dinner, I took a for-fun ride on the cable cars.

I started at Union Square, hopping on the Powell/Mason Cable car on Market Street heading North all the way up to Fisherman’s Wharf.  I briefly walked around and then caught the Embarcadero Streetcar and road South along the F-Market & Wharves line to the Ferry Building at Market Street.

I walked around the area, took some pictures of the Bay Bridge, had dinner nearby then walked over to the California line cable car terminus.  I rode up Nob Hill, back to my hotel.

This is a fun loop; this is something I have always wanted to do.  The only really new segment for me was the Streetcar.  I rode in one of the decades old vintage street cars.  It was perfectly restored and had a very comfortable ride.  I shared it with about 15 other people.  I have seen the street cars before; they look really cool, but they aren’t the same as the cable car… much more like a bus.

On the loop, I took pictures of some noteworthy sites:  “Hearts in San Francisco” and Dewey Monument in Union Square Park, Westin St Francis, Sam’s Cable Car Lounge, Blue Mermaid bar in Fisherman’s Wharf, Ferry Building Clock Tower, San Francisco–Oakland Bay Bridge, Gandhi Statue in the Golden Gate Ferry Terminal, Southern Pacific Building, Vaillancourt Fountain, and the The Pacific-Union Club, Grace Cathedral and the Mark Hopkins hotel on Nob Hill.

I bought a one day pass for the cable cars.  It came in handy for this trip, which otherwise would have cost 3 separate fares.  I did this at night, a little bit late.  This was mostly ok, because during the day it is alot more crowded.
Cable Car Loop: Union Square taking Powell/Mason line to Embarcadero Streetcar to California Line to Nob Hill at EveryTrail

EveryTrail – Find the best Walking Tours in San Francisco, California

jqueryWriteLessDoMore120213

$.ajax logging using Ajax Global Events. Re-factoring Single Page Web Application

Background on $.ajax logging using Ajax Global Events:  So I’ve moved from jQuery 1.4 to 1.9. I have some time to refactor my code to take advantage of some of the new features of 1.9 and to get ready for 1.10; the next jQuery release removes some of the deprecated methods.

For this round of coding, I am focusing on the $.ajax() method. In my present design, my single page web application makes REST calls for many of the UI menu items. For example, a click on the FILE->LOAD menu item triggers a function call to code that retrieves a file from my server. The basic pattern is like this:

// Start spinner
// start logging timer
$.ajax({"url":RestURI,
 "type":"GET",
 "dataType":"json",
 success: function(data) {
 // Do success stuff (parse, format and display)
 // stop logging timer, do logging
 // stop spinnger
 }, /* end success: */

 error: function (req, stat, err) {
 // Do error stuff
 // stop logging timer, do logging
 // stop spinner
 } /* end error: */
});

I have more than 7 code blocks that follow this pattern. Since the success/error/complete callback functions have been deprecated and I need to touch the code anyways, I thought I’d use the newish $.ajax() global events handlers  to clean up my code. The event handlers seem to be a useful place to put common pieces of code that really shouldn’t have been so liberally cut-and-pasted when I wrote the original code.

jQueryIcon120213For each of my ajax code blocks, I put a generous amount of logging in. Maybe this logging should only be needed when writing/debugging the code, but for me, since I spend so little dedicated time on this application, I wanted to keep verbose logging on always to make it real easy for me to debug.

$.ajax logging using Ajax Global Events

The following new block of code is doing my $.ajax logging using Ajax Global Events.

$(document).ajaxSend(function(evt, xhr, settings) {
 console.log(settings.type+" "+settings.url+" Sent");
 start = new Date().getTime();
 // Other logging
});
$(document).ajaxSuccess(function(evt, xhr, settings) {
 console.log(settings.type+" "+settings.url+" Success");
 // Other logging
});
$(document).ajaxError(function(evt, xhr, settings, exc) {
 console.log( settings.type+" "+settings.url+" Failed. "
 +xhr.status+"-"+xhr.statusText);
 // Other logging
});
$(document).ajaxComplete(function(evt, xhr, settings) {
 console.log(settings.type+" "+settings.url+" Complete");
 end = new Date().getTime();
 diff = end - start;
 // Other logging
});

As you can see, the ajaxSend/ajaxSuccess/ajaxError/ajaxComplete events are fired in sequence at the $.ajax() function executes and after the  .done(), .fail() and .compete() callbacks are executed.

The “Other logging” comment represents 2 or 3 lines of code where I put logging information into a user visible menu item (REPORTS->LOG) where I can see even more details without having to open the console window. For me, this effort is a nice clean out some of the logging stuff, to make the application logic a little more visible;  this clears up a bunch of clutter for me.

New-ish .done/.fail/.always Callbacks

Therefore, my $.ajax() code blocks are straighten out to follow the new done/fail/always callbacks. Here’s an example new $.ajax() code block:

// Start spinner
$.ajax({url:RestURI,
 type:"GET",
 dataType:"json"})
 .done( function(data, textStatus, jqXHR) {
 // Do success stuff
 }) /* end done: */

 .fail( function (jqXHR, textStatus, err) {
 // Do error stuff
 }) /* end fail */

 .always( function() {
 // stop spinner
 }); /* End always */

Some things to note: I still put the start/stop spinner function calls inline. I may move this to the global even handlers, but not yet.

Deferred Objects

Also, the done/fail/always call backs follow the new Deferred Object model. This will then let me setup some promise objects to let me address some of the async race conditions I have in my application.

For example, I have a case where I can run FILE->SAVE and then run REPORT->General and the report will produce results before the save was completed. I know how to fix this, but I was looking to use my new ajax code blocks architecture to get some practice with promise objects instead… for next time.

Code Snippets Causing Slow Website Load Time

Background on my Slow Website Load Time issue: I wrote a blog entry that described how I upgraded one of my web pages to use normalize.css (part of my migration to HTML5 Boilerplate 4.2). Normalize.css let me clean up my CSS nicely and helped teach me some discipline on CSS design. All good, but…

The blog posting took a crazy long time to load. I am used to WordPress blog pages being a little heavy and but this was too slow.

I had recently learned about the WebPageTest.org tool, and decided to use it to troubleshoot my issue. Other bloggers point to this website for workingSlow Website Load Time issuess. Here’s what the tool’s waterfall summary page  showed me:

Webpagetest17secBefore110713

 

The chart had lots of red lines: these are lines that reflect 404 error timeouts. I was surprised; the posting didn’t have any links to external content (that I knew of!). I clicked on the waterfall thumbnail and saw the following:
Webpagetest404err110713

 

The 404s are from style.css, normalize.css, main.css, and jquery-ui — huh? These are links in my code snippet!

My blog postings showed the before/after of my <head> section of my normalized web page. Here’s the after snippet:

HeadSection110713

 

 

So do web browsers resolve and fetch URLs embedded in <pre> sections? Really? (sorry to be ignorant about this, but I really didn’t think so). Yes a quick search of stackoverflow and I find that this questions has been asked and answered. When you have a <pre> block, you need to escape the < and > characters (&lt; and &gt;). Stackoverflow reference

So, I manually edited my code snippets to escape the angle brackets, and everything loaded much more quickly. The browser no longer tried to resolve the URLs.

Here’s the new WebPageTest.org thumbnail (no red lines!)
Webpagetest10secAfter110713

Oh, and while I was learning the WebPageTest.org tool, I found a bunch of other problems, which were much more obvious and easy to fix.

72-hourChinaorgcn102813

Experiences entering Beijing on the 72-hour Visa-Free Transit

My trip to China was a challenge. I had to schedule my trip to follow the new 72-hour Visa-Free Transit  process; I didn’t have time to go through the normal visa process. I am pleased to report that my visit to Beijing worked out well, but it was more complicated than I thought it would be. I share my notes here for my records and perhaps the benefit of others.

My host gave me 3 weeks to plan my travel, but I was already scheduled for two other overseas trips so I couldn’t put my passport through the normal (or even expedited) visa process. So my host suggested that I travel on the 72-hour Visa-Free Transit visit  process. I had never heard of this and was skeptical (if not a little reluctant).

The 72-hour Visa-Free Transit rules say that you need a travel itinerary where your departure time is less than 72 hours after the time your inbound flight is scheduled to land. AND, you need to be heading to a different country from which you came. I booked a flight from Chicago to Beijing that landed Monday afternoon. Then I booked a return flight to Tokyo to leave Thursday morning. My Tokyo flight had a 3 hour layover for me to connect with a flight back to Chicago.

BTW, there’s lots more rules: you cannot leave Beijing, you have to be from one of the approved countries, and more. Please don’t go by what I say here, go research this yourself.

This worked. But I had to go through several document checks, with each step adding some doubt and uncertainty.

Ticket counter.

When I started the trip, my airline required me to show my China visa at the ticket counter before they would give me a boarding pass. Not surprisingly, everyone in line ahead of me had a visa. When I got to the head of the line, the poor agent had no idea what I was trying to do. He said “… you have to have a visa to get a boarding pass.” So I pulled out a print-out of an FAQ from the Chinese Embassy that explained the 72-hour Visa-Free Transit  policy; I pulled out a TripAdvisor.com posting, and I pulled out a print-out of a travel blogger’s experiences (including photos). I showed all of this to the agent and only a brief 5 minutes later he gave me a boarding pass.

At the departure gate.

I thought that once I got a boarding pass, I was set. But no. At the boarding gate there’s a roped-off line with a sign saying secondary document checks. I was the first in line. I gave them my visa-less passport, my itinerary, and print-outs from several web pages. The first agent I saw, she didn’t know what to do; she took all my papers then said she was calling her supervisor. Well he came, and didn’t know what to do; they both consulted with someone else. They asked me to sit down; they’d get back to me. Well finally a ticket agenda who knew how to read Chinese came to the gate and she knew what to do right away. They stamped my boarding pass and let me on. This was more drama than I wanted, but understandable.

Chinese immigration hall.

72-hoursebeijinggovcn102813After my long 13 hour flight, with some anxiety I got off my plane at Terminal 3 at the Beijing airport. After a short walk I get to the immigration area. Much to my delight there were two lines dedicated to 72-hour Visa-Free Transit visitors. I went to one of the lines and it was closed?! I politely asked and an immigration agent pointed and said “Foreigner.” This meant I should get into one of the 6 or so lines with a big title of foreigner over the agent’s station.

I got into one of the lines. It was long but it moved fast. Clearly everyone in front of me had a visa. Gulp, was my immigration agent going to know what to do? I gave him my passport, my itinerary, and I said “72-hour Visa-Free Transit .” He apparently knew what I was talking about. He called over one of his associates and they directed me to a separate desk where my travel itinerary was checked. The agent took out a special, big-ish stamp, stamped my passport, and let me pass. Overall, very smooth. Yeah!!

Once I got passed immigration, there was a big back-lit poster celebrating the 72 hour transit visa — implying a welcome for all of us visitors entering under the new process. Thanks, I am glad to be here, so it was OK.

72-hourBCIA102813

Return Trip

I landed in Beijing on a Monday afternoon; I left on a Thursday AM flight. Exiting China at the Beijing airport was very smooth. My passport and boarding pass were briefly checked, stamped and then I went through security, very much, like normal.

I was surprised by the reaction of my host. I got some adventure-traveler bonus points from the him and other members of the local team because I was willing to try the new process, but in retrospect it wasn’t that hard and hopefully my story can help others.

72-hourchinatraveldepot102813

Summary

In summary, make sure you have a printed copy of your travel itinerary, and make sure your departure is to a different country from where you came, and make sure your departure time is less than 72-hours from your landing time, and read the FAQs for all the details of the rules.

References