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
+----------------------------+----------------------+-------------+----------------+----------------+
| | | | | |
| Helper | GET | POST | PUT | DELETE |
| | | | | |
+----------------------------+----------------------+-------------+----------------+----------------+
| | | | | |
| blog_post_path(@post) | /blog/posts/12 | | /blog/posts/12 | /blog/posts/12 |
| | | | | |
+----------------------------+----------------------+-------------+----------------+----------------+
| | | | | |
@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
@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 / app.js
Created October 3, 2013 09:12
Angular controller this vs $scope.
'use strict';
var app = angular.module('app', []);
app.controller('AppCtrl', function ($scope) {
this.foo = 'bar';
$scope.hello = 'world';
});
<test data-test=" 'hello' "></test>
window.app = angular.module('myApp', []);
@chinghanho
chinghanho / gist:5794508
Created June 17, 2013 03:37
In Chrome, tweet with selected text which contained the title and the URL of the page from Tweetbot app.
on run (input)
tell application "Google Chrome"
set theURL to URL of active tab of first window
set theTitle to title of active tab of first window
set theData to theTitle & " " & theURL & " #「" & input & "」" as string
end tell
activate application "Tweetbot"
tell application "System Events" to tell process "Tweetbot"
click menu item "New Tweet" of menu 1 of menu bar item "Tweet" of menu bar 1
@chinghanho
chinghanho / gist:5783349
Created June 14, 2013 16:31
判斷字串是否含有中文
// 英文、數字、符號:[a-z0-9~!@#&;=_\$\%\^\*\-\+\,\.\/(\\)\?\:\'\"\[\]\(\)]
// 中文:\u4e00-\u9fa5
// 日文:\u3040-\u30FF
var string = "中文內容"
string.match(/[\u4e00-\u9fa5]+/)
@chinghanho
chinghanho / dev.rake
Created November 25, 2012 11:45
Rebuild system by rake
namespace :dev do
desc "Rebuild system"
task :build => ["tmp:clear", "log:clear", "db:drop", "db:create", "db:migrate"]
task :rebuild => [ "dev:build", "db:seed" ]
end
@chinghanho
chinghanho / pptpd.sh
Created November 5, 2012 01:15 — forked from alvin2ye/pptpd.sh
Automaticlly install pptpd on Amazon EC2 Amazon Linux
# Automaticlly install pptpd on Amazon EC2 Amazon Linux
#
# Ripped from http://blog.diahosting.com/linux-tutorial/pptpd/
# pptpd source rpm packing by it's authors
#
# WARNING:
# first ms-dns setting to 172.16.0.23, 172.16.0.23 was showing on my
# /etc/resolv.conf, I'm not sure this is the same on all Amazon AWS zones.
#
# You need to adjust your "Security Groups" which you are using too.