Skip to content

Instantly share code, notes, and snippets.

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

Yan Sheng lizzie

🏠
Working from home
View GitHub Profile
@lizzie
lizzie / jscs-config.js
Created April 22, 2015 05:47
jscs 的配置文件
// jscs 配置文件
{
disallowAnonymousFunctions: true, // 不允许匿名函数
disallowCapitalizedComments: true, // 不允许注释首字符大写
disallowCommaBeforeLineBreak: true, // 不允许逗号出现在换行符之前
disallowCurlyBraces: true, // 不允许语句后面出现不必要的大括号
disallowDanglingUnderscores: true, // 除特殊内置变量外,不允许变量名是下划线开头或结尾的
disallowEmptyBlocks: true, // 除 try catch 外,不允许空语句块
disallowFunctionDeclarations: true, // 不允许声明函数
@lizzie
lizzie / load-spm-components-by-webpack.js
Created April 20, 2015 08:47
webpack加载spm组件的配置
var webpack = require('webpack');
var path = require('path');
var bower_dir = path.join(__dirname, 'bower_components');
var node_modules_dir = path.join(__dirname, 'node_modules');
var spm_dir = path.join(__dirname, 'spm_modules');
var config = {
addVendor: function (name, path) {
this.resolve.alias[name] = path;
this.module.noParse.push(path);
@lizzie
lizzie / remove-event.js
Created October 30, 2013 03:10
IE8- 下, jQuery 绑定自定义事件之后, 无法删除导致内存泄露问题
// jQuery 1.7.2- removeEvent 的代码
function( elem, type, handle ) {
if ( elem.detachEvent ) {
elem.detachEvent( "on" + type, handle );
}
};
// jQuery 1.8.0+ removeEvent 的代码
function( elem, type, handle ) {
var name = "on" + type;
@lizzie
lizzie / ssh-config.txt
Last active December 25, 2015 18:39
Multiple SSH Keys settings for different github account
$ more ~/.ssh/config
Host github.com_ls
HostName github.com
User lizziesky@gmail.com // 邮箱或者账户名
IdentityFile ~/.ssh/id_rsa_ls
Host github.com
HostName github.com
User shengyan1985@gmail.com
IdentityFile ~/.ssh/id_rsa
@lizzie
lizzie / get_common_ancestor.js
Created July 17, 2013 06:52
获取节点公共的父节点
function getCommonAncestor(nodes) {
if (!nodes || !nodes.length) {
return null;
}
else if (nodes.length == 1) {
return nodes[0].parentNode;
} else {
var p = nodes[0],
pass = 0;
while (!pass && p != document.body) {
@lizzie
lizzie / is_empty_object.js
Last active December 18, 2015 14:09
判断是否空对象
function isEmptyObject(o) { // jQuery
var name;
for (name in o) {
return false;
}
return true;
}
function isEmptyObject(o) { // KISSY
@lizzie
lizzie / each.html
Created June 6, 2013 13:31
remove array item dynamically by each
<!doctype html>
<html>
<head>
<title>Test Each</title>
<script src="http://assets.spmjs.org/seajs/seajs/2.0.0/sea.js"></script>
</head>
<body>
<script>
@lizzie
lizzie / pubsub.js
Created February 20, 2013 05:06
Pub/Sub
var PubSub = {
subscribe: function(ev, callback) {
var calls = this._callbacks || (this._callbacks = {});
(this._callbacks[ev] || (this._callbacks[ev] = [])).push(callback);
return this;
},
publish: function() {
var args = Array.prototype.slice.call(arguments, 0);
@lizzie
lizzie / hash.js
Created February 20, 2013 04:56
about hash
window.location.hash = "something";
$(window).bind("hashchange", function() {
// do sth.
});
@lizzie
lizzie / es5_bind.js
Last active December 13, 2015 23:39
等价于ES5的bind()
if (!Function.prototype.bind) {
Function.prototype.bind = function (obj) {
var slice = [].slice,
args = slice.call(arguments, 1),
self = this,
nop = function () {},
bound = function () {
return self.apply( this instanceof nop ? this: (obj || {}), args.concat(slice.call(arguments)));
};