Skip to content

Instantly share code, notes, and snippets.

@feng-ming
feng-ming / ddd
Created August 4, 2020 12:19
sdf #java
public static List<String> entriesSortedByValues(List<String> lists) {
Collections.sort(lists,
new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o2.split("\\|")[0].compareTo(o1.split("\\|")[0]);
}
}
);
return lists;
@feng-ming
feng-ming / 0_reuse_code.js
Created April 22, 2014 08:37
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@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;

#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:

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()
}
1. if (typeOf(x) === 'undefined')
2. if (typeOf(x) !== 'object')
3. if (!x)
@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
@feng-ming
feng-ming / object_len.js
Created June 9, 2013 14:36
js 对象的长度。
Object.keys(myObject).length
@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 / 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);
}