Skip to content

Instantly share code, notes, and snippets.

@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
/*
* 频率控制 返回函数连续调用时,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,
// 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] ||
@liunian
liunian / gist:7133112
Created October 24, 2013 08:08
A to Z in 10x10
/*
10 x 10
A-Z ( 65 -> 90)
output something like this
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* J I * * * * * * *
var supports = (function() {
var div = document.createElement('div'),
vendors = 'Khtml Ms O Moz Webkit'.split(' '),
len = vendors.length;
return function(prop) {
if ( prop in div.style ) return true;
prop = prop.replace(/^[a-z]/, function(val) {
return val.toUpperCase();
@liunian
liunian / isContain
Last active April 26, 2024 03:30
mouseenter / mouseleave
function bindMouseLeave(obj, fn) {
if (obj.attachEvent) {
obj.attachEvent('onmouseleave', function() {
fn.call(obj, window.event);
});
} else {
obj.addEventListener('mouseout', function(e) {
var rt = e.relatedTarget;
if (rt !== obj && !isContain(obj, rt)) {
fn.call(obj, e);
@liunian
liunian / gist:9338301
Last active April 26, 2024 03:30
Human Readable File Size with PHP
<?php
# http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
function human_filesize($bytes, $decimals = 2) {
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
echo human_filesize(filesize('example.zip'));
@liunian
liunian / gist:9757295
Last active April 26, 2024 03:30
References
{
'Safari Developer Library': 'https://developer.apple.com/library/safari/navigation/index.html',
'Safari HTML Reference': 'https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html',
'Safari Web Content Guide': 'https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html'
}
/**
* find all markdown files in given directory, (here just current directory)
* and then fetch their title to generate index markdown file
*
* use -v to show verbose detail
* use -o to specify output file, default to ./index.md
* use -d to specify scanner directory, such as -d the_directory, default to ./
*/
var fs = require('fs'),
path = require('path')