Skip to content

Instantly share code, notes, and snippets.

View GengGao's full-sized avatar
🏠
Working from home

Geng Gao GengGao

🏠
Working from home
View GitHub Profile
@GengGao
GengGao / .huskyrc
Last active April 19, 2022 05:53
Enable husky pre-commit hooks for Git GUI's
# set the PATH
PATH=/usr/local/bin:$PATH
# this loads nvm.sh and sets the correct PATH before running hook
. ~/.nvm/nvm.sh
@GengGao
GengGao / gist:8062726
Created December 20, 2013 22:37
for-in Loops that filters prototypes
var i, hasOwn = Object.prototype.hasOwnProperty;
for (i in man) {
if (hasOwn.call(man, i)) { // filter
console.log(i, ":", man[i]);
}
}
@GengGao
GengGao / .jshintrc
Last active December 28, 2015 17:38
removed comments
{
"maxerr" : 50,
"bitwise" : true,
"camelcase" : false,
"curly" : true,
"eqeqeq" : true,
"forin" : true,
"immed" : false,
"indent" : 4,
@GengGao
GengGao / .jshintrc
Last active December 25, 2015 19:59
JSHint config file
{
// Based on JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details
"maxerr" : 50, // {int} Maximum error before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : false, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
@GengGao
GengGao / gist:6025270
Created July 17, 2013 22:53
inherit function
function inherit(child, parent) {
var copy = Object.create(parent.prototype);
copy.constructor = child;
child.prototype = copy;
}
@GengGao
GengGao / gist:6024684
Created July 17, 2013 21:30
Douglas Crockford's Object.create method
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {
}
F.prototype = o;
return new F();
};
}
@GengGao
GengGao / gist:5700469
Created June 3, 2013 19:04
Better Feature check
var doSomthing = features.someFeature ? function() {
// Plan A
} : function() {
// Plan B
};
@GengGao
GengGao / gist:5075402
Created March 3, 2013 09:08
MDN .forEach()
// Shim .forEach()
if ( !Array.prototype.forEach ) {
Array.prototype.forEach = function(fn, scope) {
for (var i = 0, len = this.length; i < len; ++i) {
fn.call(scope || this, this[i], i, this);
}
}
}
@GengGao
GengGao / gist:4142363
Created November 25, 2012 04:10
jQuery: Scroll to Top
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
@GengGao
GengGao / gist:4142359
Created November 25, 2012 04:09
jQuery: Traversing the DOM
$("div#home").prev("div"); // find the div previous in relation to the current div
$("div#home").next("ul"); // find the next ul element after the current div
$("div#home").parent(); // returns the parent container element of the current div
$("div#home").children("p"); // returns only the paragraphs found inside the current div