Skip to content

Instantly share code, notes, and snippets.

@LingDong-
LingDong- / unmark.js
Created October 29, 2018 22:53
Markdown to HTML in 1 chain of regexes
var unmark = (t)=>(t
//escape tags
.replace(/\\</g,"&lt")
//tables
.replace(/[\n\r^]((((.*\|)+.+)[\n\r$])((\||)((:|)\-+(:|)\|(:|))+\-+(:|)(\||)[\n\r])(((.*\|)+.+)[\n\r$])+)/g,'<p><table>\n$1</table></p>\n')
.replace(/(\||)((:|)\-+(:|)\|(:|))+\-+(:|)(\||)[\n\r](?=((.*[\n\r])*<\/table>))/g,'')
.replace(/(((.*\|)+.+))[\n\r$](?=((.*[\n\r])*<\/table>))/g,' <tr>|$1|</tr>\n')
.replace(/<tr>\|+(.*)\|+<\/tr>/g,'<tr> <td>$1</td> </tr>')
.replace(/\|(?=((.+)<\/tr>))/g,'</td> <td>')
//paragraph
@LingDong-
LingDong- / LaTeX-skin.css
Created October 29, 2018 23:41
Make your HTML look like it's typeset with LaTeX
/*
* LaTeX-skin.css
* (c) Lingdong Huang 2018
* Make your HTML look like it's typeset with LaTeX
*
* Features:
* - LaTeX look and feel, including its font Computer Modern;
* - Automatic numbering of (sub)sections and figures;
* - Print / export to PDF, (On macOS Safari/Chrome, File > Print)
*/
@LingDong-
LingDong- / cli-ptcloud.c
Last active December 26, 2019 22:57
cli-ptcloud.c
//
// cli-ptcloud.c
// - Lingdong Huang 2019
//
// View point clouds (.ply format) in commandline
//
// Dependencies:
// - curses (-lcurses, comes with most unix systems)
// - rply (http://w3.impa.br/~diego/software/rply/, place in path below:
#define RPLY_PATH "include/rply/rply.h"
@LingDong-
LingDong- / Wormhole.java
Created September 13, 2021 02:22
applet to create cursor "wormholes" connecting different displays
// Wormhole.java
// Lingdong Huang 2021, Public domain
// Simple app to create "wormholes" connecting different displays:
// When cursor enters a black patch, it comes out from the other
// Idea inspired by this mac app "Wormhole by Tod LLC": https://macdownload.informer.com/wormhole1/
// I implemented the idea in java to work on Windows
//
// Usage:
// javac Wormhole.java; java Wormhole <x0> <y0> <x1> <y1>
// (arguments being the positions of the two holes)
@LingDong-
LingDong- / png_read.js
Created October 10, 2022 15:05
a baseline PNG decoder in 400 lines
// baseline PNG decoder in 400 lines
//
// - supports all color types: RGBA, RGB, gray+A, gray, paletted
// - supports all bit depths: 1, 2, 4, 8, 16 bits (color type dependant, per spec)
// - allways return RGBA(0-255) format: other color+bit combinations will be scaled
// - downscaled 16-bit values retain floating point, e.g. 1000/65535 -> 3.89/255
// - support transparency palette / chroma-key
// - supports interlaced / non-interlaced
// - supports all zlib methods: non-compressed / fixed / dynamic huffman
// - supports all filters: none / sub / up / average / paeth
@LingDong-
LingDong- / png_write1.js
Created October 10, 2022 20:05
a baseline somewhat-compressing PNG writer in 150 lines
// baseline somewhat-compressing PNG writer in 150 lines
//
// - supports gray, gray+A, RGB, RGBA, bit depth : 8
// - uses "fixed" huffman codes of DEFLATE spec
// - compresses well for graphics with large "flat" areas,
// basically pixel-wise run-length encoding translated to LZ77 style <len,dist>,
// always filtered with SUB filter
// - writes IHDR, IDAT, IEND -- optional chunks can be
// passed as function argument to be encoded (see example)
//
@LingDong-
LingDong- / png_write.js
Last active October 10, 2022 20:06
a bare minimum, non-compressing PNG writer in 80 lines
// a bare minimum, non-compressing PNG writer in 80 lines
//
// - supports gray, gray+A, RGB, RGBA, bit depth: 8 (0-255)
// - uses "non-compressed blocks" of DEFLATE spec
// - writes IHDR, IDAT, IEND -- optional chunks can be
// passed as function argument to be encoded (see example)
//
// reference:
// - https://en.wikipedia.org/wiki/Portable_Network_Graphics
// - https://datatracker.ietf.org/doc/html/rfc1951
@LingDong-
LingDong- / PoissonFill.java
Last active April 13, 2023 07:49
Poisson Filling Shader for Processing(Java)
/* Poisson Filling for Processing
* Made possible with support from The Frank-Ratchye STUDIO For Creative Inquiry
* At Carnegie Mellon University. http://studioforcreativeinquiry.org/
*/
package poissonfill;
import processing.core.*;
import processing.opengl.*;
import java.util.*;
@LingDong-
LingDong- / bpmrw.h
Created April 19, 2023 15:58
tiny .BMP image reader/writer in C99
/*
bmprw.h
tiny .BMP image reader/writer in C99
with no memory allocations
reader supports:
- 1, 4, 8, 24, 32 bit depth, palette / no palette
- RLE4 / RLE8 compression / no compression
@LingDong-
LingDong- / core_midi_synth.mm
Last active May 19, 2023 08:23
a barebones midi synthesizer calling mac's low level API (CoreMIDI and CoreAudio) directly
//
// core_midi_synth.mm
//
// a barebones midi synthesizer demo that calls
// mac's low level API (CoreMIDI and CoreAudio) directly
// (because I can't be bothered to compile other people's libraries)
//
// with code fragments adapted from
// - https://stackoverflow.com/a/7964300
// - https://github.com/thestk/rtmidi