Skip to content

Instantly share code, notes, and snippets.

View furixturi's full-sized avatar
😈

Xiaoli Shen furixturi

😈
View GitHub Profile
@furixturi
furixturi / gist:6775381
Last active December 24, 2015 09:09
HTML5 canvas mouse event
addMouseEvents: function (){
this.canvas.addEventListener('mousedown', function(event){
console.log("mouse down");
}, false);
this.canvas.addEventListener('mouseup', function(event){
console.log("mouse up");
}, false);
}
@furixturi
furixturi / gist:6775391
Last active December 24, 2015 09:09
neutralize request animation frame function
neutralizeAnimationFunc: function(){
if(!window.requestAnimationFrame){
window.requestAnimationFrame = (window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
return window.setTimeout(callback, 1000/60);
});
}
@furixturi
furixturi / gist:6775423
Created October 1, 2013 08:28
Check canvas support
checkCanvasSupport: function(){
if(!document.createElement('canvas').getContext) {
alert("This browser dosn't support the canvas element");
return false;
}else{
console.log("success!");
return true;
}
},
@furixturi
furixturi / gist:6775430
Created October 1, 2013 08:29
Use reauestAnimationFrame
drawFrame: function(){
window.requestAnimationFrame(this.drawFrame, this.canvas);
this.render();
},
@furixturi
furixturi / gist:6790715
Created October 2, 2013 08:34
simulate slow connection in osx
# configure a pipe rule
sudo ipfw pipe 1 config bw 512Kbit/s delay 500ms
# add the pipe to connection in and out port 80
sudo ipfw add 1 pipe 1 src-port 80
sudo ipfw add 2 pipe 1 dst-port 80
# remove the rules and delete the pipe
sudo ipfw delete 1
sudo ipfw delete 2
@furixturi
furixturi / gist:7413927
Created November 11, 2013 14:27
JS stack trace
var err = new Error();
console.log(err.stack)
@furixturi
furixturi / shuffleAry.js
Created July 31, 2017 23:48
Fischer-Yates shuffle an array
function shuffleArray(ary) {
var i = ary.length, j, x;
while (i) {
j = Math.floor(Math.random() * i);
i -= 1;
x = ary[i];
ary[i] = ary[j];
ary[j] = x;
}
}
@furixturi
furixturi / wp-without-ftp.php
Created September 10, 2017 13:08
add a wordpress template file without using ftp
/* in header.php */
<?php touch('wp-content/themes/{your theme name}/{your template name}.php'); ?>
let aConstant: Int = 70
var aVariable: Int = 70
aConstant += 1 // Error! aConstant is not mutable
aVariable += 1
let numOfApples = 3
print("I have \(numOfApples) apples")