Skip to content

Instantly share code, notes, and snippets.

@elzup
elzup / day-per-year
Last active January 24, 2023 03:00
src/time/day-per-year.ts
1/19 [ 19] => 0.0006 = (0.0526 - 0.0521)
4/14 [104] => 0.0008 = (0.2857 - 0.2849)
8/13 [225] => 0.0011 = (0.6154 - 0.6164)
3/15 [ 74] => 0.0027 = (0.2000 - 0.2027)
2/16 [ 47] => 0.0038 = (0.1250 - 0.1288)
1/20 [ 20] => 0.0048 = (0.0500 - 0.0548)
1/18 [ 18] => 0.0062 = (0.0556 - 0.0493)
7/13 [194] => 0.0070 = (0.5385 - 0.5315)
2/15 [ 46] => 0.0073 = (0.1333 - 0.1260)
9/13 [256] => 0.0091 = (0.6923 - 0.7014)
@elzup
elzup / node.yml
Created May 1, 2022 12:50
GitHub workflow template node.js test
name: Node CI
on:
push:
branches:
- main
paths-ignore:
- '**/readme.md'
jobs:
@elzup
elzup / tsconfig.json
Last active April 5, 2022 15:13
web tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true,
@elzup
elzup / flow-5s-to-1s.json
Created February 27, 2022 11:51
Node RED flow 5s to 1s pub
[
{
"id": "877f0c504eb0eb9e",
"type": "websocket out",
"z": "bf3d520d6566704c",
"name": "",
"server": "b94d746ecdec7aad",
"client": "",
"x": 910,
"y": 220,
@elzup
elzup / map.ts
Created December 24, 2021 06:03
map-step-comp
const a = [
{ name: 'a', age: 10 },
{ name: 'b', age: 20 },
]
a.map((p) => {
const len = p.name.length
const id = `${p.name}-${p.age}`
const ageDouble = p.age * 2
@elzup
elzup / suwarippa-flow.json
Created December 4, 2021 01:11
座りっぱなし検知アラート
[ { "id": "f6f2187d.f17ca8", "type": "tab", "label": "Swarippa", "disabled": false, "info": "", "env": [] }, { "id": "19e47bd1eea2e757", "type": "http request", "z": "f6f2187d.f17ca8", "name": "Slack Webhook - elzup", "method": "POST", "ret": "txt", "paytoqs": "ignore", "url": "${SLACK_URL}", "tls": "", "persist": false, "proxy": "", "authType": "", "senderr": false, "x": 1050, "y": 1180, "wires": [ [] ] }, { "id": "803d03164af5eb1a", "type": "change", "z": "f6f2187d.f17ca8", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "{\"text\":\"動いて!\",\"icon_emoji\":\":chair:\",\"username\":\"座りっぱ執事\"}", "tot": "json" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 820, "y": 1180, "wires": [ [ "19e47bd1eea2e757", "29d5897e04face4f" ] ] }, { "id": "29d5897e04face4f", "type": "debug", "z": "f6f2187d.f17ca8", "name": "debug log", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusTy
import { promisify } from 'util'
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms))
const argSwap = <A1, A2, R>(f: (a1: A1, a2: A2) => R) => (a2: A2, a1: A1) =>
f(a1, a2)
const sleep2 = promisify((ms, cb) => setTimeout(cb, ms))
const sleep3 = promisify(argSwap(setTimeout))
const { readdir } = require('fs').promises
const readdirRecursiveEnt = async (dir, ent) => {
const path = `${dir}/${ent.name}`
if (ent.isFile()) return path
if (ent.isDirectory()) {
return await readdirRecursive(path)
}
console.log(`${ent.name} is not a file or directory`)
return null
@elzup
elzup / n-node-install.sh
Last active February 10, 2022 15:22
node setup by n
# install n
sudo apt install -y nodejs npm
sudo npm install n -g
# install node by n
sudo n stable
sudo apt purge -y nodejs npm
# reload
exec $SHELL -l
@elzup
elzup / is-my-network.ts
Created July 8, 2021 07:00
Check is home Network
import fs from 'fs'
import { promisify } from 'util'
import network from 'network'
const getActiveInterface = promisify(network.get_active_interface)
const getCurrent = async () => (await getActiveInterface())?.mac_address
const SAVE_FILE = 'home.mac.txt'
const saveHomeNetwork = (id: string) => fs.writeFileSync('home.mac.txt', id)