A Paris
Thursday, October 4, 2012
Update eclipse to support new maven resource
This command will update eclipse to support new maven resource needed by the project
mvn eclipse:eclipse -DdownloadSources
Thursday, August 11, 2011
Ajax
$.ajax({
url: "/inbox/newresults",
async: true,
dataType: 'json',
data: data,
timeout: 3000,
success: function(json) {
if(json == null || json.currenttime == undefined){
return;
}
//json.count=Math.ceil(Math.random()*100);
if(json.count > 0 && json.count != monitor.numOfNewResults ){
monitor.lastCheckingTime = json.currenttime;
monitor.message=_("Vous avez %1 nouveaux résultats")
.replace('%1',''+json.count+'');
document.title = document.title.replace(/\s+\(\d+\)$/,'')+' ('+json.count+')';
}
monitor.refresh();
monitor.numOfNewResults = json.count;
}
});
public function action_availableSerieObjectTypes(){ $this->auto_render=false; $types = stats\Chart::getAvailableChartTypes(); // translate foreach($types as $k=>$v){ $types[$k]=_($v); } $this->request->response = json_encode(array('serie_object_types'=>$types)); }
Reference:
Wednesday, August 10, 2011
Javascript Utilities
function createTag(tag, content, attrs){ var ret = "<" + tag; var isFirst = true; if(attrs != null){ for( var k in attrs){ if(isFirst){ isFirst = false; ret = ret + " " + k + "='"; } else{ ret = ret + ", " + k + "='"; } ret = ret + attrs[k] + "'"; } } if(content == null){ ret = ret + "/>\n"; } else ret = ret + ">" + content + "" + tag + ">\n"; return ret; } function createComboBox(options, defaultOption, attrs){ var ret = ""; for( var i in options){ if(defaultOption != null && defaultOption == options[i]){ ret += createTag("option", options[i], {"selected":"true"}); } else{ ret += createTag("option", options[i]); } } ret = createTag("select", ret, attrs); return ret; };
Reference:
Thursday, August 4, 2011
关键字云
class Token{ public $count = 0; public $key = null; private $subTokens = array(); // type could be "object" or "category" public $type = null; public static function create($key, $type="object", $MIN_LEN=2, $MAX_LEN=6){ $t = new Token; $t->key = $key; $t->type = $type; $len = mb_strlen($key, "UTF-8"); if($len > $MIN_LEN){ if($len > $MAX_LEN){ $len = $MAX_LEN + 1; } $strs = self::extractTokenStrs($key, $len-1, $len-1); foreach($strs as $str){ $t->addSubToken($str); } } return $t; } public function addSubToken($key){ if(!isset($this->subTokens[$key])){ $this->subTokens[$key]=1; } else{ $this->subTokens[$key]++; } } public function getSubTokens(){ return array_keys($this->subTokens); } public static function extractTokenStrs($string, $MIN_LEN=2, $MAX_LEN=6){ $tokenStrs = array(); //match the 2-char, 3-char, 4-char, 5-char and 6-char tokens and put it into $rawtokens $len = mb_strlen($string, "UTF-8"); if($MAX_LEN >= $MIN_LEN){ for($k = $MAX_LEN; $k >= $MIN_LEN; $k--){ for($j = 0; $j <= $len-$MIN_LEN; $j++){ $subStr = mb_substr($string, $j, $k, "UTF-8"); if(mb_strlen($subStr, "UTF-8") != $k){ break; } $tokenStrs[] = $subStr; } } } return $tokenStrs; } } class Cloud{ private $keywords = array(); private $categories = array(); private function addToken($string){ if(empty($string)){ return false; } if(!isset($this->keywords[$string])){ $this->keywords[$string] = Token::create($string, "object"); } $this->keywords[$string]->count++; return $this->keywords[$string]; } private function addCategory($string){ if(empty($string)){ return false; } if(!isset($this->categories[$string])){ $this->categories[$string] = Token::create($string, "category"); } return $this->categories[$string]; } private function emptyCategories(){ $this->categories = array(); } public function addTokens($string){ $strs = self::split($string, array("的","了","然后","[\pP\pS\pZ\pC\pM]+","[0-9a-zA-Z]+")); foreach($strs as $str){ if(mb_strlen($str, "UTF-8") >= 2){ $this->addCategory($str); } } } private function emptyKeywordsList(){ $this->keywords = array(); } public function buildKeyWordsList(){ $this->emptyKeywordsList(); foreach($this->categories as $c){ $ss = Token::extractTokenStrs($c->key, 2, 6); foreach($ss as $s){ $this->addToken($s); } } } public static function longest_string_in_array($array) { $mapping = array_combine($array, array_map('mb_strlen', $array)); return array_keys($mapping, max($mapping)); } public function findBestMatchingWords($threshold){ /* find the longest words satisfies the threshold */ $keywords = array(); foreach($this->categories as $k){ $this->extractCategoryKeywords($k, $threshold, $keywords); } $keys = array_keys($keywords); if(count($keywords)===0){ return false; } $lkeys = self::longest_string_in_array($keys); $ret = array(); foreach($lkeys as $k){ $ret[$k] = $keywords[$k]; } return $ret; } private function removeInfluence(Token $token){ $num = $token->count; $ss = Token::extractTokenStrs($token->key, 2, 6); foreach($ss as $s){ $this->keywords[$s]->count-=$num; } } public function getKeywords($threshold = 3){ $this->buildKeyWordsList(); $stopList = array(); $keywords = array(); $categoriesToRestore = $this->categories; while(true){ $bestWords = $this->findBestMatchingWords($threshold); if($bestWords === false){ break; } // add it to stopList // add it the keywords foreach($bestWords as $w){ $keywords[$w->key]= $w; $this->removeInfluence($w); $stopList[] = $w->key; } // use the stop list to rebuild the categories $oldCategories = $this->categories; $this->emptyCategories(); foreach($oldCategories as $c){ $list = self::split($c->key, $stopList); foreach( $list as $nc){ $this->addCategory($nc); } } } $this->categories = $categoriesToRestore; return $keywords; } public static function split($string, $delimiters){ //build the patterns $pattern = "/"; foreach($delimiters as $c => $d){ if($c === 0){ $pattern = $pattern.$d; } else{ $pattern = $pattern."|".$d; } } $patterns = $pattern."/isu"; $rawtokens = preg_split($patterns, $string); return $rawtokens; } public function extractCategoryKeywords($root, $threshold, &$keywords=null){ $key = $root->key; if($keywords === null){ $keywords = array(); } if(isset($keywords[$key])){ return; } if(isset($this->keywords[$key]) && $this->keywords[$key]->count >= $threshold){ $keywords[$key]=$this->keywords[$key]; } else{ $subTokens = $root->getSubTokens(); foreach( $subTokens as $s){ $this->extractCategoryKeywords($this->keywords[$s], $threshold, $keywords); } } } }// Cloud ends set_time_limit ( 1000 ); $string = <<<EOT meta http-equiv="Content-Type" content="text/html; charset=UTF-8" meta name="description" content="[回到部落格首頁]" EOT; $cloud = new Cloud(); $cloud->addTokens($string); print_r(array_keys($cloud->getKeywords(3))); echo "hello";
Reference
Tuesday, August 2, 2011
优女友待举措
【女孩子希望得到,却不愿说出的事】:
1.搂她的腰;
2.跟她真正的谈话;
3.和她分享秘密;
4.给她一件你的衬衫;
5.温柔地亲她;
6.和她拥抱;
7.和她一起笑;
8.带她去你去的地方;
9.和朋友出去玩时带上她;
10.和她合影;
11.让她坐在你膝上;
12.告诉她她很漂亮;
13.不要对她说谎;
14.别脚踏两只船......
Reference:
1.搂她的腰;
2.跟她真正的谈话;
3.和她分享秘密;
4.给她一件你的衬衫;
5.温柔地亲她;
6.和她拥抱;
7.和她一起笑;
8.带她去你去的地方;
9.和朋友出去玩时带上她;
10.和她合影;
11.让她坐在你膝上;
12.告诉她她很漂亮;
13.不要对她说谎;
14.别脚踏两只船......
Reference:
PHP general variable or array control
//swap two variables function swap (&$x, &$y) { $x ^= $y ^= $x ^= $y; }
Reference:
Subscribe to:
Posts (Atom)