Skip to content

Instantly share code, notes, and snippets.

View gkatsev's full-sized avatar

Gary Katsevman gkatsev

View GitHub Profile
@gkatsev
gkatsev / gist:5456373
Created April 24, 2013 23:14
preventDefault a click on android
if (/android/i.test(navigator.userAgent) && !/chrome/i.test(navigator.userAgent)) {
this.on('click', function(event) {
event.preventDefault();
event.stopPropagation();
});
} else {
this.on('touchend', function(event) {
event.preventDefault();
event.stopPropagation();
});
if (this.player_.muted()) {
return 0;
} else {
return this.player_.volume();
}
@gkatsev
gkatsev / loadscript.js
Created May 10, 2013 23:48
A simple script loader
// loadScript :: String, function, predicate [, arg1 [, arg2 [, ...]]] -> undefined
// The optional arguments will get passed to the callback
var loadScript = (function() {
var scripts = {};
return function(url, callback, predicate) {
var
body = document.body,
script = document.createElement('script'),
loaded = false,
var Ctor = (function(window, undefined) {
var private = 5;
var Ctor = function() {
// ...
}
Ctro.protoype.foo = function() {
return private;
}
@gkatsev
gkatsev / objcreate.js
Created May 27, 2013 22:11
Object.create in JS.
var foo = {};
var bar = Object.create(foo);
@gkatsev
gkatsev / toggleable.js
Created July 25, 2013 20:26
A toggleable object.
var Toggleable = function(a, b) {
this._a = a;
this._b = b;
};
Toggleable.prototype.valueOf = function() { return this._a; };
Toggleable.prototype.toggle = function() {
if (this.valueOf() == this._a) {
@gkatsev
gkatsev / module.js
Last active December 20, 2015 06:28
define(function(require, exports, module) {
var $ = require('jquery');
});
function foo(id) {
var deferred = q.defer();
bar(id)
.then(function(obj) {
var anotherDeferred = q.defer();
log('fail');
@gkatsev
gkatsev / gist:6528315
Created September 11, 2013 19:08
log shows only `foo`.
var http = require('http');
var server = http.createServer(function(req, res) {
console.log('foo');
res.end('foo');
}, function(req, res) {
console.log('bar');
res.end('bar');
});
server.listen(5555);
function readTep(evt) {
var three;
taps.push((new Date()).getTime());
taps = taps.slice(-3);
if (taps.length === 3) {
three = taps.reduce(function(p, c, i) {
return p && Math.abs(c - (taps[i - 1] || c)) < 50;
}, true);
if (three) {