View pdf_to_txt.py
#!/usr/bin/python3 | |
import sys | |
from PDFNetPython3 import * | |
def main(): | |
if len(sys.argv) < 3: | |
print("Usage: python3 pdf_to_txt.py path_to_pdf path_to_txt") | |
return |
View utf8_to_unicode.py
import sys | |
def ch2int(ch): | |
if '0' <= ch <= '9': | |
return ord(ch) - ord('0') | |
if 'a' <= ch <= 'f': | |
return ord(ch) - ord('a') + 10 | |
if 'A' <= ch <= 'F': | |
return ord(ch) - ord('A') + 10 |
View visual_studio_projects_dependency.py
import re | |
import os | |
import sys | |
def vba_vso_name(text): | |
ans = text.replace(' ', '_').replace('.', '_') | |
assert re.compile(r'^\w*$').match(ans) | |
return ans | |
def generate_VBA(d_dir_dep): |
View simple_tklb.py
def simple_tklb(fn_get_list, fn_double_click_item): | |
from tkinter import Tk, Listbox | |
tk = Tk() | |
lb = Listbox(tk) | |
for idx, item in enumerate(fn_get_list()): | |
lb.insert(idx, item) | |
def onselect(event): |
View var_arg_func_ptr_demo.cpp
#include <stdio.h> | |
#include <stdarg.h> | |
typedef void (*f_type)(int, ...); | |
void foo1(int n1) { printf("%d\n", n1); } | |
void foo2(int n1, int n2) { printf("%d %d\n", n1, n2); } | |
void foo3(int n1, int n2, int n3) { printf("%d %d %d\n", n1, n2, n3); } | |
void bar(f_type pf, ...) { | |
if ((void *)pf == (void *)foo1) { |
View memleak.cpp
/** | |
* Here is an example of mem leak I met today. I didn't write the codes, I just help finding the memleak. | |
* Of course the real code is much more complicated, I simplify it here. | |
* | |
* To prove there is memleak, just compile and run: | |
* $ gcc a.cpp --std=c++11 -lstdc++ && ./a.out | |
* | |
* And you will see below: | |
* 4 bytes leaked. | |
* |
View 2018年刑侦科目推理试题.py
# http://news.sina.com.cn/s/wh/2018-03-02/doc-ifyrztfz6281140.shtml | |
def main(): | |
ans = [None for _ in range(10+1)] | |
def least_answered(ans): | |
vs = ans[1:] | |
vc = {v:vs.count(v) for v in vs} | |
minc = min(vc.values()) | |
for v,c in vc.items(): |
View 打印螺旋矩阵3.py
def main(n): | |
delta = [(1,0), (0,1), (-1,0), (0,-1)] | |
arr = [[0 for _ in range(n)] for _ in range(n)] | |
row,col,k,di = -1,0,1,0 | |
while k <= n*n: | |
row += delta[di][0] | |
col += delta[di][1] | |
if not 0 <= row < n or not 0 <= col < n or arr[row][col] > 0: | |
row -= delta[di][0] | |
col -= delta[di][1] |
View remove_nodes_with_val_from_linkedlist.py
class Node: | |
def __init__(self, v, n=None): | |
self.v = v | |
self.n = n | |
def do_print(head: Node): | |
t = head | |
print('=====') | |
while t is not None: | |
print(t.v) |
View palindromic_number.py
def main(a): | |
a = abs(a) | |
b = a | |
c = 0 | |
while b > 0: | |
c = c * 10 + b % 10 | |
b //= 10 | |
print(c == a) | |
if __name__ == '__main__': |
NewerOlder