Monday, March 30, 2015

Set Tomcat encoding to UTF-8

By default, Tomcat uses ISO-8859-1 encoding, but there is a way to completely set tomcat using UTF-8.

-Dfile.encoding=UTF-8
Set JVM default encoding to UTF-8. Charset.defaultCharset() will reflect changes to the file.encoding property.

set JAVA_OPTS=-Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8
or Use a character encoding filter with the default encoding set to UTF-8, for HTTP POST

Set URIEncoding="UTF-8" on your <Connector> in server.xml.
<Connector port="8080" URIEncoding="UTF-8"/> for HTTP GET

For returned response, set
response.setContentType("text/html; charset=UTF-8");
response.setCharacterEncoding("UTF-8");


http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q8
http://stackoverflow.com/questions/138948/how-to-get-utf-8-working-in-java-webapps

Thursday, March 19, 2015

Upgrade to TurboTax Premier

This year I installed TurboTax Deluxe, but realized it didn't support Stock/ESPP investment during my filing. I had to get a new Premier copy. However, new download Premier copy always show TurboTax Deluxe after open the premier application.

After search and talking to intuit technical support, found TurboTax cached files impacted different versions. It is an obvious bug which Intuit doesn't cover, and it also implies they use configuration or temp files to differentiate Deluxe or Premier edition. If they implement in this way, we might be able to get a free upgrade from Deluxe to Premier or even Business and Home edition. :-)

I did the following which resolved the issue
1. Delete previous installed Deluxe application
2. Delete ~/Library/Application Support/TurboTax 2014 folder
3. Delete ~/Library/Caches/TurboTax 2014 folder
4. Reboot my macbook
5. Reinstall the premier application

Above also implies Mac OSX un-installation actually includes application itself and system caches.

Wednesday, March 18, 2015

Shell script error: bad interpreter: No such file or directory

It is highly likely that you created this file with a windows editor, which will place a <cr><lf> at the end of each line. This is the standard under dos / windows. However, under Unix / linux, the standard is to just put a <lf> at the end of the line.

Linux is now looking for a file called /bin/bash<cr> to interpret the file, where <cr> is a carriage return character, which is a valid file character under linux. Such a file doesn't exist. Hence the error.

http://stackoverflow.com/questions/2841593/bash-script-bad-interpreter

Sublime Text 2 -> View -> Line Endings -> Unix

Trip parking tips

1. Big Sur - Calla Lily
加州1号公路Big Sur附近有个州立公园 - Garrapata State Park。那里的一条通海的沟中长有很多野生马蹄莲 (Calla Lily),那个沟不在公园内,所以免费。

Address:26374 Cabrillo Hwy‎, Carmel-by-the-Sea, CA 93923
GPS:36.423139,-121.912419
Garmin GPS找不到上面的地址,只好用google map 定位GPS

Parking: 停在一号公路靠海的一边(免费)

2. California Academy of Sciences
加州科学馆在金门公园内,里面有好几个主题,包括天文馆,水族馆,热带雨林,还有新建的地震体验区。 旧金山居民每个月好像有免费入馆,非旧金山居民每个季度有一天免费入馆。

Address: 55 Music Concourse Dr., Golden Gate Park, San Francisco, CA 94118

Parking: 周末人很多,但路边多转转可以找到免费停车位,而且没有平时最多4小时的限制。不是特别event的情况下没有必要付费停车库。

3. Natural Bridges State Beach
Santa Cruz这个beach是我们最常去的海滩了,因为很近,而且环境不错。每年11月份后面的蝴蝶谷会有蝴蝶。以前有3个桥在海里,目前就一个了,远看有点桂林山水的那个大象图。

Address: 2531 W Cliff Dr, Santa Cruz, CA 95060

Parking: 进入Beach需要收费,不过里面有BBQ和picnic的地方。不进入门的靠beach的那条路的自行车道上可以免费停车,人多走些路还是可以找到不少路边车位。

4. Happy Hollow Park & Zoo
比较适合小小孩,从名字看有玩的也有动物可以看。

Address: 1300 Senter Rd, San Jose, CA 95112

Parking: 在downtown找免费停车位比较困难,不过旁边的日本花园那边的停车场每天$6, 比他们那边的$10便宜不少。日本花园对面的路边有些停车位,不过周末很难停到。回头找找google earth看看附近有没有其他街道可以停。

5. Yosemite National Park
Parking: 进入公园$30, 有效期一个礼拜。Valley里面主要有2个停车场,一个是在Curry Village那边,一个是在Visitor Center那边,然后可以坐valley的shuttle去不同景点,包括Yosemite fall, Sentinel Bridge 等。不是旺季的话,可以自己开车,每个景点有一些路边停车点。

6. Golden Gate Bridge
South bound 是在101没有上桥的地方拐进去,里面有一个很小的停车场,每小时$1,限2小时,但很难找到停车位,运气好的话等几分钟可以等到。免费的估计要停远点,然后hike到桥上。

7. Lombard Street (九曲花街)
把GPS设置到 1070 Lombard Street, San Francisco, CA94109
附近有免费2小时街边停车

8. Pier 39
附近停车都比较贵,但www.pier39.com上可以申请Fun Pack, 里面一般会有免费2小时的停车coupon,但要在39号码头的对面多层停车场停车。 还有一种就是停远点,1mile左右的street parking, 然后走过去。

9. Palace of Fine Arts
那边是免费停车的。前后都有,位置比较充足。

10. Napa valley
Napa的酒庄都是免费停车的,今年Memorial Day (2015)去的3个值得推荐
4089 Silverado Trail
4240 Silverado Trail
1240 Duhig Rd

Upgrade to facebook v2.0 Javascript SDK

Facebook asks every app developer to upgrade to v2.0+ version before April 30, 2015.

Fortunately Facebook has well written document to explain the upgrade and new SDK

https://developers.facebook.com/docs/apps/upgrading
https://developers.facebook.com/docs/javascript/quickstart/v2.2

One main change is about Login API which needs review process if ask for non-default permissions. And the whole upgrade change limits to:
1. Point to new sdk endpoint which supports locale and versioning
https://connect.facebook.net/en_US/sdk.js
2. When init SDK, pass in version, for example
                       FB.init({
                            appId: app.config.global.fb_app_id,
                            status: true,
                            cookie: true,
                            // Disabling XFBML Parsing if we don't use social plugins (but we use feed dialog)
                            xfbml: true,
                            // frictionlessRequests: true,
                            version: 'v2.2'
                        });

We also use feed dialog, but Facebook suggests to change to new Share Dialog, will consider the migration in future release.
https://developers.facebook.com/docs/sharing/reference/feed-dialog/v2.2

Monday, March 9, 2015

WebStorage fallback

http://caniuse.com/#search=webstorage shows WebStorage is well supported across browsers, but modern browsers support private browsing mode and the implementation is quite different with regarding to WebStorage support. For example, Chrome is doing a very smart logic - support localStorage and sessionStorage, but stores the data in a temp folder. On the other hand, Safari is doing a dumb logic - disable storage APIs in private browsing mode.

Nowadays Web developers don't need to worry about IE6 any more, but need to think of private browsing experience. As to writing, most browsers have private browsing mode though their names are slightly different.

IE: InPrivate browsing
Firefox: New Private window
Safari: New Private window
Chrome: Incognito window

To better support private browsing mode, we need fallback (just like we did for old browsers or new ES6 features). Googled for some time and found cookie is one possible solution to fallback Storage APIs.

https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills
https://gist.github.com/remy/350433
http://stackoverflow.com/questions/4692245/html5-local-storage-fallback-solutions
https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage

It works in some cases, but cookie has issues:
1. cookie value has size limit
2. cookie is shared across tab/windows
3. cookie has http overhead
4. cookie has security issues
5. cookie value is string instead of JSON

Monday, March 2, 2015

Mac OSX mouse click no response in login screen

Suddenly My macbook air doesn't respond to mouse click on login screen though mouse move works. I didn't meet this issue before, so did some google and found this nice blog.
http://www.justanswer.com/mac-computers/2w49b-mac-frozen-login-screen-mouse-cursor-works-no-response.html

It provides 3 methods, and I tried all of three, but only worked once. Next time, I open Macbook Air, it stops working again. I have to hit shutdown and restart again using command line, and fortunately I saw a bluetooth device connected (something like Apple magic trackpad). After see that image, I realized that the external Magic trackpad took over the mouse click events from built-in trackpad. I went to garage and found the magic trackpad, then use it to login OSX and disconnected the bluetooth trackpad through System -> Preference -> TrackPad.

Reset PRAM and NVRAM
    Shut down your iMac
    Locate thfollowing keys on the keyboard: Command, Option, P, and R.
    Turn on the computer.
    Press and hold the Command-Option-P-R keys. You must press this key combination before the gray screen appears and before the chime sound.
    Hold the keys down until the computer restarts and you hear the startup sound for three times.
    Release the keys.

Restart in SafeMode
Make sure that the computer is shut down. Press the power button. Immediately after you hear the startup tone, press and hold the Shift key. Release the Shift key when you see the gray Apple and progress indicator. Let the Mac bootup...

Run Disk Utility in Single User Mode :
Turn it off. Turn it back on and this time hold down the Command (Apple) key and the S keys at the same time. Then type the following command...

/sbin/fsck -fy (note the space between fsck and -fy)

If you can't run /sbin/fsk - fy then type only fsk - fy
Hit return and the disk utility should run and let it finish. When it finishes and there is no error, then type reboot and hit return. Let the Mac boot up and see if it is still giving you problems.

Read more: http://www.justanswer.com/mac-computers/2w49b-mac-frozen-login-screen-mouse-cursor-works-no-response.html#ixzz3TGuGYDJO