Skip to content

Instantly share code, notes, and snippets.

@thomasjao
thomasjao / 臺灣郵遞區號
Last active January 7, 2019 09:44
各縣市郵遞區號以 JSON 表示
台北市 = {"中正區":"100","大同區":"103","中山區":"104","松山區":"105","大安區":"106","萬華區":"108","信義區":"110","士林區":"111","北投區":"112","內湖區":"114","南港區":"115","文山區":"116"};
新北市 = {"萬里區":"207","金山區":"208","板橋區":"220","汐止區":"221","深坑區":"222","石碇區":"223","瑞芳區":"224","平溪區":"226","雙溪區":"227","貢寮區":"228","新店區":"231","坪林區":"232","烏來區":"233","永和區":"234","中和區":"235","土城區":"236","三峽區":"237","樹林區":"238","鶯歌區":"239","三重區":"241","新莊區":"242","泰山區":"243","林口區":"244","蘆洲區":"247","五股區":"248","八里區":"249","淡水區":"251","三芝區":"252","石門區":"253"};
基隆市 = {"仁愛區":"200","信義區":"201","中正區":"202","中山區":"203","安樂區":"204","暖暖區":"205","七堵區":"206"};
宜蘭縣 = {"宜蘭市":"260","頭城鎮":"261","礁溪鄉":"262","壯圍鄉":"263","員山鄉":"264","羅東鎮":"265","三星鄉":"266","大同鄉":"267","五結鄉":"268","冬山鄉":"269","蘇澳鎮":"270","南澳鄉":"272"}:
新竹市 = {"東區":"300", "北區":"300", "香山區":"300"};
新竹縣 = {"湖口鄉":"303","新豐鄉":"304","新埔鎮":"305","關西鎮":"306","芎林鄉":"307","寶山鄉":"308","竹東鎮":"310","五峰鄉":"311","橫山鄉":"312","尖石鄉":"313","北埔鄉":"314","峨眉鄉":"315"};
桃園市 = {"中壢區":"320","平鎮區":"324","龍潭區":"325","楊梅區":"326","新屋區":"327","觀音
@thomasjao
thomasjao / sort_out_unique_value_in_array
Created June 15, 2015 16:41
To sort out unique values in an array, strip out repetitive items from an array
/* Following function find unique value in a sorted array */
function get_unique_in_array( arr ) {
var ret = [arr[0]];
for (var i=1; i<arr.length; i++) {
if ( ret.indexOf(arr[i]) < 0 ) {
ret.push(arr[i]);
}
}
return ret;
}
@thomasjao
thomasjao / showData()
Last active August 29, 2015 14:23
Generate Table with Head Using JSON as source
function showData( data ) {
var docs = data;
if ( Array.isArray( docs )) {
var tbl = document.createElement('table');
var tr = document.createElement('tr');
/* 表格標題列 */
var titles = Object.keys(data[0]);
var tr = document.createElement('tr');
for (var i in titles) {
@thomasjao
thomasjao / volunteer_system_code
Created June 10, 2015 14:22
志願服務系統代碼表
var zipcode = {"950":"台東市", "951":"綠島鄉", "952":"蘭嶼鄉", "953":"延平鄉", "954":"卑南鄉", "955":"鹿野鄉", "956":"關山鎮", "957":"海端鄉", "958":"池上鄉", "959":"東河鄉", "961":"成功鎮", "962":"長濱鄉", "963":"太麻里鄉", "964":"金峰鄉", "965":"大武鄉", "966":"達仁鄉"};
var education = {"01":"博士", "02":"碩士", "03":"大學", "04":"專科", "05":"高中", "06":"國中", "07":"職校", "08":"小學", "09":"其他"};
var occupation = {"01":"工商", "02":"公教", "03":"退休", "04":"家管", "05":"學生", "06":"服務業", "07":"其他"};
var join_role = {"01":"一般志工", "02":"高中生", "03":"大學生", "04":"其他"};
var service = {"01":"身心障礙者福利服務", "02":"老人福利服務", "03":"婦女福利服務", "04":"少年福利服務", "05":"兒童福利服務", "06":"諮商輔導服務", "07":"醫院社會服務", "08":"家庭福利服務", "09":"社區福利服務", "10":"綜合福利服務", "99":"其他(文化、環保)"};
var specialty = {"01":"家電修理", "02":"機械", "03":"汽車修護", "04":"工藝", "05":"刻印", "06":"印刷", "07":"語文", "08":"文書處理", "09":"編輯", "10":"打字", "11":"美工", "12":"縫紉/編織", "13":"烹飪/烘焙", "14":"美容/美髮", "15":"家事服務", "16":"護理", "17":"手工藝", "18":"電腦", "19":"攝影", "20":"團康", "21":"管理", "22":"會計", "23":"作物栽培", "24":"農牧(藝)", "25":"音樂", "26":
// JavaScript In-Depth
JavaScript 的 function 是 first-class 的意義:
* function 可以被指派到某個變數
* function 可以當作另一個 function 的參數
* function 可以作為另一個 function 的回傳值
* function 具備和 Object 一樣的特質,包括:high order(?), assign 及 property
Higher-order function 的意義:1. function 可以將 1 或多個 function 作為參數 2. 輸出(回傳) function
// 如何呼叫 JS function //
==========================
@thomasjao
thomasjao / gist:2d21a0059c626f920f35
Created January 29, 2015 16:02
Dynamically Add Script Using JavaScript Code
var script = document.createElement('script');
script.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js');
document.getElementsByTagName('head')[0].appendChild( script );
@thomasjao
thomasjao / epoch of Taiwan to AD
Created January 29, 2015 14:36
Convert epoch of Taiwan to AD
/* Epoch used in Taiwan started since 1911 AD. For example, this year (2015 AD) in Taiwan epoch is 中華民國 104 年
Often we need to different epoch notation between system/languages */
/* From String to JavaScript
Taiwan epoch notation -- '104.01.29'
AD -- Thu Jan 29 2015 22:27:19 GMT+0800 (CST) */
var str2JSdate = function( str ) {
var dt = new Date();
var date_arr = str.split('.');
dt.setFullYear( parseInt( date_arr[0] ) + 1911 );
@thomasjao
thomasjao / PHP data type conversion
Created January 27, 2015 06:23
Convert date string into MySQL Date format
$origin = '97.09.27';
$dt = preg_split('/\./', $origin);
$mysqlDate = ((int)$dt[0] + 1911).'-'.$dt[1].'-'.dt[2];
1. preg_split has at least 2 parameters:
1) '/\./' -- regular expression pattern
2) $origin -- the string to be splited
it use regular expression pattern to separate the string into array
2. convert string to number (coersion)
@thomasjao
thomasjao / README.md
Last active August 29, 2015 14:08
漢語拼音

##漢語拼音 漢語拼音的好處:

  • 祇要熟悉英文字母字鍵,不用額外學習音碼或型碼的按鍵位置
  • 以「辭」為單位輸入,大幅減少選字時間
  • 成語、常見辭句可直接輸入個別字元的首碼,大幅減少鍵入時間
  • 不經切換鍵即可直接輸入標點符號
@thomasjao
thomasjao / store date as JSON
Created September 9, 2014 00:03
JSON 的資料型態不包含 date,往往需另行處理日期相關的運算,頗為麻煩。若能將日期儲存為數值,則於運算時可便利很多。
var birthday = '1962/7/25';
function date2JSON( dt ) {
var dayArr = dt.split('/');
return JSON.parse( '{ "year":' + parseInt( dt[0] ) + ', "month:"' + parseInt( dt[1] ) + ', "day":' + parseInt( dt[3] ) + '}');
Usage Example:
var myBirthday = date2JSON( birthday );
==> {"year": 1962, "month": 7, "day": 25}