Skip to content

Instantly share code, notes, and snippets.

View mindon's full-sized avatar
💭
zig, zed, deno, wasm and ai ux

mindon mindon

💭
zig, zed, deno, wasm and ai ux
View GitHub Profile
@mindon
mindon / draggable.js
Last active August 19, 2024 10:12
Make a HTML dom or element with id or id-header (if exists, only header) draggable
// 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);
@mindon
mindon / inside_points.js
Created August 2, 2024 04:13
Fill a geometry with points in THREE.js
// 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();
@mindon
mindon / sort_by_attrs.js
Last active August 19, 2024 10:12
sort a object array with string attributes
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));
@mindon
mindon / qconvert.ts
Last active October 11, 2022 03:26
qconvert typescript for deno, a Quantum Computing Language Converter
// 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";
@mindon
mindon / cadder.go
Last active March 22, 2023 02:19
Simple command tool to start|stop|reload CaddyServer in current directory without merging all configs into one (for Caddy2+)
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
@Cpavrai
Cpavrai / curltime
Created May 9, 2022 12:53
Script for computing loading time depending on web URL
#!/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
@mindon
mindon / dual-flipped.css
Last active August 20, 2021 08:51
pure css for a simple flipping card
/* <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;
@mindon
mindon / deno_ts_testing_private_func_test.ts
Created March 12, 2021 17:43
A simple helper to test functions not-exported but with _ prefix
// 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));
@mindon
mindon / fetch-js.go
Created January 7, 2021 12:45
make a fetch from js code from golang
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
)
@varnav
varnav / pagespeed_optimize_images.sh
Last active June 14, 2022 07:46 — forked from julianxhokaxhiu/pagespeed_optimize_images.sh
Recursively optimize all PNG and JPG files
#!/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