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 / 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 / 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 / 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)
//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 / 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()