Skip to content

Instantly share code, notes, and snippets.

View ThomasBurleson's full-sized avatar

Thomas Burleson ThomasBurleson

View GitHub Profile
@ThomasBurleson
ThomasBurleson / refactor_6.md
Last active October 2, 2023 06:28
Best Practices: Using Permissions as BitFlags

💚 Best Practices: Use Permissions as BitFlags

Developers often miss the opportunity to express permissions as a collection of enumerated bitflags; where complex permissions can be easily grouped by context.

Consider the scenario where a user may have 30 or more permission flags.


Improved Version 😄:

@ThomasBurleson
ThomasBurleson / refactor_4.md
Last active December 5, 2019 15:05
Refactor #4: RxJS Memory Leaks, Zombie Subscriptions, & Errors

💚 Best Practices: Avoid 3 Common RxJS Issues

Bad-RxJS Issues

Developers often find scenarios where they are compelled to manaully subscribe to Observables in View components; these scenarios do not use the async pipe levels of manual subscription management. These manual subscriptions can lead to:

  • Observables + memory leaks, and
  • Zombie subscriptions
@ThomasBurleson
ThomasBurleson / untilDestroyed.ts
Last active April 18, 2023 07:47
Using untilViewDestroyed to link component ngOnDestroy to observable unsubscribe.
/**
* When manually subscribing to an observable in a view component, developers are traditionally required
* to unsubscribe during ngOnDestroy. This utility method auto-configures and manages that relationship
* by watching the DOM with a MutationObserver and internally using the takeUntil RxJS operator.
*
* Angular 7 has stricter enforcements and throws errors with monkey-patching of view component life-cycle methods.
* Here is an updated version that uses MutationObserver to accomplish the same goal.
*
* @code
*
@ThomasBurleson
ThomasBurleson / tickets.facade.md
Last active February 22, 2024 07:41
Using ngrx with Effects + Facades

NgRx State Management with TicketFacade

Facades are a programming pattern in which a simpler public interface is provided to mask a composition of internal, more-complex, component usages.

When writing a lot of NgRx code - as many enterprises do - developers quickly accumulate large collections of actions and selectors classes. These classes are used to dispatch and query [respectively] the NgRx Store.

Using a Facade - to wrap and blackbox NgRx - simplifies accessing and modifying your NgRx state by masking internal all interactions with the Store, actions, reducers, selectors, and effects.

For more introduction, see Better State Management with Ngrx Facades

@ThomasBurleson
ThomasBurleson / es6-curry.md
Created December 18, 2017 12:41 — forked from JamieMason/es6-partial-application.md
ES6 Curry Function

ES6 Curry Function

const curry = (fn, ...cache) => (...args) => {
  const all = cache.concat(args);
  return all.length >= fn.length ? fn(...all) : curry(fn, ...all);
};

Example

@ThomasBurleson
ThomasBurleson / REST Anti-Patterns.md
Last active August 8, 2018 15:23
Demonstration of classic REST service anti-pattern

Typical coding example for a sequence of asynchronous REST calls:

function update(ev, updateDiff) {
  // get current event from Back End
  return scheduleService.getEvent(ev.id).then(function(event) {
    // send updates to Back end
    return scheduleService.editEvent(ev.id, event.version, updateDiff).then(function(evt) {
 var pack = findAircraftPackById(evt.aircraft.id);
@ThomasBurleson
ThomasBurleson / gist:072c194a8142d93154b480bd0c17d96a
Created October 21, 2017 22:05 — forked from jenkek/gist:8553579
How to: Delete a remote Git tag
# remove local tag
git tag -d tagname-123
# remove remote tag
git push origin :refs/tags/tagname-123
# delete multiple tags by patterns
for tag in $(git tag -l '[production|tusur]*'); do git tag -d $tag; git push origin :refs/tags/$tag; done
@ThomasBurleson
ThomasBurleson / ngInterview.md
Last active February 2, 2021 17:40
Angular Interview Questions

The interview questions below are grouped by category and each category lists questions in easy-to-hard order.

Interviews should ask the candidate to self-assess their skills/experience. Based on the candidate's response, the interviewer can jump to the appropriate section.

Some basic questions going from easy to difficult. A more exhaustive list of more questions from the community can be found here.

JavaScript

  • What is variable shadowing
@ThomasBurleson
ThomasBurleson / switchMap_example.ts
Last active December 13, 2018 19:04
Compare switchMap() to nested subscribe calls.
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {ContactsService} from '../contacts.service';
import {Contact} from '../models/contact';
import 'rxjs/add/operator/switchMap';
import {Subscription} from 'rxjs';
@Component({
selector: 'trm-contacts-detail',