Skip to content

Instantly share code, notes, and snippets.

View numbcoder's full-sized avatar
🎯
Focusing

Seekr Wang numbcoder

🎯
Focusing
View GitHub Profile
@numbcoder
numbcoder / connect_to_airpods.lua
Created April 4, 2022 13:18
Connect to AirPods for hammerspoon
-- 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()
//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;
@numbcoder
numbcoder / removeComments.js
Created October 18, 2012 09:02
remove js or json comments
/**
* 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)
@numbcoder
numbcoder / video_events.js
Created February 14, 2012 08:56
test video events
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) {
@numbcoder
numbcoder / gist:1564086
Created January 5, 2012 07:04
new animation method
requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.oRequestAnimationFrame ||
function(callback) { setTimeout(callback, 1000 / 60); };
@numbcoder
numbcoder / require.js
Created December 20, 2011 07:21
CommonJS Module simple implemention
/**
* 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;
@numbcoder
numbcoder / testResize.js
Created November 22, 2011 10:21
Textarea auto resize
$.fn.textResizer = function(options) {
var el = $(this), h;
var settings = {
minHeight: el.height(),
maxHeight: 300,
duration: 100
}
if (options) {
$.extend(settings, options);
}
@numbcoder
numbcoder / gist:1287356
Created October 14, 2011 14:59 — forked from xdite/gist:758319
Ruby / Rails Convention of Techbang

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
@numbcoder
numbcoder / image_load.js
Created July 5, 2011 09:31
js image load
if(isie){
if($.browser.version==6.0){
image.onreadystatechange = function () {
if (image.readyState == "complete"){
dothing();
}
};
}else{
ie7imagetime = window.setInterval(function(){
var rs = image.readyState;
<!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>