Python
2013-04-17
示例
import string
import random
CHARS1 = string.ascii_letters
CHARS2 = string.ascii_letters + string.digits
def get_random_string(len=5, chars=None):
if not chars:
chars = CHARS1
return ''.join(random.choice(chars) for _ in range(len))
# python3
def get_random_bytes(len=5):
return bytes(bytearray((random.randrange(256) for _ in range(len))))
# python2
def get_random_bytes(len=5):
return ''.join(chr(random.randrange(256)) for _ in range(len))
其他 随机字节的方法:
import Cryptodome.Random
Cryptodome.Random.get_random_bytes(size)
In [15]: os.getrandom
Out[15]: <function posix.getrandom(size, flags=0)>
In [17]: os.urandom
Out[17]: <function posix.urandom(size, /)>
开发者
2013-04-13
计算机的本科教育主要是不变的政治、英语、数学,加上计算机专业课。
- 政治
- 英语、专业英语
- 数学
- 高等数学(微积分)
- 离散数学
- 线性代数
- 概率论与数理统计
- 计算机专业课
- 电气方面
- 大学物理
- 模拟电路
- 数字逻辑(数字电路与逻辑设计)
- 信号处理原理
- 系统分析与控制
- 硬件方面
- 计算机组成原理
- 计算机体系结构
- 微机原理与接口技术
- 汇编语言
- 理论课程
- 操作系统
- 计算机网络
- 数据结构与算法
- 数据库系统原理
- 编译原理 / 形式语言 / 自动机 / 程序语言理论
- 软件工程
- 编程语言
- 一些杂七杂八的课程(更细致的发展方向)
- 多媒体技术
- 相关法律法规
- Linux 驱动开发
- 人工智能 / 机器学习 / 自然语言处理
- 云计算
- 分布式系统
- 图形学
- 机器人工程
- SQL Server
- 计算机安全
- 计算机视觉(CV)
- 软件测试
PS:我觉得比较重要的五门理论课程加粗了。
参考资料与拓展阅读
Linux
2013-04-07
## list, sort by name
# display mtime (默认)
ls -l
# display ctime
ls -lc
ls -l --time=ctime # OR status
# display atime
ls -lu
ls -l --time=atime # OR access, use
# display birth time
ls -l --time=birth # OR creation
## list, sort by time
# sort by mtime
ls -lt
ls -lt --time=mtime
# sort by ctime
ls -ltc
ls -lt --time=ctime
# sort by atime
ls -ltu
ls -lt --time=atime
# sort by birth time
ls -lt --time=birth
助记:
-l # list, sort by name
-t # sort by time
-c # use ctime
-u # use atime
--time=ctime/atime/birth
# 默认时间是 mtime
小实验
# cat /tmp/test.sh
set -xe
rm -f /tmp/a.log
date +%T
touch /tmp/a.log # brtime, birth time
sleep 1
date +%T
echo "hello world" > /tmp/a.log # mtime, modify time
sleep 1
date +%T
cat /tmp/a.log # atime, access time
sleep 1
date +%T
chmod 666 /tmp/a.log # ctime, change time
sleep 1
# date +%T
# echo "nihao" >> /tmp/a.log # mtime, modify time
# sleep 1
stat /tmp/a.log
PS: 修改内容的时候也会更改 ctime
Python PythonNotes
2013-04-03
声明
a = set() # ps: {} 表示空字典
b = set([1, 2, 3])
c = {1, 2, 3}
方法清单
.add(x) 添加元素
.clear() 清空集合
-
.copy() 复制集合
-
.difference() 返回两个集合的差集
-
.difference_update() 在主集合中只移除交集部分
-
.discard() 删除集合中的元素
-
.intersection() 返回两个集合的交集
-
.intersection_update() 在主集合中只保留交集部分
-
.isdisjoint() 判断两个集合是否没有公共元素
.issubset() 判断一个集合是否是另一个集合的子集
.issuperset() 判断一个集合是否是另一个集合的超集
.pop() 删除并返回一个随机元素
-
.remove() 删除集合中的元素
-
.symmetric_difference() 返回两个集合的对称差集,即排除所有重复元素之后的合集
-
.symmetric_difference_update() 在主集合中加入其他集合中的元素,然后移除交集部分
-
.union() 返回两个集合的并集
.update() 在一个集合中添加另一个集合中的元素
PHP
2013-02-21
FPM 就是 PHP FastCGI Process Manager 的简称。
历史
最传统的方式是通过 Apache mod_php 模块提供服务,将 PHP 解释器内嵌到 Apache 进程内部。
另一条路就是通过 CGI/FastCGI。演化路线:php cgi -> php fastcgi -> php fpm
CGI (公共网关接口) 是一个非常简单的协议,每次来一个请求,CGI 就启动一个 PHP 进程,请求处理完成之后就退出进程。
PS: PHP 内置 CGI 支持(php-cgi)。
PS:php-cgi 也可以常驻内存,作为 FastCGI Worker 运行。
CGI 需要反复启动退出进程(解析配置文件,配置环境变量,加载拓展...),这个性能开销就非常大了,所以 CGI 很快被 FastCGI 所替代。
FastCGI 则是通过 CGI 进程常驻的方式提供服务,Web 服务器通过 FastCGI 协议将请求发给主进程 (master), 主进程又将请求分发给子进程(worker)进行处理。
这样的话性能得到的很大的改进。而且可以和数据库之间保持连接,进一步节省时间提高效率。
之前是使用 Apache 的 FastCGI 拓展模块 mod_fastcgi、mod_fcgid 来弄,这个模块是起到 CGI 进程管理的作用。
有人开发了 Spawn-FCGI(来自 lighttpd 项目,通用 FastCGI 管理)、PHP-FPM (作为 PHP 的补丁开发) 来提供 CGI 进程管理,将管理权从 Apache 拿过来,其中 FPM 和 PHP 结合更好,性能更胜一筹,后来被并入 PHP (从 5.4 开始)。
https://php-fpm.org/
https://www.php.net/manual/en/install.fpm.php
Apache + mod_proxy_fcgi + php-fpm
http://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html
加载 mod_proxy_fcgi 模块
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
SetHandler
<FilesMatch "\.php$">
# Note: The only part that varies is /path/to/app.sock
SetHandler "proxy:unix:/path/to/app.sock|fcgi://localhost/"
</FilesMatch>
<FilesMatch ...>
SetHandler "proxy:fcgi://localhost:9000"
</FilesMatch>
<Proxy "balancer://myappcluster/">
BalancerMember "fcgi://localhost:4000"
BalancerMember "fcgi://localhost:4001"
</Proxy>
<FilesMatch ...>
SetHandler "proxy:balancer://myappcluster/"
</FilesMatch>
ProxyPass
ProxyPass "/myapp/" "fcgi://localhost:4000/"
ProxyPass "/myapp/" "fcgi://localhost:4000/" enablereuse=on
ProxyPass "/myapp/" "balancer://myappcluster/"
ProxyPassMatch
ProxyPassMatch "^/myapp/.*\.php(/.*)?$" "fcgi://localhost:9000/var/www/" enablereuse=on
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php5-fpm.sock|fcgi://localhost/var/www/"
Nginx + php-fpm
Nginx 中的 fastcgi_pass 可以指定 FastCGI 进程,比如:fastcgi_pass 192.168.64.234:9000。
WebDev 字符编码
2013-02-02
Content-Type: text/html; charset=ISO-8859-4 HTTP 头部
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- HTML5:
<meta charset="utf-8">
<?xml version="1.0" encoding="ISO-8859-1"?> XHTML 可以才用 XML 声明来定义编码
个人
2013-01-01

- 个人领域的成功:从依赖到独立
- 习惯一 积极主动 —— 个人愿景原则
- 习惯二 以终为始 —— 自我领导原则
- 习惯三 要事第一 —— 自我管理原则
- 公众领域的成功:从独立到互赖
- 习惯四 双赢思维 —— 人际领导原则
- 习惯五 知己知彼 —— 同理心沟通原则
- 习惯六 统合综效 —— 创造性合作原则
- 自我提升和完善
b2a
2012-03-07
按二进制位来算:
- Base16 四位
- Base32 五位
- Base64 六位
不按二进制位来算:
- Base36 数字 + 字母
- Base62 数字 + 字母(大小写敏感)
- Base58 数字 + 字母(大小写敏感),然后排除
0OIi 4 个字符
- Base85 有多种方案
b2a
2012-03-07

b2a
2012-03-07
