Skip to content

Instantly share code, notes, and snippets.

View AntiKnot's full-sized avatar
🎯
Focusing

Yan.xxx AntiKnot

🎯
Focusing
View GitHub Profile
@AntiKnot
AntiKnot / pdfminer_demo.py
Created October 15, 2019 02:45
pdfminer demo
import re
from pdfminer.pdfparser import PDFParser, PDFDocument
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import PDFPageAggregator
from pdfminer.layout import LAParams, LTTextBox
from pdfminer.pdfinterp import PDFTextExtractionNotAllowed
path = "xxx.pdf"
# 用文件对象来创建一个pdf文档分析器
import abc
class Animal(metaclass=abc.ABCMeta):
@abc.abstractmethod
def screaming(self):
'Return when animal screaming the sound hear likes'
return NotImplemented
@AntiKnot
AntiKnot / mysort_compare.py
Created February 27, 2020 16:19
Python sort list by function with two arguments
import functools
from typing import List
class Solution(object):
def largest_nums(self, nums: List[int]) -> str:
snums = [str(item) for item in nums]
snums.sort(key=functools.cmp_to_key(self.cmp), reverse=True)
_res = ""
for i in snums:
@AntiKnot
AntiKnot / ten2n.py
Created April 2, 2020 04:56
十进制转任意进制
code = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd']
# todo unicode 可以简化这个书写 62个[0-9,a-z,A-Z] 乱序可以制作一个混淆 算是加密算法
def ten2n(x, n):
b = []
while True:
j = x // n
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 04:58
update dict in loop
from copy import deepcopy
d1 = {1: 1, 2: 2}
def change_dict_in_loop():
d_copy = deepcopy(d1)
for k, v in d1.items():
d_copy.pop(1, None)
return d_copy
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 05:03
matlibplotlib.pyplot demo
import decimal
import time
from functools import reduce
import matplotlib.pyplot as plt
import random
# generate scale number
def scale_random_number(scale):
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 05:24
get excel colums name;获取excel 工作簿 列名
import openpyxl
if __name__ == '__main__':
wb = openpyxl.load_workbook('xxxx.xls')
sheet = wb.get_sheet_by_name('审计报告')
names = [cell.value for cell in sheet[0]]
print(names)
@AntiKnot
AntiKnot / bcrypt.py
Created April 2, 2020 05:25
bcrypt demo; 使用bcryptj加密和验证
import bcrypt
def get_hashed_password(plain_text_password):
return bcrypt.hashpw(plain_text_password, bcrypt.gensalt())
def check_password(plain_text_password, hashed_password):
return bcrypt.checkpw(plain_text_password, hashed_password)
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 05:26
inset sort; 插入排序
import random
from typing import List
test_case = [2, 1, 3, 8, 0]
def insert_sort(l: List[int]) -> List[int]:
if l is []:
return []
length = len(l)
@AntiKnot
AntiKnot / shape.py
Created April 2, 2020 05:27
km-touch
shape = lambda n, m, default: [[default for _ in range(n)] for _ in range(m)]
a = shape(2, 3, 0)
print(a)
a[0][1] = 2
print(a)
"""
[[0, 0], [0, 0], [0, 0]]
[[0, 2], [0, 0], [0, 0]]