Skip to content

Instantly share code, notes, and snippets.

@zzuhan
zzuhan / relative_path.php
Created March 12, 2014 08:18
测算相对路径,摘自php.net网友贡献
function relative($from, $to, $ps=DIRECTORY_SEPARATOR){
$arFrom = explode($ps, rtrim($from, $ps));
$arTo = explode($ps, rtrim($to, $ps));
while(count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0]))
{
array_shift($arFrom);
array_shift($arTo);
}
return str_pad("", count($arFrom) * 3, '..'.$ps).implode($ps, $arTo);
}
@zzuhan
zzuhan / *md-compatible.js
Created June 4, 2014 14:43
how to write amd,cmd,browser environment supported js code
/*
* this series is write like the title
*/
{
"db":{
"host":"127.0.0.1",
"port":3306,
"user":"root",
"password":"",
"database":"crawler"
},
"baseSite":"http://s3131212.com/links/"
}
@zzuhan
zzuhan / ajax.js
Created October 24, 2012 16:36
simple ajax
$('#loading').ajaxStart(function () {
$(this).show();
});
$('#loading').ajaxStop(function () {
$(this).hide();
});
$('#send').click(function () {
@zzuhan
zzuhan / drag.js
Last active December 26, 2015 03:19
code_structure simple module
function drag(o){
var params = {
startLeft: 0,
startTop: 0,
_x:
_y:
isDrag: false
};
params.startLeft = o.currentLeft;
@zzuhan
zzuhan / slideshow.js
Last active December 26, 2015 03:19
code_structure singleton
var slideshow = {
context: false,
tabs: false,
timeout: 1000,
slideSpeed: 1000,
tabSpeed: 300,
fx: 'scrollLeft'
init: function () {
this.context = $('#slideshow');
@zzuhan
zzuhan / timer.js
Created October 21, 2013 15:14
code_structure single var
$('#timer').focus(function(){
// turn on timer
startTimer();
}).blur(function(){
// turn off timer
endTimer();
});
var lastValue = "",
@zzuhan
zzuhan / check.js
Created October 29, 2013 01:37
check helpers function
// ECMAScript 5
function isEmpty(obj){
return Object.getOwnPropertyNames(obj).length === 0;
}
function isEmpty(obj){
return Object.keys(obj).length === 0;
}
// compitable
@zzuhan
zzuhan / uniqueid.js
Created November 3, 2013 15:20
create unique cid learn from underscore.js
var uniqueId = function () {
var idCounter = 0;
return function(prefix){
var id = ++idCounter + '';
return prefix ? prefix + id : id;
}
}();
var cid = uniqueId(); // 1
@zzuhan
zzuhan / get-global.js
Created November 23, 2013 02:31
Get global object in any js runtime environment.
(function(){
var global = this;
})();