Skip to content

Instantly share code, notes, and snippets.

@mindon
mindon / optimize-embed-images-size-in-svg.js
Created May 26, 2022 12:36
Let's say, what if your designer providing a svg file with large embedded images... how to optimize the svg file size?
(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: mindon@live.com
function optimize(img, cb) {
const src = img ? img.getAttribute("xlink:href") : undefined;
let c = document.createElement("canvas");
const done = () => {
cb && cb();
@mindon
mindon / lost-in-cos.go
Created May 25, 2022 11:12
Find any file sync failed folders under Tencent Cloud COS bucket 查找腾讯云COS有同步(移动)失败文件的文件夹
package main
import (
"context"
"log"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
@mindon
mindon / drc_hook.rb
Created April 6, 2022 02:35
hook (previouse) for KLayout DRC, put this file under folder bin-release/drc/
# $autorun-early
require 'open3'
# mindon@live.com 2022-04-02
module DRC
module Hook
def self.on(drc, macro)
name = 'KLAYOUT_HOOK_DRC'
body = macro.text
@mindon
mindon / keyield.go
Last active February 22, 2022 10:25
RSA Private/Public Key Generator, Encrypt and Decrypt in Golang
package main
import (
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/hex"
"encoding/pem"
@mindon
mindon / guides.js
Created January 5, 2022 02:54
simple guides tour
function guides(hashes, shared) {
let g = undefined,
gs = {},
list = [],
step = 0,
astyle,
padding,
m,
width = 0,
height = 0,
@mindon
mindon / tai-chi.css
Last active August 20, 2021 09:03
Chinese Tai-Chi Diagram Pure CSS Style
/* https://mindon.github.io/blog/2012/08/28/css3-tai-chi
<div class="yinyang">
<div class="yin"><div class="yinc"><div class="yind"></div></div></div>
<div class="yang"><div class="yangc"><div class="yangd"></div></div></div>
</div>
**/
@-webkit-keyframes r {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(-360deg); }
}
@mindon
mindon / wasm-at.ts
Last active November 16, 2022 09:22
read wasm at local or from remote in deno typescript
// 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'
}});
}
@mindon
mindon / vasp2cif.ts
Created August 11, 2021 08:35
Convert VASP POSCAR to Cif - TypeScript | JavaScript
let cifblocknr = 1;
const findsymtolerance = 0;
// convert VASP POSCAR to cif format
function vasp2cif(poscar: string): string {
const lines = poscar.split('\n');
const cell = new Cell();
cell.HMSymbol = "'P 1'";
cell.label = cifblocknr.toString();
@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));