成天被别人打:
$ sed -n 139p access.log | xxd
00000000: 7b22 7469 6d65 223a 2232 3032 312d 3035 {"time":"2021-05
00000010: 2d31 3154 3031 3a34 313a 3439 2b30 383a -11T01:41:49+08:
00000020: 3030 222c 2272 656d 6f74 6522 3a22 3136 00","remote":"16
00000030: 372e 3939 2e31 3639 2e32 3035 222c 2272 7.99.169.205","r
00000040: 6571 7565 7374 223a 2239 39cc 5c75 3030 equest":"99.\u00
00000050: 3133 eb8b 55c0 218b 69c8 96a5 7532 de8e 13..U.!.i...u2..
00000060: bad5 8da0 b0d3 7c8f 6374 57f0 5c75 3030 ......|.ctW.\u00
00000070: 3030 5c75 3030 3132 3845 5c22 aed0 2b68 00\u00128E\"..+h
00000080: 85c2 56d1 725c 7530 3031 39b4 443d 42a6 ..V.r\u0019.D=B.
00000090: 67d3 72c7 9ac9 33bc 5c75 3030 3037 d371 g.r...3.\u0007.q
000000a0: c3d7 8a80 cfa9 b83e 5c75 3030 3142 e38f .......>\u001B..
000000b0: 59d5 7692 6c88 aa5c 7530 3031 3183 5c75 Y.v.l..\u0011.\u
000000c0: 3030 3045 8d2e bc39 b1c9 f63b 84b5 5d9c 000E...9...;..].
000000d0: 5c75 3030 3032 6c5c 7530 3031 414d c828 \u0002l\u001AM.(
000000e0: 46bf 8370 345c 6238 7fcf b6fb a4f7 6bb7 F..p4\b8......k.
000000f0: dfd2 d278 7d73 dc5d 51e7 5296 769d 202a ...x}s.]Q.R.v. *
00000100: 475f 9fc8 5c75 3030 3136 805c 7530 3030 G_..\u0016.\u000
00000110: 346a 7490 d9ab 288d f7af d7d7 e44d 775c 4jt...(......Mw\
00000120: 7530 3030 306c c736 28a2 62ca f97c 4f5d u0000l.6(.b..|O]
00000130: f25c 225c 7530 3030 345c 7530 3030 30f8 .\"\u0004\u0000.
00000140: 23a3 665c 7466 db51 36d5 7ad3 bcda 5c75 #.f\tf.Q6.z...\u
00000150: 3030 3141 2b77 eae7 a45c 7530 3030 42e7 001A+w...\u000B.
00000160: d780 32d4 41ea d0d2 b435 e78f 92d5 b54e ..2.A....5.....N
00000170: d8cc affd 4c3a 4bb8 5c75 3030 3030 5c75 ....L:K.\u0000\u
00000180: 3030 3042 30ed 9db8 e89d 5c75 3030 3133 000B0.....\u0013
00000190: 97b4 e920 482d d959 f9b4 9bdc b35c 6298 ... H-.Y.....\b.
000001a0: a49e d599 8eb5 f7cd 9389 b3bf 3591 9b52 ............5..R
000001b0: 523f 222c 2273 7461 7475 7322 3a22 3430 R?","status":"40
000001c0: 3022 2c22 686f 7374 223a 2222 2c22 7365 0","host":"","se
000001d0: 6e74 223a 2231 3530 222c 2272 6566 6572 nt":"150","refer
000001e0: 6572 223a 2222 2c22 7573 6572 5f61 6765 er":"","user_age
000001f0: 6e74 223a 2222 7d0a nt":""}.
readpe 支持 x64 了
#define DUMP_SECTIONS() do{ \
printf("ImageBase:\t" READPE_PTR_FMT "\n", ((READEPE_NT_HEADERS*)nt_header)->OptionalHeader.ImageBase); \
printf("StackCommit:\t" READPE_PTR_FMT "\n", ((READEPE_NT_HEADERS*)nt_header)->OptionalHeader.SizeOfStackCommit); \
\
puts(""); \
\
puts("Sections\n============"); \
IMAGE_SECTION_HEADER* section = (IMAGE_SECTION_HEADER*)xmalloc(sizeof(IMAGE_SECTION_HEADER)); \
fseek(file, dos_header->e_lfanew, SEEK_SET); \
fseek(file, (size_t)IMAGE_FIRST_SECTION(((READEPE_NT_HEADERS*)nt_header)) - (size_t)nt_header, SEEK_CUR); \
fread(section, sizeof(IMAGE_SECTION_HEADER), 1, file); \
puts("## Name FLAGS virtaddr[ size ] fileaddr[ size ]"); \
puts("------------------------------------------------------------------"); \
for (int i = 0; i < ((READEPE_NT_HEADERS*)nt_header)->FileHeader.NumberOfSections; ++i) \
{ \
printf("%02d %8.8s\t%5s\t" READPE_PTR_FMT "[" "%08lx" "]\t" "%08lx" "[" "%08lx" "]\n", \
i, \
section->Name, \
get_section_flags(section->Characteristics), \
section->VirtualAddress + ((READEPE_NT_HEADERS*)nt_header)->OptionalHeader.ImageBase, \
section->Misc.VirtualSize, \
section->PointerToRawData, \
section->SizeOfRawData); \
\
fread(section, sizeof(IMAGE_SECTION_HEADER), 1, file); \
} \
free(section); \
}while(0)
Boost for CMake
cmake_minimum_required(VERSION 3.7)
project(boost-playground)
set(CMAKE_CXX_STANDARD 11)
# Boost
set(BOOST_ROOT E:/opensource/boost_1_75_0)
find_package(Boost)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
link_libraries(${Boost_LIBRARIES})
message(STATUS "[Boost] version: ${Boost_LIB_VERSION}")
message(STATUS "[Boost] include: ${Boost_INCLUDE_DIRS}")
message(STATUS "[Boost] library: ${Boost_LIBRARY_DIRS}")
message(STATUS "[Boost] library: ${Boost_LIBRARIES}")
message(STATUS "All target links: ${Boost_LIBRARIES}")
else()
message(ERROR "Boost notfound")
endif()
# Playgrounds
add_subdirectory(playground)
response.css
怎么实现的今天喝水多,头脑比较清醒,从官网的例子里看到了这个:
import scrapy
class BlogSpider(scrapy.Spider):
name = 'blogspider'
start_urls = ['https://www.zyte.com/blog/']
def parse(self, response):
for title in response.css('.oxy-post-title'):
yield {'title': title.css('::text').get()}
for next_page in response.css('a.next'):
yield response.follow(next_page, self.parse)
其中 response.css
不禁让我感叹,我要是早点知道这玩意能这么搞,我还html5lib.parse
个锤子。
经过一番我已经记不起来的搜索,从 response
和 css
关键字,用 github 在仓库内搜索便可以找到这里:
def css(self, *a, **kw):
"""Shortcut method implemented onlyby responses whose content
is text (subclasses of TextResponse).
"""
raise NotSupported("Response contentisn't text")
同一个文件夹下有一个 text.py
可以找到这里:
def css(self, query):
return self.selector.css(query)
同一个类中,找到 selector 的实现:
@property
def selector(self):
from scrapy.selector import Selector
if self._cached_selector is None:
self._cached_selector = Selector(self)
return self._cached_selector
从 from...import
语句可以看出该进入包 scrapy.selector:
from scrapy.selector.unified import Selector, SelectorList
找到 Selector
类的定义:
class Selector(_ParselSelector, object_ref):
然后去找 _ParselSelector
类就可以看到这个:
from parsel import Selector as _ParselSelector
就能确定转发给了软件包parsel。
进一步还能确定parsel进一步转发了cssselect。
scrapy -> parsel -> cssselect
大致思路是css选择器转换为xpath再交给lxml跑。
不知道隔了多久,重新读了一下自己的代码
二义性验证器(雾)
"""简单文法推导 & 二义性检查器
文法:
S -> iS | M
M -> iMeS | O
-----
记号:
S = statement, M = matched_statement, O = other
i = if, e = else
"""
import copy
class Obj:
"""储存推导路径的定制对象
Attributes:
value: 当前值
path: 推导路径
"""
def __init__(self, init):
self.value = init # 当前值
self.path = [] # 推导路径
self.path.append(init)
def push(self, ns):
"""推导
指定推导并加入推导路径
Args:
ns: 新推导出的短语
"""
self.value = ns
self.path.append(ns)
def __repr__(self):
return self.value
# 重载相等性判断
def __hash__(self):
return hash(self.value)
def __eq__(self, other):
return self.value == other.value
# 推导用到的结构
cur = [Obj('S')] # 当前值 | 初始值
nxt = [] # 被推导出的临时值
# 所有推导结果
# 用来检查二义性
ahs = set()
ahl = []
# 检查二义性检查有效
assert(Obj('SS') == Obj('SS'))
assert(Obj('SS') != Obj('SSb'))
def cfind(s : str):
"""查找文法变量(非终结符)
"""
spos = s.find('S')
mpos = s.find('M')
if spos == -1 and mpos == -1:
return 'O'
if spos == -1:
return 'M'
if mpos == -1:
return 'S'
if spos < mpos:
return 'S'
else:
return 'M'
# main -------------------------------------------------------------------------
for i in range(100):
# 推导
for mem in cur:
svar = cfind(mem.value)
if svar == 'S':
# 1
prod1 = copy.deepcopy(mem)
prod1.push(prod1.value.replace('S', 'iS', 1))
nxt.append(prod1)
# 2
prod2 = copy.deepcopy(mem)
prod2.push(prod2.value.replace('S', 'M', 1))
nxt.append(prod2)
elif svar == 'M':
# 1
prod1 = copy.deepcopy(mem)
prod1.push(prod1.value.replace('M', 'iMeS', 1))
nxt.append(prod1)
# 2
prod2 = copy.deepcopy(mem)
prod2.push(prod2.value.replace('M', 'O', 1))
nxt.append(prod2)
ahl.extend(nxt) # 推导出的 nxt 加入 all history list
# 查找二义性冲突 并更新 set
for nmem in nxt:
# 在 all history set 中查找相同的推导结果
# 如果找到二义结果才执行整个 if
if nmem in ahs:
# 在 ahl 里找所有重复推出的短语
# NOFIXME: 是不是应该先找在把 nxt 加入 ahl,不然如果列表顺序乱了不就输出两个一毛一样的
# FIXNMB: 这里是打印所有的重复项
for s in ahl:
if s == nmem:
print(s.path) # 打印重复项
ahs.add(nmem)
# 交互式控制一轮轮推导
print(i+1)
input('next>')
cur = nxt
nxt = []
所以说搞标签化不是蠢就是坏,还能又蠢又坏
https://hello.2heng.xin/@line/106186064069280006
无聊之fuzz spec:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main()
{
int a;
int b;
for(unsigned long long count = 0; count < ULLONG_MAX; ++count)
{
a = rand();
b = min(1, rand()); // b 不能是 0
printf("\rcheck for %llu random number", count);
// printf("%d %d\n", a, b);
if( ( (a/b) * b + a % b ) != a )
printf("\nunequal for {a = %d, b = %d}\n", a, b);
}
return 0;
}
至今无一例外
(a/b)*b+a%b shall equal to a
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int a;
int b;
if (argc < 3)
exit(1);
// atoi(str) equal to (int)strtol(str, NULL, 10)
a = (int)strtol(argv[1], NULL, 10);
b = (int)strtol(argv[2], NULL, 10);
printf("a = %d ; b = %d\n", a, b);
printf("a/b = %d ; a %% b = %d\n", a/b, a%b);
printf("(a/b)*b+a%%b = %d\n", (a/b)*b+a%b);
return 0;
}
> a -500 -91
a = -500 ; b = -91
a/b = 5 ; a % b = -45
(a/b)*b+a%b = -500
#学校那些事 我比较后悔的事情就是跟同学说我会计算机。我还算运气好的,我们老师大多得知后给我提供机会,建议我去参加比赛。而我的网友就没那么好的运气了,他被偏见所折磨。比如周围人会认为他有关计算机的一切都会,再比如校领导想白嫖他,而且任务量不可思议。
莉特雅 literal
写代码业余爱好者 amateur coder