Skip to content

Instantly share code, notes, and snippets.

@elzup
elzup / _app.tsx
Last active July 5, 2023 12:42
Next.js with typescript minimum pages/_document.tsx, pages/_app.tsx
import { AppProps } from 'next/app'
import Head from 'next/head'
const App = ({ Component, pageProps }: AppProps) => (
<>
<Head>
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
@elzup
elzup / 0->100 arrow functions
Last active May 22, 2023 17:02
Goal: 100 Arrow functions, Anonymous function, lambda, closure example.
...
checks
// no args
// block
// implicit parameter
// assign
@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 / 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 / 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))