Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Working from home

Tom jsdevtom

👨‍💻
Working from home
View GitHub Profile
@jsdevtom
jsdevtom / PaypalWebhookVerifierExample.cs
Last active April 7, 2023 17:55
The solution to getting Paypal's verify endpoint to work was to serialize JSON manually like so:
View PaypalWebhookVerifierExample.cs
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@jsdevtom
jsdevtom / recursify-onto.type.ts
Last active August 30, 2019 04:34
Recursifies an object on to another object in Typescript
View recursify-onto.type.ts
/**
* T: The normal object to apply O to at every nested object
*
* @example
export const OBJECT_ID = Symbol('_objectId');
export interface IHasOBJECT_ID {
[OBJECT_ID]: UUID;
}
@jsdevtom
jsdevtom / deep-equals.ts
Created May 18, 2019 14:42
fast deep equals in TypeScript
View deep-equals.ts
const isArray = Array.isArray;
const keyList = Object.keys;
const hasProp = Object.prototype.hasOwnProperty;
export function isDeeplyEqual<T extends any>(a: T, b: T): boolean {
if (a === b) { return true; }
if (a && b && typeof a === 'object' && typeof b === 'object') {
const arrA = isArray(a)
@jsdevtom
jsdevtom / frontend-ws-connection.ts
Last active June 8, 2023 14:13
kubernetes-ingress websockets with nodejs
View frontend-ws-connection.ts
export const ws = webSocket<WebsocketMessage>(`wss://${location.hostname}:${location.protocol === 'https:' ? 443 : 80}/ws/`);
export const wsObserver = ws
.pipe(
retryWhen(errors =>
errors.pipe(
delay(1000)
)
)
);
@jsdevtom
jsdevtom / README.md
Last active February 6, 2021 13:09
Angular 2 4 5 6 +: Find out if FormControl has required validator with Angular Material example.
View README.md

Although this pipe is impure, it uses a "Blazing fast" hash in order to check if the AbstractControl has changed at all before calculating whether or not the AbstractControl has a required field.

You will need to install hash-sum like so:

npm i -S hash-sum

@jsdevtom
jsdevtom / index.ts
Created July 29, 2018 14:43
Connect to MongoDB from Google Cloud function best practice through Maintaining Persistent Connections
View index.ts
import {CustomError} from "./error/custom-error.interface";
require('dotenv').config();
import {RequestHandler} from 'express';
import {MongoClient} from 'mongodb';
let client: MongoClient;
const connectToClientIfDropped: () => Promise<void> = async () => {
if (client && client.isConnected()) {
@jsdevtom
jsdevtom / upper-case-node-transform.js
Last active April 16, 2018 03:25
A simple implementation of a node.js transformer class in ES6.
View upper-case-node-transform.js
const {Transform} = require('stream')
class UpperCase extends Transform {
_transform (chunk, encoding, done) {
done(null, chunk.toString().toUpperCase())
}
}
module.exports = UpperCase
@jsdevtom
jsdevtom / app-routing.animation.ts
Last active December 23, 2022 17:09
Fade out angular 2 loading page/ Fade in first angular 2 component
View app-routing.animation.ts
import {
trigger,
state,
style,
animate,
transition
} from '@angular/animations';
import { AnimationEntryMetadata } from "@angular/core";