Skip to content

Instantly share code, notes, and snippets.

@zmmbreeze
zmmbreeze / urlCacheTime.js
Created October 9, 2013 06:22
url resource update every hour.
url = url + '?cacheTime=' + Math.ceil(new Date() / 3600000);
@zmmbreeze
zmmbreeze / timeline.js
Created October 18, 2013 09:31
Timeline
/***************************************************************************
*
* Copyright (c) 2013 Baidu.com, Inc. All Rights Reserved
* $Id$
*
**************************************************************************/
goog.provide('ad.fx.Timeline');
goog.provide('ad.fx.moveTo');
@zmmbreeze
zmmbreeze / bookstyle.css
Created October 25, 2013 05:25
book css style test
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div class="book">
<h1>背影</h1>
<p>我与父亲不相见已二年余了,我最不能忘记的是他的背影。</p>
@zmmbreeze
zmmbreeze / module_base.js
Created November 12, 2013 03:23
module & define
if (typeof module === 'object' && module && typeof module.exports === 'object') {
// Node.js module pattern
module.exports = jQuery;
} else {
// AMD
if (typeof define === 'function' && define.amd) {
define('jquery-onscreen', [], function() { return jQuery; });
}
}
@zmmbreeze
zmmbreeze / guessVcsName.js
Created November 22, 2013 04:38
猜测当前目录使用了哪个版本控制系统的node函数
var Deferred = require('./Deferred'); // 支持Promise api的库都可以,例如q(http://documentup.com/kriskowal/q/)
var exec = require('child_process').exec;
/**
* 猜测当前目录使用了哪个版本控制系统
*
* @return {string} svn/git/hg/cvs, 如果检测不到返回空字符串
*/
function guessVcsName() {
var svnDef = new Deferred();
@zmmbreeze
zmmbreeze / resolvePath.js
Created December 2, 2013 11:03
`path.resolve` for browser
var resolvePath = function () {
function resolve(pathA, pathB) {
// 先做split,得到的结果如下几种
// ‘a’ => ['a']
// 'a/b' => ['a', 'b']
// '/a/b' => ['', 'a', 'b']
// '/a/b/' => ['', 'a', 'b', '']
pathB = pathB.split('/');
if (pathB[0] === '') {
// 如果pathB是想对于根目录
@zmmbreeze
zmmbreeze / inView.js
Created December 19, 2013 08:15
Is element in client view. use tangram
var inView = function (e) {
var clientW = baidu.page.getViewWith();
var clientH = baidu.page.getViewHeight();
var rect = e.getBoundingClientRect();
return (rect.bottom > 0 && rect.top < clientH)
&& (rect.right > 0 && rect.left < clientW);
};
/*!
* jQuery JavaScript Library v2.1.1pre
* http://jquery.com/
*
* Includes Sizzle.js
* http://sizzlejs.com/
*
* Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
* Released under the MIT license
* http://jquery.org/license
@zmmbreeze
zmmbreeze / getGlobal.js
Created March 5, 2014 08:46
Get global in node and browser
(function(win) {
// Do something with the global
})(Function('return this')());
@zmmbreeze
zmmbreeze / stringify.js
Created March 7, 2014 09:13
json stringify can deal with circular reference
// http://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-structure-to-json/11616993#11616993
var o = {};
o.o = o;
var cache = [];
JSON.stringify(o, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;