Skip to content

Instantly share code, notes, and snippets.

View chinghanho's full-sized avatar
💁‍♂️
What's up?

Ching-Han Ho chinghanho

💁‍♂️
What's up?
View GitHub Profile
@chinghanho
chinghanho / gist:9155542
Created February 22, 2014 14:20
translate camelCase variant to hyphenated style
str.replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
@chinghanho
chinghanho / find-urls.js
Last active August 29, 2015 13:56
尋找中英文夾雜 string 中的 URL
var url = /^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?((?:(?:[-\w\d{1-3}]+\.)+(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2}))|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/i
, chinese = /[\u4e00-\u9fa5]+/
, cText = '中文https://github.com/夾雜網址。'
, eText = 'english https://github.com/ url.'
, mixText = '中 en 文https://github.com/夾雜 google.com網址'
, gResult;
// utilities
+----------------------------+----------------------+-------------+----------------+----------------+
| | | | | |
| Helper | GET | POST | PUT | DELETE |
| | | | | |
+----------------------------+----------------------+-------------+----------------+----------------+
| | | | | |
| blog_post_path(@post) | /blog/posts/12 | | /blog/posts/12 | /blog/posts/12 |
| | | | | |
+----------------------------+----------------------+-------------+----------------+----------------+
| | | | | |
@chinghanho
chinghanho / index.html
Last active August 29, 2015 14:02
CSS 練習
<div class="jumbotron">
<div class="jumbotron-header">
<h1>這是標題</h1>
</div>
<div class="jumbotron-body">
<p>這裡是內文,上面要有一條線</p>
</div>
<div class="jumbotron-footer">
<p>這裡是 footer,上面不能有線</p>
</div>
//
//
//
// .__ __. ______ _______ _______ __ _______.
// | \ | | / __ \ | \ | ____| | | / |
// | \| | | | | | | .--. || |__ | | | (----`
// | . ` | | | | | | | | || __| .--. | | \ \
// oooooooooooo | |\ | | `--' | | '--' || |____ __| `--' | .----) |
// `888' `8 |__| \__| \______/ |_______/ |_______(__)\______/ |_______/
// 888 oooo ooo oo.ooooo. oooo d8b .ooooo. .oooo.o .oooo.o
<?php
$url = 'http://vimeo.com/71673549';
preg_match('/\/\/(www\.)?vimeo.com\/(\d+)($|\/)/', $url, $matches);
?>
<iframe src="http://player.vimeo.com/video/<?php echo $matches[2] ?>?title=0&amp;byline=0&amp;portrait=0&amp;badge=0&amp;color=ffffff" width="640" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
@chinghanho
chinghanho / gist:3346205
Created August 14, 2012 04:18 — forked from lucasfais/gist:1207002
Sublime Text 2: Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T 切換檔案
⌘⌃P 切換專案
⌘R 畫面切換到 method
⌃G 畫面切換到指定行數
⌘KB 關閉 / 開啟側邊欄
⌘⇧P 開啟指令控制面板
@chinghanho
chinghanho / gist:3505158
Created August 28, 2012 23:08 — forked from iCasablanca/gist:1150914
Rails: Convention of Techbang

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
@chinghanho
chinghanho / app.go
Last active October 10, 2015 09:03
Simple benchmark of plain text in Go, Ruby, PHP and Node.js
package main
import (
"fmt"
"log"
"net/http"
)
func rootHandler(w http.ResponseWriter, r *http.Request) {
@chinghanho
chinghanho / devise.zh-TW.yml
Created October 1, 2012 01:11 — forked from littlebtc/devise.zh-TW.yml
Rails: Devise i18n Chinese Traditional Translation
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
zh-TW:
errors:
messages:
expired: "已經過期,請重新申請一個"
not_found: "找不到"
already_confirmed: "已經驗證,請直接登入"
not_locked: "被鎖定了"
not_saved: