Skip to content

Instantly share code, notes, and snippets.

View oshinko's full-sized avatar

Oshinko oshinko

View GitHub Profile
@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 24, 2022 10:37
Convert to Boolean
def boolify(value):
"""
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))
@oshinko
oshinko / ssh-jump.sh
Last active November 20, 2021 05:24
SSH ProxyCommand Oneliner
ssh -o ProxyCommand='ssh -W %h:%p -i ~/.ssh/xxxx.pem user@proxy' -i ~/.ssh/xxxx.pem user@private
@oshinko
oshinko / broadcast-value-on-eddystone-on-microbit.js
Last active August 26, 2021 02:55
Broadcast the sensor value on Eddystone (BLE) on micro:bit
const NAMESPACE = [ // sha1('your.doma.in').slice(0, 10)
0x8f, 0xa3, 0xfa, 0xa1,
0xb4, 0xa3, 0x99, 0x67,
0x0c, 0x0f
]
const DEVICE = 0x0000 // 2 bytes
const POWER = 7 // no reason
const CONNECTABLE = false // no reason
// Returns depend on the role of the device