Skip to content

Instantly share code, notes, and snippets.

from collections import defaultdict
from collections.abc import Iterable
from dataclasses import dataclass
from enum import Enum
from itertools import chain
import random
class ActionType(Enum):
"""Enum for different action types"""
@linnil1
linnil1 / watermark.py
Created November 20, 2024 14:22
Decrypt + Watermark + merge + to PDF
from functools import partial
from itertools import chain
import os
def runDocker(image, command):
os.system(f"podman run -it --rm -v $PWD:/app -w /app " f"{image} {command}")
def pdfToImage(name, password):
@linnil1
linnil1 / memory_leak_by_sublist.java
Created April 17, 2024 03:35
I found java doesn't release original array after being assigned by sublist
import java.util.ArrayList;
import java.util.List;
public class SublistMemoryTest {
public static void main(String[] args) {
List<Integer> largeList = new ArrayList<>();
// Measure memory usage before creating the sublist
long beforeMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
@linnil1
linnil1 / read_excel_contains_merged_cell.py
Created February 29, 2024 14:43
Read Excel that contains merge cell
import pandas as pd
from openpyxl import load_workbook
def readExcel(filename):
excel = load_workbook(filename)
sheetname = excel.sheetnames[0]
df = pd.read_excel(filename, sheet_name=sheetname, header=None)
# print("origin:", df, sep="\n")
sheet = excel.get_sheet_by_name(sheetname)
@linnil1
linnil1 / result.txt
Last active October 10, 2023 08:15
Use GPT to summarize the SRT files and output SRT.
# https://www.youtube.com/watch?v=I3gKT1CL5Z
0:20:13 XX的設計
0:22:50 OO的設計
0:31:51 XX的設計
0:52:08 新衣裝發表
0:52:42 描述鞋底和鞋帶
0:53:50 描述大腿骨和骨頭
0:54:40 描述臉部設計包括牙齒和鼻子
0:57:42 詳細介紹外套設計和LOGO
0:58:52 獵物胸章和腰帶的設計
@linnil1
linnil1 / logstash.conf
Created September 17, 2023 06:03
logstash syslog config with support of rfc3164 and rfc5424 (using different port)
input {
syslog {
id => "syslog_rfc3164"
port => 1514
}
syslog {
id => "syslog_rfc5424"
port => 1515
grok_pattern => "%{SYSLOG5424LINE}"
tags => [ "rfc5424" ]
import sys
import time
import json
import random
import requests
from pathlib import Path
from datetime import datetime
cookie_path = "./cookie.json"
@linnil1
linnil1 / watermark.md
Created August 17, 2023 10:43
Adding Text Watermark to Images with Random Rotation using ImageMagick and Docker (Supports CJK)

Adding Text Watermark to Images with Random Rotation using ImageMagick and Docker (Supports CJK)

TL;DR

./watermark.sh input.jpg "僅供 linnil1 使用" output.jpg /OTF/TraditionalChinese/NotoSansCJKtc-Regular.otf

#!/bin/sh
podman run -it --rm \
    -v $4:/font/noto_sans_tc.otf:ro \
 -v $PWD:/app -w /app \
@linnil1
linnil1 / test.py
Created June 25, 2023 17:20
httpx is easier to use than aiohttp
import time
import uuid
import asyncio
import httpx
import aiohttp
url = "http://localhost:8080/"
@linnil1
linnil1 / 1a2b.hs
Created June 2, 2023 12:50
Excercise Haskell
-- Excercise Haskell
-- Aim: 1A2B game without import library (random excluded)
-- Author: linnil1
import System.Random (randomRIO)
import qualified Data.Map as M
------------
-- utilities
------------