Skip to content

Instantly share code, notes, and snippets.

@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
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active May 6, 2024 07:52
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@cschiewek
cschiewek / x11_docker_mac.md
Last active May 2, 2024 17:53
X11 in docker on macOS

To forward X11 from inside a docker container to a host running macOS

  1. Install XQuartz: https://www.xquartz.org/
  2. Launch XQuartz. Under the XQuartz menu, select Preferences
  3. Go to the security tab and ensure "Allow connections from network clients" is checked.
  4. Run xhost + ${hostname} to allow connections to the macOS host *
  5. Setup a HOSTNAME env var export HOSTNAME=`hostname`*
  6. Add the following to your docker-compose:
 environment:
@sergeyklay
sergeyklay / sed-cheatsheet.md
Last active July 8, 2023 01:44
Sed Cheatsheet

Sed Cheat Sheet

Sed command line options

sed [options] sed-command [input-file]
Option Description Example