Skip to content

Instantly share code, notes, and snippets.

@flisboac
flisboac / rpi-helper.sh
Created May 1, 2019 00:31
A simple and quick frankensteined/projectified Raspbian/RaspberryPi provisioner and tester helper sorta-thing.
#!/bin/sh
RPI_PIVERSION="${RPI_PIVERSION:-""}"
RPI_PIMODEL="${RPI_PIMODEL:-""}"
RPI_IMAGE_URLPREFIX="${RPI_IMAGE_URLPREFIX:-"https://downloads.raspberrypi.org/raspbian_"}"
RPI_IMAGE_VARIANT="${RPI_IMAGE_VARIANT:-"lite"}"
RPI_IMAGE_VERSION="latest"
RPI_GUEST_SHELL="${RPI_GUEST_SHELL:-"sh"}"
interface IValidQuestionValidation {
success: true;
value: string;
}
interface IInvalidQuestionValidation {
success: false;
message: string;
}
class MonadError extends Error {}
class EmptyMonadError extends MonadError {}
class Maybe<T> {
protected value?: T;
constructor(value?: T) {
this.value = value;
@flisboac
flisboac / construct-string-from-templ-string.ts
Created February 25, 2019 22:44
Generic method to (re-)construct a string from a tagged template string literal. Useful for shims (e.g. fool your editor into thinking there's a `gql` tag).
function s(strings: ReadonlyArray<string>, ...exprs: any[]): string {
return strings.reduce((accum, elem, idx) => `${accum}${elem}${idx < exprs.length ? exprs[idx] : ''}`, '');
}
// Example:
// s`a_${10}_b` -> "a_10_b"
@flisboac
flisboac / FormDataUtil.ts
Created October 31, 2018 22:13
Some ideas about type shaping from other types, applied to form data handling/type-safety. Please, use Yup instead, makes much more sense. :)
type FormFieldTuple<T> = { value: Required<T>, valid: boolean, message?: string };
type FormFieldData<T>
= T extends undefined ? FormFieldTuple<T> | undefined
: FormFieldTuple<T>
;
type FormFields<F, K extends keyof F = keyof F> = { [KK in K]:
F[KK] extends object ? FormFields<F[KK]> : FormFieldData<F[KK]>
@flisboac
flisboac / quickmonad.ts
Created October 17, 2018 22:48
A quick and dirty Monad/Maybe type in TypeScript
class MonadError extends Error {}
class EmptyMonadError extends MonadError {}
class Maybe<T> {
protected value?: T;
constructor(value?: T) {
this.value = value;
@flisboac
flisboac / ws.sh
Last active September 12, 2018 23:30
#!/bin/sh
readonly wsconfig_env_home="$(cd "$(dirname "$0")" && pwd -P)"
{ WS_DOCKERFILE_CONTENTS="$(cat)"; } <<"_DOCKERFILE_"
FROM ubuntu:bionic
ENV DEBIAN_FRONTEND="teletype"
# Update system and install essential developer tools
@flisboac
flisboac / m2-purge
Last active July 25, 2018 17:26
Forcibly deletes/purges individual artifact coordinates from a default-layout M2 repository, without using `mvn` or downloading any dependency tree. (P.S.: Does not work with transitive dependencies! For that, use https://maven.apache.org/plugins/maven-dependency-plugin/purge-local-repository-mojo.html)
#!/bin/sh
main() {
local m2_root; m2_root="~/.m2"
local groupId
local artifactId
local parsing; parsing=0
local path
local exitcode; exitcode=0
local dry_run; dry_run=1
See https://stackoverflow.com/questions/38335668/how-to-refer-to-typescript-enum-in-d-ts-file-when-using-amd
Run with `npm run exec`, will install all dependencies as needed.
@flisboac
flisboac / xmlrpc-c-config
Created October 19, 2017 23:52
Sample xmlrpc-c-config
#! /bin/sh
#
# This file was generated by a make rule
#
#
#######################################################
# From 'shell_config'
#######################################################
ENABLE_ABYSS_THREADS="yes"
THREAD_LIBS="-lpthread"