Monday, April 2, 2012

Google Map 8-bit Landscapes Gallery

The Google April fool 2012 is Google Map in 8-bit. It is freakin awesome and I have capture some landscapes around the world for you.

Let's have the promotion clip from Google first:

OK! Let's go!

Hong Kong Google office
The Ocean Park in Hong Kong, all parks around the world using Panda as the logo

Taiwan 101 tower

Mountain Fuji in Japan
Monster at Japan
Slime and JR in Tokyo
Osaka Castle
Kyoto Tower
Another castle in Kyoto
Unknown characters at Kyoto

Eiffel tower in Paris
Arch of Triumph, France

Statue of Liberty in US
New York
The white house
Area 51
Mountain View Google headquarter
Monster at US
Golden bridge gate
Space Needle in Seattle
Shanghai Tower, China

Sydney Opera House
Monster at Tasmania, Australia

Petronas Twin Towers,Kuala Lumpur City Centre

The Pyramids
Dragon at the center of the world
Buckingham Palace
Monster at Loch Ness
Monster at Deutschland
Jesus mountain
Roman Coliseum
Sagrada Familia
Leaning Tower of Pisa
London Bridge
If you found more landscape in 8-bit. Please tell me!

Monday, March 26, 2012

Missing 'type' field from Facebook Graph API result

Last Friday I have joined Facebook Mobile Hack event which held at Hong Kong. I have learnt alot and want to build something by Facebook Graph API for fun. The first thing I have to try is retrieving my feed in Facebook. However I found that if I retrieving the information from the Facebook Graph API Explorer it return a 'type' field for the post such as status, link, video, checkin, etc, but the 'type' field is missing if I use Javascript SDK to retreive the post.

After do some googling, I found out the answer and I think it's worth to share. Just add "?metadata=true" at the end of query will work fine.

  <link rel="stylesheet" type="text/css" href="style.css">
  <meta name="viewport" content="initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <script src=""></script>

<div id="fb-root"></div>

(function() {
  var e = document.createElement('script'); e.async = true;
  e.src = document.location.protocol + '//';

window.fbAsyncInit = function() {
  FB.init({ appId: 'YOUR_APP_ID',
  status: true,
  cookie: true,
  xfbml: true,
  oauth: true})

function checking() {
  FB.api('/414866888308?metadata=true', function(response) { // retrieving checkin ID
    // the response.type come out finally

function login() {
  FB.login(function(response) { }, {scope:'user_likes'});


Here is the book you may feel interested:

Monday, March 5, 2012

PHP function that get query from search engine

SEO (Search Engine Optimisation) take an important role for the success of your online business. For someone you may not know what is SEO, here is the definition from wiki.

Search engine optimization (SEO) is the process of improving the visibility of a website or a web page in search engines via the "natural," or un-paid ("organic" or "algorithmic"), search results. In general, the earlier (or higher ranked on the search results page), and more frequently a site appears in the search results list, the more visitors it will receive from the search engine's users. SEO may target different kinds of search, including image search, local search, video search, academic search,news search and industry-specific vertical search engines.
Indeed, you may want to know more how your customers go to your site through search engine. This is a function to track the search query on search engine before a user goes to your site.

function search_engine_query_string($url = false) {

    if(!$url) {
        $url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
    if($url == false) {
        return '';

    $parts = parse_url($url);
    parse_str($parts['query'], $query);

    $search_engines = array(
        'about' => 'terms',
        'alice' => 'qs',
        'alltheweb' => 'q',
        'altavista' => 'q',
        'aol' => 'q',
        'aol.' => 'query',
        'aol..' => 'encquery',
        'answers' => 's',
        'aolsearch' => 'q',
        'ask' => 'q',
        'baidu' => 'wd',
        'bing' => 'q',
        'cnn' => 'query',
        'daum' =>'q',
        'eniro' => 'search_word',
        'ekolay' => 'q',
        'google' => 'q',
        '' => 'as_q', // seen on
        '' => 'q',
        'kvasir' => 'q',
        'live' => 'q',
        'lycos' => 'query',
        'mamma' => 'query',
        'msn' => 'q',
        'mynet' => 'q',
        'naver' => 'query',
        'najdi' => 'q',
        'netscape' => 'query',
        'onet' => 'qt',
        'ozu' => 'q',
        'pchome' => 'q',
        'rambler' => 'words',
        'search' => 'q',
        'sesam' => 'q',
        'seznam' => 'q',
        'sNOWsh' => 'q',
        'szukacz' => 'q',
        'terra' => 'query',
        'voila' => 'rdata',
        'virgilio' => 'qs',
        'wp' => 'szukaj',
        'yahoo' => 'p',
        'yam' => 'k',
        'yandex' => 'text'

    preg_match('/(' . implode('|', array_keys($search_engines)) . ')\./', $parts['host'], $matches);

    return isset($matches[1]) && isset($query[$search_engines[$matches[1]]]) ? $query[$search_engines[$matches[1]]] : '';


Books you may feel interested:

Saturday, January 7, 2012

Mysql fastest distance lookup given latitude/longitude

Recently I have developed an Android application, which is an LBS(location-based services) application. This application is in Chinese, but the name in English is "Hong Kong chain store" (香港連鎖店). I have got a list of branch in my database, and the app can help user to find out all branch nearby.

The question is, how to retrieve the distance between user location and branch location in the most fastest way. I think most of people just store the latitude and longitude of the location in database. And the code loop through the whole database and calculate the distance record by record. But running the code by this method is very time consuming. We need a much more faster way.

I have google around and got the answer in stackoverflow. However, I found that there is some typo in the answer, and it is not a complete answer. So right now I make a summary to tackle this question.

I assumed that you have got the latitude(lat) and longitude(lng) point of your locations in database. But this is not enough, you should open one more field that store a geo point of the location(latlng) and create a spatial index on it. Here is the SQL statement to make this field when you create the table,
Please note that the field [latlng] should be in GEOMETRY type. If you have already create the field, you can use ALERT command to create spatial index.
CREATE SPATIAL INDEX sp_index ON geom (latlng);
Then, run the following SQL to update [latlng] field.
UPDATE geom SET latlng = POINT(lat, lng)
OK, that is all the things for database. Here is the PHP script in your code. Assume that you have to find all locations not more then 0.5km distance.
$orglng = $_GET["user_lng"];
$orglat = $_GET["user_lat"];
$distance = 0.5;

$pt1 = $orglat + $distance / ( 111.1 / cos($orglat));
$pt2 = $orglng + $distance / 111.1;
$pt3 = $orglat - $distance / ( 111.1 / cos($orglat));
$pt4 = $orglng - $distance / 111.1;

$qry = "SELECT  * ";
$qry .= "FROM geom ";
$qry .= "WHERE MBRContains(GeomFromText('LineString(".$pt1." ".$pt2.", ".$pt3." ".$pt4.")'), latlng)";
Here is what you need! Test it yourself now.

Happy coding!

Book you may feel interested:

Friday, January 6, 2012

Facebook Hacker Cup 2012

Facebook Hacker Cup is open for registration now. Frankly speaking, if you love programming, you should try it. I have joined this contest last year. You may mislead by the contest name. Actually it is not related to "hack" anymore. It is just a purely programming competition. Understanding the question, solve the problem with your prefer programming language, download the data set from facebook and submit your result, that is.

Comparing with Google Codejam, I feel the question from facebook is much more easy to understand. But since you have to submit your answer within certain time, you have to optimize the running process of your code. Most likely there is a math formula or philosophy behind. If you didn't notice it, I bet your code cannot return the result in time.

Anyway, get it a try if you love programming.

Related Posts Plugin for WordPress, Blogger...