Skip to content

Instantly share code, notes, and snippets.

// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
/*
* 频率控制 返回函数连续调用时,fn 执行频率限定为每多少时间执行一次
* @param fn {function} 需要调用的函数
* @param delay {number} 延迟时间,单位毫秒
* @param immediate {bool} 给 immediate参数传递false 绑定的函数先执行,而不是delay后后执行。
* @return {function} 实际调用函数
*/
var throttle = function (fn,delay, immediate, debounce) {
var curr = +new Date(),//当前时间
last_call = 0,
@liunian
liunian / gist:5932390
Created July 5, 2013 06:29
批量复制文件来简单测试是否扩容,可以直接copy大文件,不用等测试工具动态生成小文件
@echo off
for /l %%i in (1,1,115) do (
@echo %%i...
copy sourceFile Path/%%i_DesinationFile
)
pause
@liunian
liunian / gist:5926438
Last active April 26, 2024 03:32
javascript sort
/*
list: the array
fn: sort fn
start: the start index of the sorted range, included
end: the end index of the sorted range, excluded
means range: [start, end)
modify the array itself and return nothing
*/
@liunian
liunian / gist:5910792
Created July 2, 2013 16:23
fix top and scroll bottom
// http://msdn.microsoft.com/zh-cn/library/ie/bg124132(v=vs.85).aspx
epx = window.epx || {}, epx.library = window.epx.library || {}, epx.library.tocFixedModule = function(w, d) {
function init() {
epx.topic && epx.topic.isPrintExperience() === !0 || ($leftNav = $("#leftNav"), $toc = $("#tocnav"), $footer = $("#ux-footer"), w && d && $leftNav.length !== 0 && $toc.length !== 0 && $footer.length !== 0) && ($(w).scroll(function() {
setPosition()
}), $(w).resize(function() {
setPosition()
}))
}
@liunian
liunian / gist:5676234
Created May 30, 2013 07:24
jquery 和 underscore 式的构造器,有无 new 都会进行创建,传入已创建的对象会直接返回
var _ = function(obj) {
if (obj instanceof _) return obj;
if (!(this instanceof _)) return new _(obj);
this._wrapped = obj;
};
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
@liunian
liunian / gist:4116655
Created November 20, 2012 07:57
chrome scrollbar style
/* from http://www.alloyteam.com/wp-content/themes/alloyteam/style.css */
::-webkit-scrollbar-track-piece {
background-color:#f5f5f5;
border-left:1px solid #d2d2d2;
}
::-webkit-scrollbar {
width:13px;
height:13px;
}
::-webkit-scrollbar-thumb {
@liunian
liunian / gist:4015978
Created November 5, 2012 08:16
detect whether the client is ie6 or not
function isIE6() {
return strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.0');
}
# ie6's UA example
# Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 6.1; QQDownload 731; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)3
@liunian
liunian / jquery.ui.intersect.js
Created November 1, 2012 02:31
calc two rectangle's position relation
$.ui.intersect = function(draggable, droppable, toleranceMode) {
if (!droppable.offset) return false;
var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
var l = droppable.offset.left, r = l + droppable.proportions.width,
t = droppable.offset.top, b = t + droppable.proportions.height;
switch (toleranceMode) {