Skip to content

Instantly share code, notes, and snippets.

// 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;
});
};
}
function getSameCharStrings(strings) {
const repeatedCharsOrSpaceRegex = /(\w)(?=.*\1)|\s/g;
const uniqueSortedChars = strings.map(word => {
return word
.replace(repeatedCharsOrSpaceRegex, '')
.split('')
.sort()
.join('');
});
@saadshahd
saadshahd / svg-to-icon.js
Last active August 7, 2017 22:14
Runtime generator not found
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);
@saadshahd
saadshahd / machine.js
Last active March 25, 2020 20:18
Generated by XState Viz: https://xstate.js.org/viz
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 / machine.js
Last active September 7, 2020 14:07
Generated by XState Viz: https://xstate.js.org/viz
const statusMachine = Machine({
id: "status",
type: "parallel",
states: {
info: {
initial: "Created",
states: {
Created: {
on: {
OFFICIALLY_SCHEDULED: "OfficiallyScheduled"
@saadshahd
saadshahd / machine.js
Last active November 4, 2020 12:10
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
@saadshahd
saadshahd / machine.js
Created September 30, 2020 13:22
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@saadshahd
saadshahd / cloudSettings
Last active January 28, 2022 20:16
Visual Studio Code Settings Sync Gist
{"lastUpload":"2022-01-28T20:16:28.891Z","extensionVersion":"v3.4.3"}