Skip to content

Instantly share code, notes, and snippets.

View wudi's full-sized avatar
🎯
Focusing

Di Wu wudi

🎯
Focusing
View GitHub Profile
<?php
$dbConnection = new PDO('mysql:dbname=dbtest;host=127.0.0.1;charset=utf8', 'user', 'pass');
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
@wudi
wudi / nsobject_to_string.php
Last active August 29, 2015 14:06
NSObject To String
<?php
$str = '82a16300 a16482a9 61737365 745f6b65 79da002a 31343130 37383632 33333538 61393737 63363732 61393836 61353333 39303238 61363035 35343261 3832a564 65627567 da005968 7474703a 2f2f3139 322e3136 382e3738 2e31373a 38303830 2f63646e 5f617373 6574732f 61756469 6f2f3230 31343039 2f31352f 62633537 61353430 34333461 31656534 38386132 30386632 64643733 37316135 2e616d72';
$str = str_replace(' ','',$str);
for($i =0; $i<strlen($str); $i+=2){
$char = substr($str, $i,2);
$dec_str = hexdec($char);
echo chr($dec_str);
}
@wudi
wudi / new_gist_file_0
Created October 11, 2014 07:51
iOS程序字体与ps设计字体换算
一,ps和pt转换px:相对长度单位。像素(Pixel)。(PS字体)
pt:绝对长度单位。点(Point)。(iOS字体)公式如下:pt=(px/96)*72。二,字体间转换1in = 2.54cm = 25.4 mm = 72pt = 6pc
具体换算是:
Points Pixels Ems Percent
6pt 8px 0.5em 50%
7pt 9px 0.55em 55%
7.5pt 10px 0.625em 62.5%
8pt 11px 0.7em 70%
9pt 12px 0.75em 75%
10pt 13px 0.8em 80%
@wudi
wudi / random.js
Created October 13, 2014 09:42
JS 生成范围内随机整数
var randNum = function (min, max) {
return parseInt(Math.random() * (max - min + 1) + min, 10);
};
@wudi
wudi / Imagick.php
Created October 16, 2014 05:10
Imagick图片处理类库
<?php
class Imagick
{
/**
* @var \Imagick
*/
private $image = NULL;
private $type = NULL;
<?php
function distance($data1, $data2) {
$num = 0;
for ($i = 0; $i < sizeof($data1); $i++) {
$num += pow($data1[$i] - $data2[$i], 2);
}
return sqrt($num);
}
@wudi
wudi / userAgents.js
Created January 12, 2015 02:45
userAgents.js
userAgents = [{'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0'},
{"User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1) Gecko/20090624 Firefox/3.5"},
{'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'},
{"User-Agent":"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1"},
{"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 TaoBrowser/2.0 Safari/536.11"},
{"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER"},
{"User-Agent":"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; LBBROWSER)"},
{"User-Agent":"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E; LBBROWSER)"},
{"U
@wudi
wudi / cls_template.php
Created January 28, 2015 15:24
ECshop preg_replace /e 修饰符修复(本文件可直接替换2.7.3)
<?php
/**
* ECSHOP 模版类
* ============================================================================
* * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。

集群

CLUSTER INFO 打印集群的信息

CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息。

节点

127.0.0.1:12345> TTL key # 尚未过期
(integer) 3
127.0.0.1:12345> TTL key
(integer) 1
127.0.0.1:12345> TTL key # 虽然键已经过期,但因为我阻塞住了主服务器,
(integer) 0 # 而主服务器没办法向从服务器发送 DEL 命令,所以值会一直滞留在从服务器里面。
127.0.0.1:12345> GET key
"value"
127.0.0.1:12345> TTL key
(integer) 0