This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
from bisect import bisect | |
FIRST_LETTERS = ["a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "l", "m", "n", | |
"o", "p", "q", "r", "s", "t", "w", "x", "y", "z"] | |
FIRST_NUMBERS = [1, 37, 233, 478, 674, 702, 833, 994, 1187, 1506, 1612, 1872, | |
2035, 2122, 2130, 2258, 2427, 2486, 2790, 2958, 3084, 3325, 3649] | |
PINYIN_LETTERS = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A signal/slot implementation | |
File: signal.py | |
Author: Thiago Marcos P. Santos | |
Author: Christopher S. Case | |
Author: David H. Bronke | |
Created: August 28, 2008 | |
Updated: December 12, 2011 | |
License: MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function test_rrd() | |
{ | |
/* 数据初始化,weight: 权重 */ | |
$hosts = array('a'=>5, 'b'=>3, 'c'=>2); | |
$result = array(); | |
/* 模拟10次 */ | |
for ($i = 0; $i < 10; $i++) { | |
round_robin($hosts, $result); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 表示Yes的字符串 | |
*/ | |
function is_yes ($word) | |
{ | |
$yes_words = array( | |
'1','y','t','ok','yes','true','allow','agree' | |
); | |
return $word && in_array(strtolower($word), $yes_words); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* 过滤$_REQUEST字符串中的危险字符,用于mysql查询 */ | |
function str2db($input, $strip_tags=true) { | |
if(is_array($input)) { | |
foreach($input as $key => $value) { | |
$input[$key] = str2db($value); | |
} | |
} else { | |
if(get_magic_quotes_gpc()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 找出上个月的这一天,没有这一天时使用月末 | |
* (使用时间戳计算,避免判断跨年) | |
*/ | |
function last_month_day($time) | |
{ | |
$day = intval(date('d', $time)); //当月第几天 | |
$time -= $day * 86400; //退回上月最后一天 | |
$tail_day = intval(date('d', $time)); //上个月有多长 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./configure --prefix=/opt/php-5.4.21 \ | |
--with-mysql --with-mysqli --with-pdo-mysql --with-mysql-sock=/var/run/mysqld/mysqld.sock \ | |
--with-mcrypt --with-zlib --enable-zip --with-bz2=shared \ | |
--with-pic --with-curl=shared --with-freetype-dir --with-png-dir \ | |
--with-gettext=shared --with-gmp=shared --with-iconv --with-jpeg-dir --with-png-dir \ | |
--with-libxml-dir --with-pcre-regex --with-kerberos \ | |
--with-openssl --with-imap --with-imap-ssl \ | |
--with-pear --with-gd --enable-gd-native-ttf --enable-calendar=shared \ | |
--enable-exif --enable-ftp --enable-sockets --enable-bcmath=shared \ | |
--enable-pcntl --enable-intl --enable-mbstring \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name blog.com; | |
root /var/www/wordpress; | |
set $var_sessid "-"; | |
access_log logs/blog.access.log main; | |
#charset utf-8; | |
index index.html index.php; | |
error_page 404 /404.html; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import sys | |
import os, os.path | |
os.chdir(os.path.dirname(os.path.realpath(__file__)) | |
if sys.getdefaultencoding() != 'utf-8': | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
from datetime import datetime |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/etc/init.d/mysql stop | |
/etc/init.d/mysql start --skip-grant-tables | |
#回车输入空密码 | |
mysql -u root -p | |
--执行SQL语句 | |
UPDATE mysql.user SET Password=PASSWORD('my-new-password') WHERE User='root'; | |
FLUSH PRIVILEGES; | |
quit; |