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
@lsauer
lsauer / InChi.js
Created October 25, 2011 14:13
Regular Expressions for validating SMILES, InChi, InChiKey
// International Chemical Identifier Regex, by lo sauer - lsauer.com
// Morphine InchI:
var x="InChI=1S/C17H19NO3/c1-18-7-6-17-10-3-5-13(20)16(17)21-15-12(19)4-2-9(14(15)17)8-11(10)18/h2-5,10-11,13,16,19-20H,6-8H2,1H3/t10-,11+,13-,16-,17-/m0/s1"
// applying an organic character-subset
// we could check for the length property, but in case of 0 matches 'null' is returned -> hence !!.. \ generally equal to Boolean(..)
!!x.trim().match(/^((InChI=)?[^J][0-9BCOHNSOPrIFla+\-\(\)\\\/,pqbtmsih]{6,})$/ig)
>true
//generic:
x.trim().match(/^((InChI=)?[^J][0-9a-z+\-\(\)\\\/,]+)$/ig)
@pmeenan
pmeenan / user-timing-rum.js
Last active January 18, 2024 23:46
Support routine for adding W3C user timing events to a site. Includes some basic polyfill support for browsers that don't support user timing or navigation timing (though the start time for non-navigation timing support could be improved with IE < 9 to use IE's custom start event).
// Support routines for automatically reporting user timing for common analytics platforms
// Currently supports Google Analytics, Boomerang and SOASTA mPulse
// In the case of boomerang, you will need to map the event names you want reported
// to timer names (for mPulse these need to be custom0, custom1, etc) using a global variable:
// rumMapping = {'aft': 'custom0'};
(function() {
var wtt = function(n, t, b) {
t = Math.round(t);
if (t >= 0 && t < 3600000) {
// Google Analytics
@ssstonebraker
ssstonebraker / sed cheatsheet
Created August 2, 2013 14:06 — forked from un33k/sed cheatsheet
Sed Cheatsheet
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@mcastilho
mcastilho / gist:e051898d129b44e2f502
Last active June 23, 2023 18:33
Cheap MapReduce in Go
package main
import (
"bufio"
"encoding/csv"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
@sergeyklay
sergeyklay / sed-cheatsheet.md
Last active June 5, 2024 19:51
Sed Cheatsheet

Sed Cheat Sheet

Sed command line options

sed [options] sed-command [input-file]
Option Description Example
@cschiewek
cschiewek / x11_docker_mac.md
Last active May 30, 2024 18:48
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:
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active June 10, 2024 00:49
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

@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
@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"
)
@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));