Skip to content

Instantly share code, notes, and snippets.

View curegit's full-sized avatar

curegit curegit

View GitHub Profile
@curegit
curegit / takeout-css.js
Created September 10, 2024 05:19
ページの CSS を締め出すブックマークレット
javascript: [...document.styleSheets].forEach(x => x.disabled = true)
@curegit
curegit / line-theme.js
Last active August 16, 2024 01:04
LINE Theme をダウンロードするやつ
javascript: (async function () {
function validateThemeIdFormat(id) {
return /^[-a-z0-9]{6,}$/.test(id);
}
function buildThemeZipUri(id, version, platform) {
const subdir1 = id.substring(0, 2);
const subdir2 = id.substring(2, 4);
const subdir3 = id.substring(4, 6);
const baseuri = "https://stickershop.line-scdn.net/themeshop/v1/products";
return `${baseuri}/${subdir1}/${subdir2}/${subdir3}/${id}/${version}/${platform}/theme.zip`;
@curegit
curegit / nonlocal-means-video.py
Created July 29, 2024 09:40
OpenCV で Non-local Means フィルタ(動画)
import itertools
from collections import deque
from rich.progress import track
import cv2
n = 5
process_frames = 60 * 3
cap = cv2.VideoCapture("SSX.avi")
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
@curegit
curegit / beatseg.py
Created July 23, 2024 10:28
拍の位置を考慮してトラックを断片化する
import itertools
import os
import shutil
import soundfile as sf
import librosa
import librosa.beat
import librosa.effects
beat = 4
@curegit
curegit / ssh.desktop
Last active July 1, 2024 14:19
SSH 端末を開くデスクトップショートカット
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/usr/bin/gnome-terminal -- ssh atlantica
Name=SSH
Comment=SSH
@curegit
curegit / nonlocal-means.py
Last active June 14, 2024 06:15
OpenCV で Non-local Means フィルタ
import cv2
import numpy as np
def nlmeans(i, o, h=10, hColor=10, templateWindowSize=9, searchWindowSize=27):
img = cv2.imdecode(np.frombuffer(open(i, "rb").read(), np.uint8), cv2.IMREAD_COLOR | cv2.IMREAD_ANYDEPTH)
denoised = cv2.fastNlMeansDenoisingColored(img, h=h, hColor=hColor, templateWindowSize=templateWindowSize, searchWindowSize=searchWindowSize)
ok, bin = cv2.imencode(".png", denoised, [cv2.IMWRITE_PNG_COMPRESSION, 9])
assert ok
open(o, "wb").write(bin.tobytes())
@curegit
curegit / bilateral-filter.py
Last active June 14, 2024 08:39
OpenCV でバイラテラルフィルタ
import cv2
import numpy as np
def bilateral(i, o, d=7, sigmaColor=32, sigmaSpace=10):
img = cv2.imdecode(np.frombuffer(open(i, "rb").read(), np.uint8), cv2.IMREAD_COLOR | cv2.IMREAD_ANYDEPTH)
denoised = cv2.bilateralFilter(img, d=d, sigmaColor=sigmaColor, sigmaSpace=sigmaSpace)
ok, bin = cv2.imencode(".png", denoised, [cv2.IMWRITE_PNG_COMPRESSION, 9])
assert ok
open(o, "wb").write(bin.tobytes())
@curegit
curegit / extstats.py
Last active April 1, 2024 10:24
ディレクトリツリーに存在する拡張子を集計するスクリプト
#!/usr/bin/env python3
import sys
import os
from pathlib import Path
from collections import Counter
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
@curegit
curegit / once.py
Created March 11, 2024 05:57
高々一回実行される副作用を定義するデコレータ
import functools
def once(func):
fst = True
result = None
@functools.wraps(func)
def wrapper(*args, **kwargs):
nonlocal fst, result
if fst:
@curegit
curegit / memmap.py
Created February 27, 2024 05:42
大規模配列のファイルからの部分読み出し例
import numpy as np
large_arr = np.random.normal(size=(3, 10000, 10000)).astype("float64")
np.save("example.npy", large_arr)
import time
import random
from numpy.lib.format import open_memmap