This file contains 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 arr = [{attr:'x', value: 2}, {attr:'y', value: 2}, {attr:'z', value: 1}]; | |
// descend | |
arr.sort((a,b,x='attr')=>+(a[x]<b[x])-+(a[x]>b[x])); | |
console.log(arr.slice(0)); | |
// ascend | |
arr.sort((a,b,x='attr')=>+(a[x]>b[x])-+(a[x]<b[x])); | |
console.log(arr.slice(0)); |
This file contains 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
#include "MixedFilterModel.h" | |
bool MixedFilterModel::fit(QString s, QVariant rule) | |
{ | |
int metaTypeId = rule.metaType().id(); | |
if (metaTypeId == QMetaType::QString) { | |
QString r = rule.toString(); | |
if (r == "*") | |
return true; | |
if (r.contains("*")) { |
This file contains 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
async function get$(src, cb, opts = { method: "GET" }) { | |
let [current, received, total] = [0, 0, 0]; | |
cb({ state: "nif" }); | |
const resp = await fetch(src, { | |
mode: "cors", | |
headers: { | |
"Content-Type": "application/octet-stream", | |
}, |
This file contains 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 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 | |
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 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 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<mindon@live.com> | |
// 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 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: mindon@live.com | |
// created: 2022-07-14 |
This file contains 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 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/std@0.144.0/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'); |
NewerOlder