Skip to content

Instantly share code, notes, and snippets.

View ThomasBurleson's full-sized avatar

Thomas Burleson ThomasBurleson

View GitHub Profile
@ThomasBurleson
ThomasBurleson / git-flat-commit-history.md
Last active February 23, 2020 16:04
Git - Benefits of Flat Commit History

Flawed Commit Strategy

Developers often want to condense their git log output. However without a proper git commit strategy (and conventions), those condensed outputs are still flawed.

For details on condensed git log outputs, see Improve your Git Log Output

Consider a git lg output for a typical project:

image

export interface ResponseError = [any, Error];	// Tuple to return either 

/**
 * special promise trap to build tuple of reponse and error
 */
const trap = (promise): Promise<ResponseError> => {  
  return promise
 .then(data =&gt; ([data, undefined]))
@ThomasBurleson
ThomasBurleson / books-page.component.ts
Last active December 28, 2019 17:03
Compressing View Logic with Facades
/**
*
* Snippet from blog article: https://auth0.com/blog/ngrx-facades-pros-and-cons/
*
*/
@Component({
selector: 'abl-books-page',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
@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 / BarChart.js
Last active October 9, 2019 15:13
Reusable Chart component for D3 - using prototypes and factories
(function() {
// Based on article @ http://www.toptal.com/d3-js/towards-reusable-d3-js-charts
// Publish a factory method for Chart instances
// @usage:
// var runningChart = BarChart.instanceOf( {barPadding : 2 } );
// var weatherChart = BarChart.instanceOf()
// .fillColor('coral');
window.BarChart = {
<!-- wInViewRoot directive is needed to specify the `root` for `IntersectionObserver` and some other it's options e.g. `margin` -->
<div class="container" wInViewRoot="viewport">
Any content can be here
<w-in-view-item>
<!-- Content will be replaced by a placeholder <div> with the same height as original content.
Also `InViewItemComponent`s change detector will be detached when it become invisible which means
all the content's change detectors won't be reachable and will be inactive as well. -->
</w-in-view-item>
...or any other content can be here
<w-in-view-item>
@ThomasBurleson
ThomasBurleson / log.operator.ts
Last active January 11, 2019 14:04
Using custom RxJS log() operator
export function log(task: string) {
const announceCompleted = () => {
console.log(`${task} %ccomplete`, 'color: green');
};
return function<T>(source: Observable<T>) {
return source.pipe(
tap(
console.log,
console.error,
announceCompleted
@ThomasBurleson
ThomasBurleson / gist:941711
Created April 26, 2011 02:52
Supplant for AS3 [no more StringUtils.substitute]
package utils.string
{
/**
* Replaces all tokenized fields in target with field values from
* the fields datasource. With this routine, the mx StringUtils.substitute
* is no longer needed to achieve printf() functionality.
*
* Supplant is more powerful since it can resolve (on-demand) property chains
* when used as fields; e.g. user.name (as shown below).
*
@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',