Skip to content

Instantly share code, notes, and snippets.

@xiaopc
xiaopc / clear_pdf_text.py
Last active January 29, 2023 03:36
remove all text on pdf
# Modify from https://gist.github.com/668/2c8f936697ded94394ff4a6ffa4ae87e
import sys
from pypdf import PdfReader, PdfWriter
from pypdf.generic import ContentStream, TextStringObject, NameObject
# Load PDF into PyPDF2
reader = PdfReader(open(sys.argv[1], "rb"))
writer = PdfWriter()
@xiaopc
xiaopc / gaWorker.js
Last active October 25, 2023 14:50
Google Analytics 4 Proxy with Cloudflare Workers
// 2023.4.23 更新,修复 gtag.js 加了个回车导致失效的问题
// 2023.3.2 更新,修复上报到 region*.google-analytics.com 未被代理的问题
addEventListener('fetch', (event) => {
// 这里可以加 filter
return event.respondWith(handleRequest(event));
});
// worker 应用的路由地址,末尾不加 '/'
const DOMAIN = 'https://example.workers.dev/routerpath';
const assert = require('assert');
const assign = require('object-assign');
const htmlWebpackPlugin = require('html-webpack-plugin');
const htmlTags = require('html-webpack-plugin/lib/html-tags');
const createHtmlTag = htmlTags.createHtmlTagObject, htmlTagToString = htmlTags.htmlTagObjectToString;
const isStylesheetLink = (def) => def.tagName === 'link' && def.attributes.rel === 'stylesheet' && def.attributes.href;
const addMediaAttribute = (tag) => {
tag.attributes.media = 'print';
@xiaopc
xiaopc / draw_table.py
Last active April 23, 2024 10:21
Draw a table using only Pillow
from PIL import Image, ImageFont, ImageDraw
from collections import namedtuple
def position_tuple(*args):
Position = namedtuple('Position', ['top', 'right', 'bottom', 'left'])
if len(args) == 0:
return Position(0, 0, 0, 0)
elif len(args) == 1:
return Position(args[0], args[0], args[0], args[0])