Skip to content

Instantly share code, notes, and snippets.

View oshinko's full-sized avatar

Shintaro Maeda oshinko

View GitHub Profile
@oshinko
oshinko / glassworm-codec.js
Last active March 21, 2026 04:10
GlassWorm Codec
// 実行環境に応じて UTF-8 バイト列へ変換
const encodeUtf8 = str =>
typeof Buffer !== 'undefined' ?
Buffer.from(str, 'utf-8') :
new TextEncoder().encode(str);
// 実行環境に応じて UTF-8 バイト列を文字列へ戻す
const decodeUtf8 = bytes =>
typeof Buffer !== 'undefined' ?
Buffer.from(bytes).toString('utf-8') :
@oshinko
oshinko / glassworm-demo.js
Last active March 21, 2026 03:57
GlassWorm Demo
// https://www.aikido.dev/blog/glassworm-returns-unicode-attack-github-npm-vscode
const s = v => [...v].map(w => (
w = w.codePointAt(0),
0xFE00 <= w && w <= 0xFE0F ? w - 0xFE00 :
0xE0100 <= w && w <= 0xE01EF ? w - 0xE0100 + 16 : null
)).filter(n => n !== null);
const d = v => typeof Buffer !== 'undefined' ?
Buffer.from(s(v)).toString('utf-8') :
new TextDecoder().decode(Uint8Array.from(s(v)));
@oshinko
oshinko / sort-tasks.gs
Last active March 15, 2024 08:11
For the ToDo list of Google Spreadsheet
function sort() {
const TARGET_SHEETS = ['全て']
const sheet = SpreadsheetApp.getActiveSheet()
if (!TARGET_SHEETS.includes(sheet.getName()))
return
const [_, targetColumn] = sheet
.getRange(1, 1, 1, sheet.getMaxColumns())
@oshinko
oshinko / boolify.py
Last active November 10, 2025 03:37
Convert to Boolean
def boolify(value: object) -> bool:
"""
Convert to bool.
>>> falsy = None, False, 0, b'', '', '0', 'false', 'off'
>>> truthy = True, 1, b'\\0', '1', 'true', 'on', 'A'
>>> any(boolify(x) for x in falsy)
False
>>> all(boolify(x) for x in truthy)
True
@oshinko
oshinko / hash-date.js
Last active April 13, 2022 02:42
Hash the date
d = new Date()
s = [d.getFullYear(), d.getMonth() + 1, d.getDate()].join('/')
(async function(text, n) {
data = new TextEncoder().encode(text)
hash = await window.crypto.subtle.digest('SHA-1', data)
uint = new DataView(hash, 0).getUint32()
console.log(text, uint % n)
})(s, 10)
@oshinko
oshinko / img2mp4.py
Last active April 2, 2022 13:12
Convert images to mp4
import pathlib
import subprocess
try:
import cv2
except ModuleNotFoundError:
import sys
subprocess.run(f'{sys.executable} -m pip install opencv-python',
shell=True)
import cv2
@oshinko
oshinko / docker-linux.sh
Last active March 15, 2022 02:21
Run the Linux sandbox container
docker run --rm -it debian:latest /bin/bash
@oshinko
oshinko / docker-mysql-login-via-host.sh
Last active March 31, 2022 09:02
Run the MySQL sandbox container
docker run --rm -it mysql mysql -h host.docker.internal -u root -p --default-character-set=utf8 test
@oshinko
oshinko / nt.bat
Last active April 12, 2022 00:25
Open a new tab in Windows Terminal
wt -w 0 nt -d %cd%\%1
@oshinko
oshinko / dirname.mjs
Created December 19, 2021 04:19
Alternative to __dirname when using ESM
import path from 'path'
import url from 'url'
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))