Skip to content

Instantly share code, notes, and snippets.

@awkward-ninja
awkward-ninja / option.js
Last active December 24, 2022 09:22
Javascript Monads
class Option {
constructor(some, value) {
this.some = some
this.value = value
}
map(next) {
return this.some ? next(this.value) : this
}
@awkward-ninja
awkward-ninja / gpgflow.sh
Last active June 28, 2022 08:22
GPG Import / Export / Clone
# Based on the following articles
# https://blog.programster.org/generating-gpg-master-and-subkeys
# https://risanb.com/code/backup-restore-gpg-key/
# https://gist.github.com/oseme-techguy/bae2e309c084d93b75a9b25f49718f85
gpg_keyid() {
gpg2 --list-secret-keys \
| sed -n 's/^ \(\w*\)/\1/p'
}
@awkward-ninja
awkward-ninja / .dockerignore
Created January 29, 2022 07:20
Rust dev container
.git

Keybase proof

I hereby claim:

  • I am awkward-ninja on github.
  • I am kenmerthe (https://keybase.io/kenmerthe) on keybase.
  • I have a public key ASDD91qDfI7HQn_IXIm7cPSEQysR_5R3VPOIVZE441UNmgo

To claim this, I am signing this object:

@awkward-ninja
awkward-ninja / index.js
Created November 23, 2017 18:51
Angular-style parameter name extraction (in ES6)
const
PARAMS_RE = /^[^(]*\(([^)]*)\)/m,
COMMENT_RE = /((\/\/.*$)|(\/\*.*?\*\/))/mg,
SPACE_RE = /\s*/mg
const params = String( pred )
.match( PARAMS_RE )[ 1 ]
.replace( COMMENT_RE, '' )
.replace( SPACE_RE, '' )
.split( ',' )
@awkward-ninja
awkward-ninja / index.js
Created November 23, 2017 18:49
Monotonic sequence that is also its current value (in ES6)
'use strict';
class SequencedNumber extends Number {
advance() { this._next = this._current + 1; }
constructor (initial) {
super(initial);
this._current = initial;
this._next = initial;
}
@awkward-ninja
awkward-ninja / rotary_switch.ino
Created November 23, 2017 18:47
Rotary switch for Arduino Nano with Debouncing, Maximum Range, Value Lock, and Position Memory
struct signal {
byte curr;
byte prev;
};
struct signalDb {
byte curr;
byte prev;
signal db;
};
@awkward-ninja
awkward-ninja / Makefile
Last active November 23, 2017 18:45
Barebones Blinky for Arduino Nano over USB
ARDUINO_DIR = /usr/share/arduino/hardware/arduino
ARDUINO_CORE_DIR = $(ARDUINO_DIR)/cores/arduino
ARCH = atmega328p
CORE_SRC = \
$(ARDUINO_CORE_DIR)/wiring.c \
$(ARDUINO_CORE_DIR)/wiring_digital.c
.PHONY: all