Month: September 2026
>>def nexts(*iters):
>> nexts = [i for i in iters]
while nexts:
>> t = nexts
try:
>> for n, i in enumerate(t):
if iter(i):
yield n
>> except:
>> t = next[:n] + next[n+1:]
nexts = t
>>for i in nexts([[1,1],[2,2],3]):
pass
Grsecurity 的用户组加固
Grsecurity提供了基于GID,UID的执行控制(TPE)和网络控制,可以让指定用户组的用户无法执行非root所有的可执行文件,或者禁止建立监听端口或者出站连接等,可以加固服务器,防止漏洞被利用。
我是这样使用的,如果有更好的方法或者哪里不妥的话欢迎拍砖讨论。
UID是在内核中设置好的,根据内核config来建立用户组:
groupadd -g 65532 tpe groupadd -g 65531 nonet groupadd -g 65530 noclient groupadd -g 65529 noserver useradd -g tpe -s /sbin/nologin -u 65532 tpe useradd -g nonet -s /sbin/nologin -u 65531 nonet useradd -g noclient -s /sbin/nologin -u 65531 noclient useradd -g noclient -s /sbin/nologin -u 65530 noclient useradd -g noserver -s /sbin/nologin -u 65529 noserver useradd -g nonet -s /sbin/nologin -u 65528 nonet-tpe useradd -g noclient -s /sbin/nologin -u 65527 noclient-tpe useradd -g noserver -s /sbin/nologin -u 65526 noserver-tpe usermod -a -G tpe noclient-tpe usermod -a -G tpe noserver-tpe usermod -a -G tpe nonet-tpe
让特定程序以特定身份运行,比如php的用户名就叫php:
详解 Unix user 与 group
使用 Javascript 完成 Lisp 解释器
微信公众号的运营
尝试微信小程序
Scheme 的奇妙表示
前段时间读 《SICP》 的时候被 lambda 重新定义的皮亚诺公理惊艳到了。
lambda表示皮亚诺公理:
最早接触数学归纳法大概i是在初中时,那时并不懂得什么叫数学,什么叫归纳,感觉这个方法的使用和命名都颇为莫名其妙。
归纳,是通过根据已有的,通过观察的来的规律,总结出一个通用规则。数学归纳,就是用严格的
推演,证明
让一个推测可被证明。
lambda表示数学归纳法:
数学归纳法和递归颇为相似。我们对第n个命题求结果,有数学归纳法的定义这个取决于n-1个命题(n-1成立时,n成立),一层层直到第一个命题,也就是n=1时命题成立。此处为尾递归。
通过归纳之后,我们不仅
lambda:
归纳法相比直接通过工程学方法去证明在直观感受上更加不直观,颇有种“流氓有文化“的感觉。工程学所带来的”直观感受”有是如何得来的?(比如?)
其实工程学的任何推导都是归纳的一部分,lambda层层“递归“最终可以实现任何计算模型可实现的功能。递归的最底层只有三条命题。
数学,数字是从现实中抽象化得来,随着发展,很多数学概念很难直接推演到。
Python 中字符串和 Bytes 的 Resize
今天尝试实现一个自带时间戳的str,需要 override += 操作符。
最初的实现:
def __iadd__(self, other):
self.__timestamps__.append((len(self), datetime.datetime.now()))
string = str(self)
string += other
return TimestampedStr.__scopy__(self.__timestamps__, string)
经过自己测试发现性能非常慢,消耗时间是原生str的100倍左右,进一步研究发现 Python 在 str 引用数为 1 的时候,确认其他对象不再使用之前的 str 的话会不销毁之前的 str 对象,直接在“原地”进行 resize ,提高性能。在 Cpython/Objects/bytesobject.c PyBytes_Concat 函数中有这行判断语句。
if (Py_REFCNT(*pv) == 1 && PyBytes_CheckExact(*pv))
其中 pv 是应该是指向实际存放字符内容的缓存,并不是Python str Object,
Monkey Patch Python’s socket
由于(你懂的)的原因,国内访问谷歌