Skip to content

Instantly share code, notes, and snippets.

View hfhimage's full-sized avatar

hfhimage hfhimage

View GitHub Profile
@hfhimage
hfhimage / xiami_decode.py
Created November 18, 2012 08:31 — forked from dndx/xiami_decode.py
Xiami URL Decoder
import urllib2
def xiami_decode(s):
s = s.strip()
if not s:
return False
result = []
line = int(s[0])
rows = len(s[1:]) / line
extra = len(s[1:]) % line
@hfhimage
hfhimage / xiami_decode.js
Last active October 12, 2015 23:28 — forked from fanzeyi/xiami_decode.js
Xiami URL Decoder
function decode(loca) {
var result = [], url = "";
var line, rows, extra;
loca = loca.trim();
if(loca === "") {
return "";
}
line = Number(loca[0]);
rows = Math.floor((loca.length - 1) / line);
extra = (loca.length - 1) % line;
@hfhimage
hfhimage / twitter storm 学习资源汇总
Created April 17, 2013 07:18
twitter storm 学习资源汇总
storm-contrib
https://github.com/nathanmarz/storm-contrib
java doc
http://nathanmarz.github.com/storm/doc-0.8.1/index.html
implemention doc
https://github.com/nathanmarz/storm/wiki/Implementation-docs
trident
https://github.com/nathanmarz/storm/wiki/Trident-tutorial
使用者:支付宝、淘宝、阿里巴巴、twitter、groupon
function throttle( fn, time ) {
var t = 0;
return function() {
var args = arguments, ctx = this;
clearTimeout(t);
t = setTimeout( function() {
fn.apply( ctx, args );
}, time );
};
@hfhimage
hfhimage / read file.php
Created September 20, 2013 14:59
php 文件阅读
$filename = "myfile";
if (file_exists($filename) && is_readable ($filename)) {
$fh= fopen($filename, "r");
while (!feof($fh)) {
$line = fgets($fh);
echo $line;
}
fclose($fh);
}
@hfhimage
hfhimage / data.php
Created September 20, 2013 15:01
php 时间操作
date('Y-m-d', strtotime("-2 weeks"))
@hfhimage
hfhimage / exit.php
Created September 20, 2013 15:03
php exit() 方法的使用例子
//exit program normally
exit;
exit();
exit(0);
//exit with an error code
exit(1);
exit(0376); //octal
// 错误则退出
@hfhimage
hfhimage / function.php
Created September 20, 2013 15:22
php 常量__FUNCTION__
// __FUNCTION__ 为函数名称
function shutdown() {
echo 'Shutdown: ' . __FUNCTION__ . '()' . PHP_EOL;
}
@hfhimage
hfhimage / h.php
Created September 20, 2013 15:24
htmlentities() 和 htmlspecialchars()
echo htmlentities($str); // 会将中文字符也转义
echo htmlspecialchars($str); // 只转换一些特殊的html代码
一般最好使用htmlspecialchars($str)
@hfhimage
hfhimage / empty.php
Created September 20, 2013 15:25
empty()和isset()的区别
empty($x) 等于 !isset($x) || !$x
!empty($x) 等于 isset($x) && $x