Skip to content

Instantly share code, notes, and snippets.

@drmikecrowe
drmikecrowe / machine.js
Created September 17, 2020 09:04
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: "formModal",
initial: "closed",
states: {
closed: {
on: {
OPEN: "opened"
}
},
@drmikecrowe
drmikecrowe / Account.js
Last active June 17, 2021 16:38
Auto-incrementing ID's in Loopback
module.exports = function (Account) {
Account.observe('before save', function addAccountId(ctx, next) {
if (!ctx.isNewInstance) {
debug('id is already set, returning', ctx.data);
return next();
}
app.dataSources.db.connector.collection("Sequences").findAndModify({name: 'Account'}, [['_id', 'asc']], {$inc: {value: 1}}, {new: true}, function (err, rec) {
if (err) {
console.err(err);
@drmikecrowe
drmikecrowe / app.js
Last active October 27, 2021 04:28
Sharing constants between node.js app and web app
//** In web app **//
var current = constants.STATE_WAITING;
@drmikecrowe
drmikecrowe / bootstrap.sh
Last active February 9, 2022 14:04
Bash Bootstrap
#!/usr/bin/env bash
function install {
FILE="$2"
URL="$1/$FILE"
wget $URL -O $FILE
sudo gdebi $FILE
rm $FILE
}
@drmikecrowe
drmikecrowe / launches.json
Last active March 4, 2022 12:14
My common launch.json config
[
{
"type": "node",
"request": "attach",
"port": 9229,
"sourceMaps": true,
"name": "Attach 9229",
"cwd": "${workspaceRoot}",
"address": "localhost",
"localRoot": "${workspaceFolder}",
TS2344: Type 'T[U]' does not satisfy the constraint '(...args: any) => any'.
Type 'T[OnlyFunctionPropertyNames<T>]' is not assignable to type '(...args: any) => any'.
Type 'T[T[keyof T] extends (...args: any) => any ? keyof T : never]' is not assignable to type '(...args: any) => any'.
Type 'T[keyof T]' is not assignable to type '(...args: any) => any'.
Type 'T[string] | T[number] | T[symbol]' is not assignable to type '(...args: any) => any'.
Type 'T[string]' is not assignable to type '(...args: any) => any'.
16 | T extends Composer<never>,
17 | U extends OnlyFunctionPropertyNames<T> = OnlyFunctionPropertyNames<T>,
> 18 | > = Filter<Parameters<T[U]>, Middleware<never>>
@drmikecrowe
drmikecrowe / machine.js
Created November 21, 2019 18:47
Generated by XState Viz: https://xstate.js.org/viz
const RETRY_INTERVAL = 2000;
const MAX_RETRIES = 3;
const initHardwareState = "initHardware";
const connectNetworkState = "connectNetwork";
const provisionState = "provision";
const retryState = "retry";
const fatalState = "fatal";
const connectedState = "connected";
@drmikecrowe
drmikecrowe / template.sh
Last active July 30, 2022 21:42
Bash Template
#!/usr/bin/env bash
function mainScript() {
debug "Arguments: $args"
}
# Options and Usage
# -----------------------------------
function usage() {
@drmikecrowe
drmikecrowe / docker-compose.yml
Last active October 10, 2022 10:49
Ultimate docker-compose setup for home media center
#Reference: https://www.smarthomebeginner.com/docker-home-media-server-2018-basic
version: "3"
# https://github.com/pi-hole/docker-pi-hole/blob/master/README.md
services:
radarr:
image: "linuxserver/radarr"
dns_search: local
@drmikecrowe
drmikecrowe / install.sh
Created June 28, 2023 08:56 — forked from mx00s/install.sh
NixOS install script based on @grahamc's "Erase Your Darlings" blog post
#!/usr/bin/env bash
#
# NixOS install script synthesized from:
#
# - Erase Your Darlings (https://grahamc.com/blog/erase-your-darlings)
# - ZFS Datasets for NixOS (https://grahamc.com/blog/nixos-on-zfs)
# - NixOS Manual (https://nixos.org/nixos/manual/)
#
# It expects the name of the block device (e.g. 'sda') to partition