Skip to content

Instantly share code, notes, and snippets.

View LeoYuan's full-sized avatar

LeoYuan 袁力皓 LeoYuan

  • Alibaba
  • Hangzhou
View GitHub Profile
@LeoYuan
LeoYuan / code-status.js
Created October 24, 2016 12:02
判断代码是否已经commit/pull/push
exports.runCmd = function(cmd) {
return Q.nfcall(exec, cmd);
}
// 检测代码是否已经ci
exports.checkCodeStatus = function() {
return this.runCmd('git status')
.then(function(stObj) {
var stMsg = stObj[0];
if (stMsg.indexOf('git add') !== -1 || stMsg.indexOf('git checkout') !== -1) {
@LeoYuan
LeoYuan / deepclone-smart.js
Created May 11, 2016 11:57
a very smart & neat way to deep clone an array of objects
const clonedArray = JSON.parse(JSON.stringify(objectArray));
// ref: http://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search
var fs = require('fs');
var path = require('path');
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var pending = list.length;
if (!pending) return done(null, results);
@LeoYuan
LeoYuan / fs-exists-promise.js
Created April 13, 2016 02:42
判断文件是否存在的promise方法
const fs = require('fs-extra');
// 1. 使用fs.exists
function exists(path) {
return new Promise(resolve => {
fs.exists(path, resolve);
})
}
// 2. 使用fs.stat
@LeoYuan
LeoYuan / exposure.js
Last active November 16, 2015 08:39
判断图片是否曝光
/**
* 判断图片是否曝光
*/
// 图片离屏幕边缘的GAP值,用于提前曝光图片,优化用户浏览体验
var OFFSET_GAP = 30;
var $win = $(window);
var $doc = $(document);
function isExposured(img) {
@LeoYuan
LeoYuan / loadMore.js
Last active November 12, 2015 04:22
loading more
/**
* 加载更多,设计要点:
* 1. 使用controller来控制滚动节流,传递controller给用户回调,用户自由控制节流,以及是否终止loadMore行为;
* 2. loadMore返回controller,让用户可以停止、启动loadMore,特别适合单页应用时不断启停loadMore;
*
* @author lihao.ylh@alibaba-inc.com
* @date 2015-11-09 11:06
*/
var LOADING_SELECTOR = '#loading';