Skip to content

Instantly share code, notes, and snippets.

View jsdevtom's full-sized avatar
👨‍💻
Working from home

Tom jsdevtom

👨‍💻
Working from home
View GitHub Profile
@jsdevtom
jsdevtom / DebugFormControl.ts
Created April 4, 2024 15:06
Angular Debug Form Control
// @ts-ignore
class DebugFormControl<T> extends FormControl<T> {
// @ts-ignore
override get pristine(): boolean {
return this._pristine;
}
override set pristine(value: boolean) {
this._pristine = value;
}
@jsdevtom
jsdevtom / PaypalWebhookVerifierExample.cs
Last active November 14, 2023 19:17
The solution to getting Paypal's verify endpoint to work was to serialize JSON manually like so:
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
/**
* 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
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 August 29, 2024 11:49
kubernetes-ingress websockets with nodejs
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.

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
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.
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
import {
trigger,
state,
style,
animate,
transition
} from '@angular/animations';
import { AnimationEntryMetadata } from "@angular/core";