- 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
- 函式如果只有一個參數,就不強制打()
- 函式如果有二個以上的參數,通通都要有 ()
- (避免發生奇怪的paser bug跟保持專案一致性)
- 字串限定用雙引號包覆
- 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- connected to AirPods by name | |
function connectToAirPods(name) | |
local current = hs.audiodevice.defaultInputDevice() | |
if current and current:name() == name then return true end | |
local device = hs.audiodevice.findOutputByName(name) | |
if device == nil then | |
hs.alert.show(name.." is not connected") | |
else | |
return device:setDefaultOutputDevice() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//dateFormat(new Date(), '%Y-%m-%d %H:%M:%S'); | |
var dateFormat = function(date, fstr) { | |
return fstr.replace (/%[YmdHMS]/g, function (m) { | |
switch (m) { | |
case '%Y': return date.getFullYear(); | |
case '%m': m = date.getMonth() + 1; break; | |
case '%d': m = date.getDate(); break; | |
case '%H': m = date.getHours(); break; | |
case '%M': m = date.getMinutes(); break; | |
case '%S': m = date.getSeconds(); break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Removes JavaScript comments from a string by replacing | |
* everything between block comments and everything after | |
* single-line comments in a non-greedy way. | |
* | |
* English version of the regex: | |
* match '/*' | |
* then match zero or more instances of any character (incl. \n) | |
* except for instances of '* /' (without a space, obv.) | |
* then match '* /' (again, without a space) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test() { | |
var evts = 'loadstart canplaythrough canplay loadeddata loadedmetadata abort emptied error stalled suspend waiting pause play volumechange playing seeked seeking durationchange progress ratechange timeupdate ended webkitbeginfullscreen webkitendfullscreen'; | |
var url = 'http://i3.ihaveu.net/image/auction/video/000/007/603/swf/000ab24b8d49a3331e6f7be30af7de1f.swf.mm320x232.mp4'; | |
var p = document.createElement('video'), | |
$p = $(p); | |
$('body').append(p); | |
$p.bind(evts, function(e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requestAnimationFrame = window.requestAnimationFrame || | |
window.mozRequestAnimationFrame || | |
window.webkitRequestAnimationFrame || | |
window.msRequestAnimationFrame || | |
window.oRequestAnimationFrame || | |
function(callback) { setTimeout(callback, 1000 / 60); }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Define a module along with a payload | |
* @param module a name for the payload | |
* @param payload a function to call with (require, exports, module) params | |
*/ | |
(function() { | |
var global = (function() { | |
return this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.textResizer = function(options) { | |
var el = $(this), h; | |
var settings = { | |
minHeight: el.height(), | |
maxHeight: 300, | |
duration: 100 | |
} | |
if (options) { | |
$.extend(settings, options); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(isie){ | |
if($.browser.version==6.0){ | |
image.onreadystatechange = function () { | |
if (image.readyState == "complete"){ | |
dothing(); | |
} | |
}; | |
}else{ | |
ie7imagetime = window.setInterval(function(){ | |
var rs = image.readyState; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<title>COLORFUL</title> | |
<script src="/jquery-1.js" type="text/javascript" charset="utf-8"></script> | |
<script src="/modernizr.js" type="text/javascript" charset="utf-8"></script> | |
<script src="/mustache.js" type="text/javascript" charset="utf-8"></script> | |
<script> |
NewerOlder