boat+hill

·舟山詩詞·淘海洗玉集 – My Poems, and etc.

Spring 2016

leave a comment »


五律·寄思

湖山風帶暖,
春月雨融冰。
薄霧丹青意,
愁雲水墨盈。
家園方入夢,
景物可傳情。
獨立櫻花岸,
遊思寄遠亭。
雙城分隔夜,
一詩念安平。
筆落惜惜句,
書成戀戀行。
雖乏盟海誓,
未忍諾言輕:
天地無憂果,
人間不老齡。
  
二零一六年三月六日
於紗糸軒

Written by Boathill

2016-03-06 at 15:35

Posted in 诗作, Photograghy, Poem

Tagged with , , ,

BC Trip 2016

leave a comment »

Written by Boathill

2016-01-17 at 20:40

Zhou Enlai

leave a comment »


沁園春 · 再懷周公,和毛詞原韻,並序《重訂丙辰清明詩鈔

  
久逝容光,
歲月塵封,思念遠飄。
記當年國喪,陰雲翳翳;
 人民心碎,淚雨滔滔。
萬業親躬,先憂後己,
誰比周公品質高?
一生夢,為中華崛起,
富裕妖嬈。
  
山河自古多嬌,
是烈士拋顱與折腰。
想伍毫學社,初揚文采;
 南昌黃埔,盡顯風騷。
外交和談,蜚聲宇內,
政治功夫巧射雕。
多少代,留傳奇故事,
遺唱今朝。

二零一一年一月八日於紗糸軒

Written by Boathill

2016-01-07 at 18:00

Punta Cana

leave a comment »

Written by Boathill

2016-01-01 at 22:00

Seattle 2015

leave a comment »

Written by Boathill

2015-12-25 at 20:00

Javascript: Sync JSON Data

leave a comment »


/**
 * Synchronize new data to original object and keep reference
 * Check object data type and traverse object tree to delete old key
 * as well as replace with new data:
 *
 * - if keyed data is directory (hash map) 'object', sync recursively
 * - else (including number, string, and array, etc), replace with new data
 *
 * @returns void.
 */
function syncObjectData(newData, orgData) {
  if (newData != null && orgData !== newData) {
    var sourceType = orgData.toType();
    var targetType = newData.toType();

    if (sourceType != targetType) {
      // the top level type must match

      var message = "Cannot update '" + sourceType + "' with different type " + targetType;
      throw new Error(message);
    } else if (sourceType != 'object') {
      // can only sync object type

      throw new Error("Does not support updating type of " + orgType);
    } else {
      for (var key in newData) {
        if (newData.hasOwnProperty(key)) {
          if (orgData.hasOwnProperty(key) && newData[key] != null) {
            var orgType = toType(orgData[key]);
            var newType = toType(newData[key]);

            if (newType == orgType && orgType == 'object' && orgData[key] != null) {
              syncObjectData(newData[key], orgData[key]);
            } else {
              orgData[key] = newData[key];
            }
          } else if (!orgData.hasOwnProperty(key)) {
            orgData[key] = newData[key];
          } else {
            delete orgData[key];
          }
        }
      }
      for (var key in orgData) {
        if (orgData.hasOwnProperty(key)) {
          if (!newData.hasOwnProperty(key) || newData[key] == null) {
            delete orgData[key];
          }
        }
      }
    }
  }
}

Here is the helper function to get name (string) of the exact type.

/**
 * Convert data type to string, e.g. 'undefined', 
 * or 'null', 'boolean', 'number', 'string', 'array', 'object', 'date', 'function', etc.
 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
 */
function toType(variable) {
  return ({}).toString.call(variable).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
}

Written by Boathill

2015-12-05 at 15:00

Posted in IT, programming, study notes

Tagged with , ,

Arizona 2015

leave a comment »

Written by Boathill

2015-11-22 at 22:00

Posted in Photograghy

Tagged with , , ,

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: