This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to purge a queue | |
purge_queue() { | |
queue_name="$1" | |
echo "Purging queue: $queue_name" | |
docker exec CONTAINER_NAME rabbitmqadmin -u USER -p PWD -H 0.0.0.0 -P MANAGEMENT_PORT purge queue name="$queue_name" > /dev/null | |
} | |
# Fetch all queues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/questions/22944631/how-to-get-the-ip-address-of-the-docker-host-from-inside-a-docker-container | |
docker run -it --rm alpine nslookup host.docker.internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zx | |
# usage | |
#./keys-to-enum.mjs "{ 220ms Thu Aug 25 11:04:52 2022 | |
# attributeName, | |
# fieldName, | |
# fullyQualifiedName, | |
# attributeType, | |
# scannerTypeGroup, | |
# }: GetRecordFindingsDto" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Constrained Identity Function | |
- Use Case: We want to create a Record with a limited set of Keys, and a defined type of Values. | |
- We also don't want to Type the Set of Keys, but leverage TypeScript inference instead (DRY) | |
- If we create a new inline object literal, TypeScript will prevent any new key from being added, by won't enforce the type of the Values. | |
- So Narrow Keys, Wide Value Type | |
- If we specify the type Record<string, number>, we'll be able to add any new Key after the object creation | |
- So Wide Keys, Narrow Value Type | |
- By using a Types Identity Function, we can build an object with enforced Value Type, and Narrow set of Keys. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sort List of Objects By Two Keys | |
type SortKey<T> = { | |
key: keyof T; | |
order: 1 | -1; | |
}; | |
export function sortByKeys<T>(list: T[], keys: SortKey<T> | [SortKey<T>, SortKey<T>]) { | |
if (!Array.isArray(keys)) { | |
const { key: sortKey, order } = keys; | |
return list.sort((v1, v2) => (v1[sortKey] < v2[sortKey] ? order * 1 : -1 * order)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const keys = ['k1', 'k2', 'k3'] | |
const Keys = typeof keys[number] | |
type Object = { | |
k1: number, | |
k2: boolean | |
} | |
type KeyValue = { | |
[k in Keys]: k extends keyof Object ? Object[k] : unknown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as cluster from 'cluster'; | |
import * as os from 'os'; | |
import { Logger } from '@nestjs/common'; | |
export class Cluster { | |
static register(workers: number, logger: Logger, callback: CallableFunction): void { | |
const cpuCount = os.cpus().length; | |
if (cluster.isMaster) { | |
logger.log(`master process started on ${process.pid}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cypress.Commands.add('interceptOnce', (method, path, alias, status) => { | |
cy.intercept({ | |
method, | |
path, | |
times: 1, | |
}).as(alias); | |
if (status) { | |
return cy.wrap(() => | |
cy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getCurrentDateP(mongoConnection) { | |
const query = { _id: 1 }; | |
const update = { $currentDate: { updated_at: true } }; | |
const queryOptions = { upsert: true, returnOriginal: false }; | |
return mongoConnection | |
.collection('current_date') | |
.findOneAndUpdate(query, update, queryOptions) | |
.then(mongoResult => mongoResult.value.updated_at) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.catch((err: Error | AxiosError) { | |
if (axios.isAxiosError(error)) { | |
// Access to config, request, and response | |
} else { | |
// Just a stock error | |
} | |
}) |
NewerOlder