Skip to content

Instantly share code, notes, and snippets.

View mdjhny's full-sized avatar

Fanxin Yang mdjhny

View GitHub Profile
@mdjhny
mdjhny / bash-invocation.md
Created January 6, 2012 12:35 — forked from yegle/bash-invocation.md
Bash Shell启动方式与RC脚本

Bash Shell启动方式与rc脚本

Shell的不同分类

根据启动Bash Shell的方式不同,对Shell有两种分类方式

登录Shell与非登录Shell

根据Shell的启动方式不同,可以将Shell分为

@mdjhny
mdjhny / README.md
Created January 3, 2013 11:45 — forked from wong2/README.md

人人的登录改版后,采用RSA加密后传输密码,该项目用于解决这种情况下人人的模拟登录

使用前先 pip install requests

@mdjhny
mdjhny / tail.py
Last active December 14, 2015 02:19
用python实现的类似tail的程序
from mmap import mmap
def tail(fn, count=10):
with open(fn,'r+') as f:
data = mmap(f.fileno(), 0)
pos = len(data)
for _ in range(count):
pos = data.rfind('\n', 0, pos)
if pos == -1:
pos = 0
break
@mdjhny
mdjhny / .vimrc
Created February 23, 2013 14:12
vim的python配置 即使配置如此 ,Python的缩进也并不是很理想。比较好的选择是再使用一个插件 hynek/vim-python-pep8-indent。
"自动缩进
set autoindent
"类似C语言风格的缩进
set cindent
"智能缩进:每一行都和前一行有相同的缩进量,
"同时这种缩进形式能正确的识别出花括号,当遇到右花括号(}),
"则取消缩进形式。此外还增加了识别C语言关键字的功能。
"如果一行是以#开头的(比如宏),那么这种格式将会被特殊对待而不采用缩进格式
set smartindent
"For Python Programmers
@mdjhny
mdjhny / factorize.py
Last active December 14, 2015 06:48
Python分解因数
def factorize(n):
'''Adapted from http://www.math.utah.edu/~carlson/notes/python.pdf'''
if n < 2:
return '本函数仅适用于不小于2的正整数'
d = 2
factors = []
while not n % d:
factors.append(d)
n /= d
d = 3
@mdjhny
mdjhny / windows右键命令行
Last active December 16, 2015 04:29
windows系统右键命令行
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\folder\shell\cmd]
@="CMD快速通道"
[HKEY_CLASSES_ROOT\folder\shell\cmd\command]
@="cmd.exe /k cd %1"
@mdjhny
mdjhny / php.sublime-build
Created April 17, 2013 05:44
在sublime中添加php build功能
{
"cmd": ["php", "-f", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.php"
}
@mdjhny
mdjhny / sublime_xdebug调试
Created April 27, 2013 05:06
利用sublime,xdebug,chrome调试php
sudo -i
apt-get install php5-xdebug
vim /etc/php5/conf.d/xdebug.ini
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
:wq
apachectl restart
exit
@mdjhny
mdjhny / 18位身份证校验方法
Created July 24, 2013 13:26
18位身份证校验方法
18位身份证标准在国家质量技术监督局于1999年7月1日实施的GB11643-1999《公民身份号码》中做了明确规定。
GB11643-1999《公民身份号码》为GB11643-1989《社会保障号码》的修订版,其中指出将原标准名称“社会保障号码”更名为“公民身份号码”,另外GB11643-1999《公民身份号码》从实施之日起代替GB11643-1989。
公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位校验码。其含义如下:
1. 地址码:表示编码对象常住户口所在县(市、旗、区)的行政区划代码,按GB/T2260的规定执行。
2. 出生日期码:表示编码对象出生的年、月、日,按GB/T7408的规定执行,年、月、日分别用4位、2位、2位数字表示,之间不用分隔符。
3. 顺序码:表示在同一地址码所标识的区域范围内,对同年、同月、同日出生的人编定的顺序号,顺序码的奇数分配给男性,偶数分配给女性。
@mdjhny
mdjhny / 管道和输入同时作为输入的解决办法
Created August 8, 2013 09:28
管道和输入同时作为输入的解决办法
如果脚本从管道获取输入,同时需要有输入交互,可以采取以下三种措施:
http://mail.python.org/pipermail/python-list/2000-March/020133.html
* Put the data in a file and pass the name of the file to your
script, then open that file:
lines = open(sys.argv[1]).readlines()
This is probably the nicest solution, and the least prone to making
wierd things happen if your script gets run differently.