Skip to content

Instantly share code, notes, and snippets.

@elzup
elzup / node.yml
Created May 1, 2022
GitHub workflow template node.js test
View node.yml
name: Node CI
on:
push:
branches:
- main
paths-ignore:
- '**/readme.md'
jobs:
@elzup
elzup / tsconfig.json
Last active Apr 5, 2022
web tsconfig.json
View 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 Feb 27, 2022
Node RED flow 5s to 1s pub
View flow-5s-to-1s.json
[
{
"id": "877f0c504eb0eb9e",
"type": "websocket out",
"z": "bf3d520d6566704c",
"name": "",
"server": "b94d746ecdec7aad",
"client": "",
"x": 910,
"y": 220,
@elzup
elzup / map.ts
Created Dec 24, 2021
map-step-comp
View map.ts
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 Dec 4, 2021
座りっぱなし検知アラート
View suwarippa-flow.json
[ { "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
View async-sleep.ts
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))
View readdirRecursive.js
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 Feb 10, 2022
node setup by n
View n-node-install.sh
# 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 Jul 8, 2021
Check is home Network
View is-my-network.ts
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)
@elzup
elzup / useFitty.ts
Created Jun 14, 2021
fitty for react
View useFitty.ts
import { useEffect, useRef } from 'react'
import fitty from 'fitty'
export function useFitty() {
const ref = useRef<HTMLDivElement>(null)
useEffect(() => {
if (!ref.current) return
fitty(ref.current)
ref.current.addEventListener('fit', (e) => {