Skip to content

Instantly share code, notes, and snippets.

@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;
};
@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
*/
/*
* 频率控制 返回函数连续调用时,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: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 * * * * * * *
### BY: MUNFAQQIHA ####################################################################################################################################
######################### A BASH SHELL SCRIPT FOR LINUX AND WINDOWS TO AUTOMATICALLY NON-STOP UPLOAD FILES TO WWW.TERABOX.COM #########################
#######################################################################################################################################################
### ----------------------------------------------------------------------------------------------------------------------------------------------- ###
### | sample of successful upload: on linux: https://s.id/teraupnix || on windows: https://s.id/teraupwin | ###
### ----------------------------------------------------------------------------------------------------------------------------------------------- ###
### it is possible to upload multiple different types of files recursively, except 0-byte file size, in a folder
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'
}