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
// simple heart shape for OpenSCAD | |
// author: Mindon <mindon@gmail.com> | |
// from https://mindon.github.io/ | |
heart(width = 160, height = 160); | |
module heart(width, height = 0) { // 0 = auto height | |
w = width; h = height; | |
r = 2 * w/7; // top circle radius | |
i = r/4.0; // top circle intersect-part width |
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
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
// 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
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 { Response } from "https://deno.land/std@0.103.0/http/server.ts"; | |
export async function wasmAt(src: string): Promise<any> { | |
if(/^http[s]?:\/\//i.test(src)) { | |
return fetch(src); | |
} | |
return new Response(await Deno.readAll(await Deno.open(src)), {status: 200, headers:{ | |
'content-type': 'application/wasm' | |
}}); | |
} |
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); |
NewerOlder