Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Working from home

Tom jsdevtom

👨‍💻
Working from home
View GitHub Profile
@jsdevtom
jsdevtom / recursify-onto.type.ts
Last active Aug 30, 2019
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
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 Dec 1, 2020
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 Nov 17, 2020
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 Jul 29, 2018
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 Apr 16, 2018
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 Mar 31, 2019
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";
You can’t perform that action at this time.