Skip to content

Instantly share code, notes, and snippets.

View azhai's full-sized avatar
🪁
Focusing

azhai

🪁
Focusing
View GitHub Profile
@azhai
azhai / gb2pinyin.py
Last active December 19, 2015 12:29
GB2312中文转拼音
#-*- 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 = [
@azhai
azhai / python_signal_slot.py
Last active December 19, 2015 13:29
Python信号与槽
"""
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
@azhai
azhai / php_weight_rrd.php
Last active December 19, 2015 13:59
PHP权重轮询
<?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);
}
@azhai
azhai / string.php
Last active December 19, 2015 22:18
PHP字符串辅助函数
<?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);
@azhai
azhai / str2db_mysql.php
Last active December 19, 2015 22:18
MySQL字符串数据过滤
<?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()) {
@azhai
azhai / last_month_day.php
Last active December 20, 2015 01:48
找出上个月的这一天,没有这一天时使用月末
<?php
/**
* 找出上个月的这一天,没有这一天时使用月末
* (使用时间戳计算,避免判断跨年)
*/
function last_month_day($time)
{
$day = intval(date('d', $time)); //当月第几天
$time -= $day * 86400; //退回上月最后一天
$tail_day = intval(date('d', $time)); //上个月有多长
@azhai
azhai / php_configure.sh
Created October 19, 2013 03:51
php 5.4.21 configure
./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 \
@azhai
azhai / nginx_php_simple.conf
Created October 19, 2013 03:53
Nginx PHP (Simple)
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;
@azhai
azhai / py_stat.py
Created November 20, 2013 13:06
python stat
# -*- 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
@azhai
azhai / change_root_password.sh
Last active August 29, 2015 13:56
mysql 修改root密码
/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;