This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _DT = {id: 'de', name: 'data'}; | |
// indexeddb | |
export function db$(id, name, todo) { | |
if (!win.indexedDB) { | |
return; | |
} | |
const { mode = "readonly" } = todo; | |
let req = indexedDB.open(id); | |
req.onsuccess = (evt) => { | |
const db = evt.target.result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fraction gets up/down from a number | |
export function fraction(v: number, { precise = 5, tries = 100 }): string { | |
const [ul, dl] = [[0, 1], [1, 0]]; | |
const max = parseInt((v - Math.floor(v)).toString().substring(2)); | |
let [previous, current] = [NaN]; | |
let c = v; | |
for (let i = 2; i < tries; i++) { | |
const n = Math.floor(c); | |
const uc = n * ul[i - 1] + ul[i - 2]; | |
if (Math.abs(ul[i]) > max) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (selector) in class to reuse classes from first element of selector | |
// define a class-ref <div id="my" class="a b c d"></div> | |
// use class ref <div class="ref x y (#my) z"></div> | |
// result in <div class="ref x y a b c d z"></div> | |
function refClass(root) { | |
[].slice.apply((root || document).querySelectorAll('.ref')).forEach(d => { | |
const c = d.className.replace(/\([:#.]?[\w.-]+\)/g, (s) => { | |
const q = s.charAt(1) == ':' | |
? `[class-ref="${s.substr(2, s.length - 3)}"]` | |
: s.substr(1, s.length -2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// qconvert for deno | |
// updated: 2022-10-11, Mindon<[email protected]> | |
// e.g. `deno run --allow-read --allow-write --unstable qconvert.ts -i hello.qasm -s qasm -o hello.quil -t quil` | |
// original: https://github.com/quantastica/qconvert-js | |
import { default as QuantumCircuit } from "npm:quantum-circuit"; | |
import { parse } from "https://deno.land/std/flags/mod.ts"; | |
import { exists } from "https://deno.land/std/fs/mod.ts"; | |
import { assert } from "https://deno.land/std/testing/asserts.ts"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// cadder to start|stop|reload simple caddy servers in current directory, without merge all configs into one | |
// example: /site0/Caddyfile, /site1/caddy.json, `cd /site0/ && cadder start` then `cd /site1/ && cadder start`` | |
// | |
// How to build cadder? | |
// you need download and install golang from <https://go.dev/dl/> then `go build cadder.go` | |
// | |
// author: [email protected] | |
// created: 2022-07-14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git diff HEAD@{1} --diff-filter=ACMR --name-only -z | xargs -0 git archive HEAD -o patch_$(date +'%Y%m%d').zip -- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
serve, | |
type ConnInfo, | |
type Handler, | |
type ServeInit, | |
} from 'https://deno.land/[email protected]/http/server.ts'; | |
function assertIsNetAddr(addr: Deno.Addr): asserts addr is Deno.NetAddr { | |
if (!['tcp', 'udp'].includes(addr.transport)) { | |
throw new Error('Not a valid network address'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(svgdoc, scale) { | |
// optimize large embed images in a svg | |
// usage: <html><body><svg>your own real svg with too large embeded images...</svg><script src="optimize-embed-images-size-in-svg.js">< /script></body></html> | |
// author: [email protected] | |
function optimize(img, cb) { | |
const src = img ? img.getAttribute("xlink:href") : undefined; | |
let c = document.createElement("canvas"); | |
const done = () => { | |
cb && cb(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"log" | |
"net/http" | |
"net/url" | |
"os" | |
"path" | |
"path/filepath" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $autorun-early | |
require 'open3' | |
# [email protected] 2022-04-02 | |
module DRC | |
module Hook | |
def self.on(drc, macro) | |
name = 'KLAYOUT_HOOK_DRC' | |
body = macro.text |