Skip to content

Instantly share code, notes, and snippets.

View tw3's full-sized avatar

Ted Weatherly tw3

  • Austin, TX
View GitHub Profile
const { rxObserver } = require('api/v0.3');
const { Observable, ConnectableObservable, GroupedObservable, observable, Subject, BehaviorSubject, ReplaySubject, AsyncSubject, asapScheduler, asyncScheduler, queueScheduler, animationFrameScheduler, VirtualTimeScheduler, VirtualAction, Scheduler, Subscription, Subscriber, pipe, noop, identity, isObservable, ArgumentOutOfRangeError, EmptyError, ObjectUnsubscribedError, UnsubscriptionError, TimeoutError, bindCallback, bindNodeCallback, defer, empty, forkJoin, from, fromEvent, fromEventPattern, generate, iif, interval, never, of, pairs, range, throwError, timer, using, EMPTY, NEVER, config } = require('rxjs');
const { audit, auditTime, buffer, bufferCount, bufferTime, bufferToggle, bufferWhen, catchError, combineAll, combineLatest, concat, concatAll, concatMap, concatMapTo, count, debounce, debounceTime, defaultIfEmpty, delay, delayWhen, dematerialize, distinct, distinctUntilChanged, distinctUntilKeyChanged, elementAt, endWith, every, exhaust, exhaustMap, expand, fil
@tw3
tw3 / lint_modified_lines.js
Last active April 12, 2019 04:29
PR blocker script that returns outputs ESLint messages for lines that have been modified vs git master branch
const Git = require('nodegit');
const CLIEngine = require('eslint').CLIEngine;
/**
* Usage: node lint_modified_lines.js
*
* This script:
* 1. Determines the files and lines that have been added or changed compared to the master branch.
* 2. Runs eslint.
* 3. Filters the lint results to only the lines that have been added or changed.
@tw3
tw3 / list_references.ts
Last active July 26, 2019 18:00
Lists references of all properties in all classes in a file
/* tslint:disable:no-console */
/**
* Example usage: ts-node --project ./tsconfig-tsnode.json ./test_encapsulation.ts <some-file.ts>
*
* Example tsconfig-tsnode.json is at the bottom of this file
*/
import { ClassDeclaration, Project, PropertyDeclaration, ReferencedSymbol, ReferenceEntry, SourceFile } from 'ts-morph';
function main(fileNameOrPath: string): void {
@tw3
tw3 / interceptor-request-config-serializer.ts
Last active November 15, 2019 19:00
Serializer that stores and pulls a generic configuration object from the HttpHeader instance so as to configure an interceptor on a per-request basis
import { HttpHeaders, HttpRequest } from '@angular/common/http';
import { isNullOrUndefined } from '../../util/misc-util';
import { HttpClientHeaders, HttpClientOptions } from './http-client-options';
/**
* Unfortunately Angular does not provide a way to pass metadata/configs into interceptors so
* we have to do it ourselves.
*
* https://github.com/angular/angular/issues/18155
*/
@tw3
tw3 / error-notification-interceptor-config.ts
Created November 15, 2019 19:02
Example usage of InterceptorRequestConfigSerializer to ignore certain response status codes for a request
import { HttpRequest } from '@angular/common/http';
import { isNullOrUndefined } from '../../util/misc-util';
import { isPositiveInteger } from '../../util/num-util';
import { InterceptorRequestConfigSerializer, PullInterceptorConfigResult } from '../entities/interceptor-request-config-serializer';
import { HttpClientOptions } from '../entities/http-client-options';
export interface ErrorNotificationInterceptorConfig {
ignoredResStatusCodes: number[];
}
@tw3
tw3 / protractor-download-helper.ts
Last active January 28, 2022 17:56
Helps read and compare files downloaded during a protractor e2e test
// <project_root>/e2e/protractorDownloads/protractor-download-helper.ts
import { browser } from 'protractor';
const fs = require('fs');
const path = require('path');
export class ProtractorDownloadHelper {
private readonly maxReadWaitTime = 10000; // 10 seconds
@tw3
tw3 / README.md
Last active April 6, 2020 18:53
Git pre-commit and pre-push hooks to avoid committing to master or release branches

Git pre-commit and pre-push hook

It will check if current branch is master or a release branch and, if so, prevents a commit or push

To install

  1. Enable git templates
    git config --global init.templatedir '~/.git-templates'
    
@tw3
tw3 / session-expire-alarm.service.ts
Created June 30, 2020 14:07
Service that creates and maintains an alarm that can trigger session timeout warnings and session expiration events
import { Injectable } from '@angular/core';
import {
EMPTY,
merge as observableMerge,
Observable,
of as observableOf,
Subject,
timer as observableTimer
} from 'rxjs';
import { delay, expand, map, takeUntil, takeWhile } from 'rxjs/operators';
@tw3
tw3 / monitor-active-requests.ts
Last active July 9, 2020 11:52
RxJS operator that keeps a running counter of the number of active requests
import { defer, Observable, ObservableInput } from 'rxjs';
import { finalize } from 'rxjs/operators';
/**
* This is an RxJS operator that keeps a running counter of the number of active requests.
* This can be used to show a spinner for the first of a series of requests, and hide the spinner
* once all requests in the series are complete.
*
* For example:
* const activeRequestMonitor: ActiveRequestMonitor = monitorActiveRequests({
/**
* Example:
*
* const builder = new XPathBuilder();
* const xpathStr = builder
* .addDescendant({ nodeName: 'carbon-dropdown' })
* .addDescendant({ className: 'bx--label', innerText: 'AWS Region' })
* .addAncestor({ nodeName: 'carbon-dropdown' })
* .build();
*