Skip to content

Instantly share code, notes, and snippets.

View machine.js
const machine = Machine({
id: "formModal",
initial: "closed",
states: {
closed: {
on: {
OPEN: "opened"
}
},
View machine.js
const PMachineOptions = {
guards: {
IS_FETCH_NEEDED: function (ctx) {
return !ctx.podcast.loaded;
},
IS_FETCHED_ALREADY: function (ctx) {
return ctx.podcast.loaded;
},
IS_SUBSCRIBE_NEEDED: function (ctx) {
return !ctx.currentDevice.isSubscribed(ctx.podcast);
@drmikecrowe
drmikecrowe / app.js
Last active Aug 14, 2020
Sharing constants between node.js app and web app
View app.js
//** In web app **//
var current = constants.STATE_WAITING;
View machine.js
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";
View machine.js
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
View machine.js
const states = {
IDLE: 'IDLE',
SEARCHING: 'SEARCHING',
};
const searchNotEmptyTarget = {
target: states.SEARCHING,
cond: (_ctx, evt) => evt.search !== '', // && evt.search.length > 3,
actions: assign({ search: (_ctx, evt) => evt.search }),
};
@drmikecrowe
drmikecrowe / index.d.ts
Created May 31, 2020
cache-manager index.d.ts types
View index.d.ts
declare module 'cache-manager/caching' {
/**
* Generic caching interface that wraps any caching library with a compatible interface.
* @param args.store - The store must at least have `set` and a `get` functions.
* @param [args.isCacheableValue] - A callback function which is called
* with every value returned from cache or from a wrapped function. This lets you specify
* which values should and should not be cached. If the function returns true, it will be
* stored in cache. By default it caches everything except undefined.
*/
function caching(args: {
@drmikecrowe
drmikecrowe / index.d.ts
Created May 30, 2020
index.d.ts for cache-manager
View index.d.ts
/**
* Instead of manually managing the cache like this:
* function getCachedUserManually(id, cb) {
* memoryCache.get(id, function(err, result) {
* if (err) { return cb(err); }
*
* if (result) {
* return cb(null, result);
* }
*
@drmikecrowe
drmikecrowe / docker-compose.yml
Created Sep 2, 2019
Ultimate docker-compose setup for home media center
View docker-compose.yml
#Reference: https://www.smarthomebeginner.com/docker-home-media-server-2018-basic
version: "3.6"
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx
ports:
- "80:80"
volumes:
@drmikecrowe
drmikecrowe / bootstrap.sh
Last active Mar 22, 2020
Bash Bootstrap
View bootstrap.sh
#!/usr/bin/env bash
function install {
FILE="$2"
URL="$1/$FILE"
wget $URL -O $FILE
sudo gdebi $FILE
rm $FILE
}
You can’t perform that action at this time.