Skip to content

Instantly share code, notes, and snippets.

View azhai's full-sized avatar
🪁
Focusing

azhai

🪁
Focusing
View GitHub Profile
@azhai
azhai / logrotate.sh
Created June 9, 2013 12:06
Nginx日志按日期切割
#!/bin/bash
cd /opt/nginx-1.4.0/logs/
#分解旧日志
mkdir -p mysite
gawk '{
dt=substr($4,2,11);
gsub(/\//," ",dt);
"date -d \""dt"\" +%Y%m%d"|getline dd;
print $0 >> "mysite/mysite.access.log-"dd
@azhai
azhai / nginx-wildcard
Created July 8, 2013 03:55
Nginx下PHP网站配置,使用子域名
#生效
#nginx -s reload
log_format sess '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$var_sessid"';
server {
listen 80;
@azhai
azhai / samba-simple-smb-conf
Created July 8, 2013 03:58
简化的samba配置 /etc/samba/smb.conf
#添加用户ryan,Samba不依赖于系统用户
#gpasswd -a ryan
#生效
#/etc/init.d/smbd restart
[global]
workgroup = WORKGROUP
server string = Smaba %V
hosts allow = 192.168.0.
security = user
@azhai
azhai / rsyncd-conf
Created July 8, 2013 04:03
Rsync服务端主配置/etc/rsync/rsyncd.conf
#客户端传输
#/usr/bin/rsync -vzrtopg --progress /home/ryan/apps/* \
# root@192.168.1.50::apps --password-file=/home/ryan/bin/rsync.pass
pid file = /var/run/rsyncd.pid
port = 873
address = 192.168.1.23
uid = root
gid = root
@azhai
azhai / vimrc.local
Last active December 19, 2015 11:18
我的VIm配置 ~/.vimrc
" 粘贴模式
set paste
" 设定配色方案
" colorscheme molokai
" 显示行号
set nu
" 突出显示当前行
" set cursorline
" 用浅色高亮当前行
autocmd InsertEnter * se cul
@azhai
azhai / get_mac_addr
Created July 8, 2013 06:32
Python获得物理网卡地址
# -*- coding:utf-8 -*-
#CPython
def get_mac_addr():
""" 获得本机网卡物理地址 """
import uuid
node = uuid.getnode()
mac = uuid.UUID(int=node)
addr = mac.hex[-12:]
return addr
@azhai
azhai / python_list_unique.py
Last active December 19, 2015 11:19
Python列表去重复
# -*- coding:utf-8 -*-
#用于Python List类型的去重复,并保持元素原有次序
def unique_list(seq, excludes=[]):
"""
返回包含原列表中所有元素的新列表,将重复元素去掉,并保持元素原有次序
excludes: 不希望出现在新列表中的元素们
"""
seen = set(excludes) # seen是曾经出现的元素集合
return [x for x in seq if x not in seen and not seen.add(x)]
@azhai
azhai / ip_address.py
Last active December 21, 2016 06:45
Python判断是否中国大陆IP
# -*- coding: utf-8 -*-
"""
需要存放IP段起止地址的二进制文件cnips.dat
"""
import os, os.path
from IPy import IP
def binary_search(total, callback, *args):
@azhai
azhai / ip_address.php
Last active June 14, 2016 12:09
PHP判断是否中国大陆IP
<?php
/*
需要存放IP段起止地址的二进制文件cnips.dat
*/
/**
* 二分(折半)查找算法
*/
function binary_search($total, $callback)
{
@azhai
azhai / md5.py
Last active January 3, 2023 12:58
Python计算MD5
# -*- coding: utf-8 -*-
import hashlib
def md5hex(word):
""" MD5加密算法,返回32位小写16进制符号 """
if isinstance(word, unicode):
word = word.encode("utf-8")
elif not isinstance(word, str):