Skip to content

Instantly share code, notes, and snippets.

@diachedelic
diachedelic / MediaCapture.m
Last active May 16, 2024 12:37
A Capacitor plugin to capture images and video. Public domain, no warranty.
#import <Capacitor/Capacitor.h>
CAP_PLUGIN(MediaCapture, "MediaCapture",
CAP_PLUGIN_METHOD(image, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(video, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(choose, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(mime_type, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(duration, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(save, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(destroy, CAPPluginReturnNone);
@diachedelic
diachedelic / crc32.js
Created October 12, 2022 05:44
A CRC-32 checksum implementation for all JavaScript runtimes.
// A CRC32 checksum implementation. It can be used to detect data corruption.
// The 'byte_array' parameter is a Uint8Array, the return value is a signed 32
// bit integer. If you are checksumming a stream of data, pass the last known
// checksum as the 'checksum' parameter.
/*jslint bitwise */
const table = (function () {
let values = new Int32Array(256);
let value_nr = 0;
@diachedelic
diachedelic / fatdeps.sh
Last active June 30, 2022 02:54
A shell script which detects the bloated dependencies in a package.json.
#!/bin/bash
# fatdeps.sh is a script that counts the number of subdependencies of every
# dependency found in a package.json file. It can be used to discover bloat,
# which is a major security risk in Node.js and browser applications.
# fatdeps.sh depends on the 'jq' and 'npx' commands.
# USAGE
@diachedelic
diachedelic / r2d2.svg
Created July 30, 2021 14:16
A vectorised, pixel art picture of R2D2.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@diachedelic
diachedelic / sudoku_solver.hs
Last active November 29, 2020 11:14
Solve sudoku puzzles with functional programming.
-- This program finds and prints all solutions to a sudoku puzzle.
-- To run:
-- $ ghc sudoku_solver.hs
-- $ ./sudoku_solver
-- To profile:
-- $ ghc -prof -fprof-auto -rtsopts sudoku_solver.hs
-- $ time ./sudoku_solver +RTS -p
@diachedelic
diachedelic / deep-link-from-browser.js
Last active October 31, 2024 07:31
Deep link to a native app from a browser, with a fallback
@diachedelic
diachedelic / jpeg_quality_vs_filesize.tsv
Created June 20, 2019 12:19
quality vs filesize resulting from `canvas.toBlob(cb, 'image/jpeg', quality)`
0 0.008210771260531026
0.01 0.008210771260531026
0.02 0.008216896670125255
0.03 0.00887707970416994
0.04 0.010482277318390965
0.05 0.01241246194163914
0.06 0.014545125382029886
0.07 0.01679247010204592
0.08 0.01906057315457573
0.09 0.021325273201775415
@diachedelic
diachedelic / broken.svg
Created November 9, 2017 01:13
Netscape navigator broken image icon as SVG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.