Skip to content

Instantly share code, notes, and snippets.

@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
------------
@linnil1
linnil1 / calculator.py
Created February 14, 2023 07:37
Calculator made by python
from typing import Any, Iterable
from operator import add, sub, mul, truediv, neg
op_func: dict[str, Any] = {"+": add, "-": sub, "*": mul, "/": truediv, "**": pow, "--": neg}
op_param: dict[str, int] = {"+": 2, "-": 2, "*": 2, "/": 2, "**": 2, "--": 1}
priority: dict[str, int] = {"+": 0, "-": 0, "*": 2, "/": 2, "**": 5, "--": 4}
op_set = ["**", "*", "+", "-", "/", "(", ")"]
num_set = "0123456789."
@linnil1
linnil1 / Dockerfile
Created December 5, 2022 09:37
Dockerfile for hla-la version 1.0.3 built in alpine for fun. Inspired by https://github.com/zlskidmore/docker-hla-la
FROM alpine
WORKDIR /usr/local/bin
# samtools
ENV samtools_version 1.16.1
RUN apk add g++ make ncurses-dev zlib-dev xz-dev bzip2-dev curl-dev
RUN wget https://github.com/samtools/samtools/releases/download/${samtools_version}/samtools-${samtools_version}.tar.bz2 && \
tar -xjf samtools-${samtools_version}.tar.bz2 && \
cd samtools-${samtools_version}/ && \
./configure && \