Skip to content

Instantly share code, notes, and snippets.

View iso2022jp's full-sized avatar
🌌
Working in the metaverse

USHIDO Hiroyuki iso2022jp

🌌
Working in the metaverse
View GitHub Profile
@iso2022jp
iso2022jp / ExcelWriter.php
Created December 4, 2020 03:49
ZipArchive 依存の単一シート Excel 出力
<?php
declare(strict_types=1);
namespace Damn\IO;
use ZipArchive;
class ExcelWriter
{
@iso2022jp
iso2022jp / encodeWindows31J.js
Created December 15, 2020 10:36
TextDecoder を使って無理矢理 Windows-31J の Encoder を作る
const encodeWindows31J = text => {
const range = (from, to) => [...Array(to - from + 1).keys()].map(b => b + from)
const islead = b => (b >= 0x81 && b <= 0x9F) || (b >= 0xe0 && b <= 0xef)
const follows = [...range(0x40, 0x7e), ...range(0x80, 0xfc)]
const decoder = new TextDecoder('Windows-31J')
const sbmap = b => ({ [decoder.decode(new Uint8Array([b]))]: [b] })
const dbmap = l => follows.reduce((mapping, f) => ({ ...mapping, [decoder.decode(new Uint8Array([l, f]))]: [l, f] }), {})
@iso2022jp
iso2022jp / body-pix-injector.js
Last active July 20, 2021 03:43
BodyPix を getUserMedia に注入してみる
'use strict'
;(async () => {
const handleSelectImage = (input, select) => {
input.addEventListener('change', e => {
const files = [...input.files]
const image = files.filter(f => f.type.startsWith('image/'))
if (image.length) {
const file = image[0]
@iso2022jp
iso2022jp / vlw-viewer.html
Created May 15, 2021 11:30
VLW font viewer
<!doctype html>
<html class="h-100">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>VLW viewer</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/mustache.min.js"></script>
@iso2022jp
iso2022jp / wifi-selector.ino
Created May 29, 2021 16:18
M5Stack Core2 で Wi-Fi に接続する GUI(入力辛い系)
#include <M5Core2.h>
#include <WiFi.h>
//--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2
void selectWiFi(String &ssid, uint8_t &encType, int32_t &rssi, uint8_t* &bssid, int32_t &channel) {
auto& d = M5.Lcd;
d.fillScreen(BLACK);
@iso2022jp
iso2022jp / ble-scan-example.ino
Last active April 2, 2022 03:32
M5Stack Basic/Gray/Core2 BLE Active Scan sample
#ifndef ARDUINO_M5STACK_Core2
#include <M5Stack.h>
#else
#include <M5Core2.h>
#endif
#include <utility/M5Timer.h>
#include <esp_bt.h>
#include <esp_bt_main.h>
@iso2022jp
iso2022jp / ranks.js
Created July 6, 2021 15:39
Compute ranks
const ranks = (values, comparator = (a, b) => b - a) => values
.map((value, i) => [value, i])
.slice().sort(([a], [b]) => comparator(a, b))
.reduce((ranks, [value, i], rank, ordered) => [
...ranks.slice(0, i),
rank && !comparator(value, ordered[rank - 1][0]) ? ranks[ordered[rank - 1][1]] : rank + 1,
...ranks.slice(i + 1),
], Array.from({length: values.length}))
@iso2022jp
iso2022jp / solver.js
Last active February 5, 2022 06:32
Wordle Solver
'use strict'
if (!globalThis.prompt) {
const buffer = require('buffer')
const fs = require('fs')
const input = buffer.Buffer.alloc(10000)
globalThis.prompt = (message, defaultValue = '') => {
message && console.info(message)
let offset = 0
while (fs.readSync(0, input, offset, 1)) {
@iso2022jp
iso2022jp / wslm.cmd
Last active November 2, 2023 03:01
Run wls on the host directory with SMB
@echo off
: Prerequisite: share C: with "C", user "foo" accessible
wsl -- ^
set -euxo pipefail; ^
[[ ! -d /mnt/c2 ]] ^|^| mount ^| grep '/mnt/c2' ^|^| sudo find '/mnt/c2' -type d -empty -delete; ^
[[ -d /mnt/c2 ]] ^|^| sudo mkdir /mnt/c2; ^
grep -qs '/mnt/c2 ' /proc/mounts ^|^| sudo mount -t cifs -o user=foo,nobrl,noperm,cache=none,actimeo=0,iocharset=utf8 //$^(grep nameserver /etc/resolv.conf ^| grep '\.' ^| cut -f2 -d' '^)/C /mnt/c2; ^
cd ${PWD/#\/mnt\/c\///mnt/c2/}; ^
@iso2022jp
iso2022jp / fake-xlsx.js
Last active July 30, 2022 14:26
Download as Excel
const download = (blob, filename, type = blob.type || 'application/octet-stream') => {
const a = document.createElement('a')
a.href = window.URL.createObjectURL(blob)
a.download = filename
a.type = type
a.click()
window.URL.revokeObjectURL(a.href)
}