Skip to content

Instantly share code, notes, and snippets.

/*!
* jQuery Tiny Pub/Sub - v0.6 - 1/10/2011
* http://benalman.com/ see https://gist.github.com/661855
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* (removed pre 1.4.3 support, added $.pubsubdebug())
*/
@feng-ming
feng-ming / utf8_detect.php
Last active December 13, 2015 20:28
检测文件是否是UTF-8编码。 转换非UTF-8编码的文件到UTF-8编码
<?php
//检测字符串是否是utf-8编码
if(mb_detect_encoding($content,"UTF-8, ISO-8859-1, GBK, gb2312") !== 'UTF-8')
{
$content = iconv("gbk","utf-8",$content);
}
//转换文件为utf-8编码的文件,如果该文件开始即为utf-8,则不会做任何处理
enca -L zh_CN -x UTF-8 $script_dir/../upload/text/$1.txt
@feng-ming
feng-ming / command_exist
Last active December 13, 2015 20:28
检测系统命令是否存在
<?php
//仅仅试用于linux/mac环境
function command_exist($cmd)
{
$returnVal = shell_exec("which $cmd");
return (empty($returnVal) ? false : true);
}
@feng-ming
feng-ming / set_union.php
Created June 8, 2013 14:50
php 实现交并集算法
<?php
$node_arr = array();
//记录每个单词首次出现的位置
$word_position = array();
/**
* 查找当前节点大夫节点
*/
function find($node)
{
@feng-ming
feng-ming / object_len.js
Created June 9, 2013 14:36
js 对象的长度。
Object.keys(myObject).length
@feng-ming
feng-ming / file_path_test.sh
Last active April 4, 2018 02:53
unix shell 判断目录/文件是否存在, 以及是否有读写权限。
shell判断文件,目录是否存在或者具有权限
#!/bin/sh
Path="/var/log/httpd/"
File="/var/log/httpd/access.log"
#这里的-x 参数判断$Path是否存在并且是否具有可执行权限
if [ ! -x "$Path"]; then
mkdir "$Path"
fi
1. if (typeOf(x) === 'undefined')
2. if (typeOf(x) !== 'object')
3. if (!x)
function letNodeCenter(selector) {
var _top = ($(window).height() - $(selector).heigh())/2,
_left = ($(window).height() = $(selector).height())/2,
_scrollTop = $(document).scrollTop(),
_scrollLeft = $(document).scrollLeft();
$(selector).css({position: 'absolute', top: top + scrollTop, left: left + scrollLeft }).show()
}

#Four Ways To Do Pub/Sub With jQuery and jQuery UI (in the future)

Between jQuery 1.7 and some of work going into future versions of jQuery UI, there are a ton of hot new ways for you to get your publish/subscribe on. Here are just four of them, three of which are new.

(PS: If you're unfamiliar with pub/sub, read the guide to it that Julian Aubourg and I wrote here http://msdn.microsoft.com/en-us/scriptjunkie/hh201955.aspx)

##Option 1: Using jQuery 1.7's $.Callbacks() feature:

$.Callbacks are a multi-purpose callbacks list object which can be used as a base layer to build new functionality including simple publish/subscribe systems. We haven't yet released the API documentation for this feature just yet, but for more information on it (including lots of examples), see my post on $.Callbacks() here:

@feng-ming
feng-ming / scroll_to_bottom.js
Last active August 29, 2015 13:58
Scroll to bottom of div
var objDiv = document.getElementById("div");
objDiv.scrollTop = objDiv.scrollHeight;