Skip to content

Instantly share code, notes, and snippets.

@saadshahd
saadshahd / cloudSettings
Last active Apr 13, 2021
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2021-04-13T13:31:02.057Z","extensionVersion":"v3.4.3"}
View machine.js
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
View machine.js
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
View machine.js
const statusMachine = Machine({
id: "status",
type: "parallel",
states: {
info: {
initial: "Created",
states: {
Created: {
on: {
OFFICIALLY_SCHEDULED: "OfficiallyScheduled"
View machine.js
const test = (regex, base) => base && base.name && regex.test(base.name);
const isStart = ({ base }) => test(/^start-/, base);
const isFull = ({ base }) => !test(/^start-/, base);
const baseMachine = Machine({
id: 'base',
initial: 'init',
context: {
startBase: null,
base: {}
@saadshahd
saadshahd / svg-to-icon.js
Last active Aug 7, 2017
Runtime generator not found
View svg-to-icon.js
const path = require('path');
const pascalCase = require('pascal-case');
const {stringifyRequest} = require('loader-utils');
const {stringifySymbol, stringify} = require('../../lib/utils');
module.exports = function ({symbol, config, context, loaderContext}) {
const {spriteModule, symbolModule, runtimeOptions} = config;
const compilerContext = loaderContext._compiler.context;
const iconModulePath = path.resolve(compilerContext, runtimeOptions.iconModule);
View sameCharsWords.js
function getSameCharStrings(strings) {
const repeatedCharsOrSpaceRegex = /(\w)(?=.*\1)|\s/g;
const uniqueSortedChars = strings.map(word => {
return word
.replace(repeatedCharsOrSpaceRegex, '')
.split('')
.sort()
.join('');
});
View side-effects
// Generates two conditional methods
// 1. (isBroken: true, method: 'some') filters the abandoned shipments
// 2. (isBroken: false, method: 'every') filters the ready shipments
function checkShipment(isBroken, method) {
return function (curShipment) {
return curShipment.packagesList[method](function (curPackage) {
return curPackage.isBroken === isBroken;
});
};
}