Skip to content

Instantly share code, notes, and snippets.

@dturton
dturton / docker.md
Created December 18, 2022 18:07 — forked from zmts/docker.md
Docker, TypeScript, Node.js

Docker, TypeScript, Node.js

Preconditions:

  • TS application listening port: 7777
|-- dist
|-- src
|-- .dockerignore
|-- Dockerfile
@dturton
dturton / proxy_createStore.js
Last active December 1, 2022 17:50
JavaScript Proxy example use case
function createStore(target, listener) {
const handler = {
set(target, prop, value, receiver) {
target[prop] = value;
listener(receiver);
return true;
},
get(target, prop) {
return target[prop];
},
@dturton
dturton / getCircularReplacer.ts
Created October 9, 2022 17:42
JSON.stringify() -- Converting circular structure to JSON - workaround
const getCircularReplacer = () => {
const seen = new WeakSet();
return (_key: any, value: object) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
@dturton
dturton / workflow-example.ts
Created May 9, 2022 14:25
Deepkit workflow concept
import { createWorkflow, WorkflowEvent } from "@deepkit/workflow";
import { eventDispatcher, EventDispatcher } from "@deepkit/event";
import { ConsoleTransport, Logger } from "@deepkit/logger";
import { InjectorContext, InjectorModule } from "@deepkit/injector";
import { BrokerDirectClient, BrokerKernel } from "@deepkit/broker";
class EndEvent extends WorkflowEvent {
completed: boolean = true;
}
@dturton
dturton / paramstoObj.js
Last active October 20, 2021 15:25
URL parameters to a JavaScript object
const toParameterObject = (search) =>
JSON.parse(
'{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
(key, value) => (key === "" ? value : decodeURIComponent(value))
);
@dturton
dturton / array_reduce_group_by.js
Created December 28, 2020 16:33
Javascript array reduce group by -- ES6
const groupByKey = (list, key) => list.reduce((hash, obj) => ({...hash, [obj[key]]:( hash[obj[key]] || [] ).concat(obj)}), {})
@dturton
dturton / index.js
Created November 23, 2020 17:25 — forked from vladgovor77771/index.js
Queue arena based on bullmq. Allows chaining jobs.
const { Queue, QueueEvents } = require('bullmq');
const { EventEmitter } = require('events');
const config = require('../config');
const createUid = require('uid');
class QueueArena extends EventEmitter {
constructor({ redisDb = 1 }) {
super();
this.redisDb = redisDb;
@dturton
dturton / arrayofnumbers.js
Created March 4, 2020 15:57
Javascript create array of x numbers
Array.from(Array(10).keys())
import client from "../client";
import CA from "../CA";
export const handle = async function() {
try {
const response = await CA.get(
"Orders?$expand=Items($select=Sku,Quantity),CustomFields&exported=false&$filter=Fulfillments/Any (c: c/DistributionCenterID eq 2) and ShippingStatus eq 'Unshipped' and CreatedDateUtc ge 2020-01-12"
);
const promises = response.data.value
import client from "../client";
import CA from "../CA";
export const handle = async function() {
try {
const response = await CA.get(
"Orders?$expand=Items($select=Sku,Quantity),CustomFields&exported=false&$filter=Fulfillments/Any (c: c/DistributionCenterID eq 2) and ShippingStatus eq 'Unshipped' and CreatedDateUtc ge 2020-01-12"
);
const promises = response.data.value