Skip to content

Instantly share code, notes, and snippets.

@nexpr
nexpr / readme.md
Created July 20, 2019 04:54
koa のルーティングミドルウェア

koa のルーティングミドルウェア

使い方

routes(route_config)

route_config : オブジェクトの配列

  • path : マッチするパス (配列可)
    • 正規表現 or 文字列
@nexpr
nexpr / tuple.js
Created October 3, 2020 08:10
tuple (weakref)
class TupleRegistry {
tuples = []
constructor() {
this.fregistry = new FinalizationRegistry(() => {
this.tuples = this.tuples.filter(ref => ref.deref())
})
}
add(tuple) {
@nexpr
nexpr / repl.example.txt
Created May 26, 2017 13:51
repl for JScript (windows10 only)
C:\Users\user\Desktop>cscript //E:{1b7cd997-e5ff-4932-a7a6-2a9e636da385} repl.js
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
> if(true){\
> 1\
> }
1
> var a = 10
undefined
@nexpr
nexpr / add.js
Last active December 18, 2023 13:45
Deno で Gist のテストを動かす
const add = (a, b) => a + b
export default add
@nexpr
nexpr / dnf.log
Created December 10, 2023 17:36
dnf vs dnf5 / install git in docker container (fedora38)
[root@af929bf74005 /]# time dnf install git -y
Fedora 38 - x86_64 9.5 MB/s | 83 MB 00:08
Fedora 38 openh264 (From Cisco) - x86_64 1.1 kB/s | 2.5 kB 00:02
Fedora Modular 38 - x86_64 3.2 MB/s | 2.8 MB 00:00
Fedora 38 - x86_64 - Updates 3.8 MB/s | 36 MB 00:09
Fedora Modular 38 - x86_64 - Updates 1.5 MB/s | 2.1 MB 00:01
Dependencies resolved.
========================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================
@nexpr
nexpr / sort-domain.js
Created November 26, 2023 12:44
sort domain
export const sortDomain = (domains) => {
return domains.map(x => x.split(".")).sort((a, b) => {
const max = Math.max(a.length, b.length)
const recur = (i = 0) => {
if (i >= max) return 0
return (a.at(-i - 1) ?? "").localeCompare(b.at(-i - 1) ?? "") || recur(i + 1)
}
return recur()
}).map(x => x.join("."))
}
<!DOCTYPE html>
<meta charset="utf-8" />
<script type="module">
import { html, render } from "https://cdn.jsdelivr.net/npm/uhtml@4.1.20/node.js"
const page = async () => {
const valueFormat = (value) => {
try {
@nexpr
nexpr / time-input.js
Created November 19, 2023 12:13
lit example: time input
import { LitElement, css, html } from "lit"
import { live } from "lit/directives/live.js"
export class TimeInput extends LitElement {
static styles = css`
.container {
display: flex;
gap: 10px;
}
input {
@nexpr
nexpr / vue3-htm.html
Created October 30, 2023 13:53
Vue3 + htm example
<!doctype html>
<meta charset="utf-8" />
<script type="module">
import { createApp, ref, h } from "https://unpkg.com/vue@3.3.7/dist/vue.esm-browser.js"
import htm from "https://cdn.jsdelivr.net/npm/htm@3.1.1/mini/index.module.js"
const html = htm.bind(
(type, props, ...children) =>
h(type, props, typeof type === "string" ? children : () => children)
)
@nexpr
nexpr / document-only-style.css
Last active October 29, 2023 07:05
ShadowDOM を使う CustomElement にグローバルスタイルを適用する
foo-bar {
display: block;
margin: 10px;
}
/* not applied */
.box {
color: red;
}