Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Burleson ThomasBurleson

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

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

View Tuples with Async-Await.md
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 Dec 28, 2019
Compressing View Logic with Facades
View books-page.component.ts
/**
*
* 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 Dec 5, 2019
Refactor #4: RxJS Memory Leaks, Zombie Subscriptions, & Errors
View refactor_4.md

💚 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 Oct 9, 2019
Reusable Chart component for D3 - using prototypes and factories
View BarChart.js
(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 = {
View angular-in-view-directives.html
<!-- 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 Jan 11, 2019
Using custom RxJS log() operator
View log.operator.ts
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 Apr 26, 2011
Supplant for AS3 [no more StringUtils.substitute]
View gist:941711
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 Dec 13, 2018
Compare switchMap() to nested subscribe calls.
View switchMap_example.ts
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',