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
// Make a HTML dom or element with id or id-header (if exists, only header) draggable | |
// auto init .draggable elements, <div class="draggable">Drag Here</div><script src="draggable.js"></script> | |
// usage: draggable(elm) | |
// orgin from https://gist.github.com/mindon/84a8906a2d9e7ad078ae07692b52c460 | |
globalThis.draggable = ((auto = true, stylize = true, globalized = false) => { | |
// ---------->>> | |
const win = globalThis || window; | |
console.assert(win); | |
const doc = win.document; | |
console.assert(doc); |
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
// generate points inside a geometry, with THREE.js | |
// Mindon<mindon@live.com> https://mindon.dev, 2024.08.01 | |
// Example code: | |
// const inside = Inside(THREE); | |
// const material = new THREE.PointsMaterial({color: 0xffffff, size: 0.25}); | |
// scene.add(inside.points(num, geometry, material)); | |
// // scene.add(new THREE.Points(inside.geometry(num, geometry), material)); | |
export function Inside(THREE) { | |
const ray = new THREE.Ray(); |
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
// 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
#!/bin/bash | |
# USAGE: curltime DOMAIN_NAME | |
curl -w @- -o /dev/null -s "$@" <<'EOF' | |
time_namelookup: %{time_namelookup}\n | |
time_connect: %{time_connect}\n | |
time_appconnect: %{time_appconnect}\n | |
time_pretransfer: %{time_pretransfer}\n | |
time_redirect: %{time_redirect}\n | |
time_starttransfer: %{time_starttransfer}\n |
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
/* <div class="dual"><div class="box"><div onclick="this.parentElement.classList.add('flipped')">current</div><div onclick="this.parentElement.classList.remove('flipped')">current</div></div></div> */ | |
.dual { | |
max-width: 100%; | |
position: relative; | |
margin: 2rem 0; | |
perspective: 1280px; | |
} | |
.dual:hover { | |
z-index: 999; |
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
// A simple helper to test functions not-exported but with _ prefix | |
const privateCases = async function (flpath: string, cases: Function) { | |
const decoder = new TextDecoder("utf-8"); | |
let body = decoder.decode(await Deno.readFile(flpath)); | |
body = body.replace(/\nfunction _/g, "\nexport function _"); | |
const tmppath = flpath.replace(/([^\/]+)$/, "~$1"), | |
encoder = new TextEncoder(); | |
await Deno.writeFile(tmppath, encoder.encode(body)); | |
cases(await import(tmppath)); |
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 | |
import ( | |
"bytes" | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"strings" | |
) |
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
#!/bin/bash | |
# https://code.luasoftware.com/tutorials/linux/command-line-optimize-image/ | |
find . -type f -iname '*.png' -exec pngquant --skip-if-larger --ext .png --force 256 {} \; | |
find . -type f -iname "*.png" | xargs optipng -o2 -strip all | |
find . -name '*.png' -print0 | xargs -0 -n1 -I{} sh -c 'zopflipng {} output.png; [ -f output.png ] && mv output.png {};' | |
# Using -print0 to deal with spaces | |
find . -print0 -type f -name "*.jpg" -o -name "*.JPG" | xargs -0 jpegoptim |
NewerOlder