Skip to content

Instantly share code, notes, and snippets.

View ahuggins-nhs's full-sized avatar

Aaron Huggins ahuggins-nhs

View GitHub Profile
@ahuggins-nhs
ahuggins-nhs / curls.it
Created March 31, 2021 21:35
Dummy curls test
console.log(`\
hi deno user!
how to use:
go to curls.it
paste file, using 'typescript' (or 'javascript') as file type
copy url
deno run -A <url here>`);
@ahuggins-nhs
ahuggins-nhs / DeepOmit.d.ts
Last active May 4, 2023 16:41
Deeply omit members of an interface or type
// Taken from https://stackoverflow.com/questions/55539387/deep-omit-with-typescript
/** Union of primitives to skip with deep omit utilities. */
type Primitive = string | Function | number | boolean | Symbol | undefined | null
/** Deeply omit members of an array of interface or array of type. */
export type DeepOmitArray<T extends any[], K> = {
[P in keyof T]: DeepOmit<T[P], K>
}
function foldIntoParentCB (result, objectResult, propertyName, objectName) {
if (propertyName === 'order' && objectName === 'Order') {
const {
externalOrderId,
shippingIntegrationId,
orderIntegrationId
} = objectResult
result.externalOrderId = externalOrderId
result.shippingIntegrationId = shippingIntegrationId
@ahuggins-nhs
ahuggins-nhs / fieldMapper.js
Last active August 18, 2020 14:41
A field-to-property mapping utility
class FieldMap {
/**
* @param {string} fieldName
* @param {string} propertyName
* @param {string} objectName
* @param {boolean} [active=false]
*/
constructor (fieldName, propertyName, objectName, active = false) {
/**
* @private
function typeOf (val) {
let typeDef = typeof val
console.log('init:', typeDef)
if (typeDef === 'object' || typeDef === 'function') {
console.log('obj/func:', typeDef)
typeDef = Object.prototype.toString.call(val)
typeDef = typeDef.substring(8, typeDef.length - 1)
}
if (typeDef === 'Object' || typeDef === 'Array') {
ahuggins@ahuggins-Virtual-Machine:~/development/libas2$ echo Something to Sign > 'test/temp-data/payload'
ahuggins@ahuggins-Virtual-Machine:~/development/libas2$ openssl dgst -sha256 -hex 'test/temp-data/payload'
SHA256(test/temp-data/payload)= 7c9088b617877e116179ad489377392ad961b5f80709d7e135ada4765d8c54cf
ahuggins@ahuggins-Virtual-Machine:~/development/libas2$ openssl asn1parse -inform DER -in 'test/temp-data/signature-cms.bin' 0:d=0 hl=4 l=1414 cons: SEQUENCE
4:d=1 hl=2 l= 9 prim: OBJECT :pkcs7-signedData
15:d=1 hl=4 l=1399 cons: cont [ 0 ]
19:d=2 hl=4 l=1395 cons: SEQUENCE
23:d=3 hl=2 l= 1 prim: INTEGER :01
26:d=3 hl=2 l= 13 cons: SET
28:d=4 hl=2 l= 11 cons: SEQUENCE
@ahuggins-nhs
ahuggins-nhs / getDataLayerObject.js
Created May 28, 2020 20:32
Get the data layer as an object from Google Tag Manager
var getDataLayerObject = function getDataLayerObject (gtmid) {
var keys = Object.keys(Object.assign(...dataLayer)) || []
var data = {}
keys.forEach(function (key) {
key = key.split(/\./gu)[0]
if (data[key] === undefined) data[key] = google_tag_manager[gtmid].dataLayer.get(key)
})
const jsforce = require('jsforce');
const jwt = require("salesforce-jwt-bearer-token-flow");
// create the connection to the org
let conn = new jsforce.Connection();
// load the private key for the token
let privateKey = require('fs').readFileSync('./server.key', 'utf8');
jwt.getToken({
@ahuggins-nhs
ahuggins-nhs / nodejs_worker_threads.d.ts
Created March 16, 2020 18:51 — forked from rsms/nodejs_worker_threads.d.ts
NodeJS worker_threads TypeScript typings
declare module "worker_threads" {
export var isMainThread: bool
export var parentPort: null | MessagePort
export var threadId: int
export var threadId: int
export var workerData: any
export interface Worker {
readonly threadId: int
readonly stdin: stream.Writable | null