Skip to content

Instantly share code, notes, and snippets.


Brian Vaughn bvaughn

View GitHub Profile
bvaughn / $q-decorator
Last active Aug 29, 2015
Additional methods for $q
View $q-decorator
var qDecorator = function($delegate) {
* Similar to $q.reject, this is a convenience method to create and resolve a Promise.
* @param {Object} data Value to resolve the promise with
* @returns {Promise} A resolved promise
$delegate.resolve = function(data) {
var deferred = this.defer();
bvaughn / gist:0e178b3fe5ef916d0389
Last active Aug 29, 2015
Sample Task Runner script
View gist:0e178b3fe5ef916d0389

Here is a simple example showing how to use:


bvaughn / gist:23749a3464d94a162205
Last active Aug 29, 2015
Task Runner example script
View gist:23749a3464d94a162205

Here is a simple example showing how to use:

  • XHRTask to load data via an XML HTTP request.
  • ClosureTask to define a small task within the context of a larger task-flow.
  • DependencyGraphTask to define application flow with only a few lines of code.


    <script src="libs/task-runner/task-runner.js"></script>
bvaughn /
Last active Aug 29, 2015
forms-js validation schema (proposal 1)

Validation example for the form shown here:

Assuming all of the fields in the form you linked to are required, I'll start by showing what formFor validation rules would look like:

  name: {
    required: true
 age: {
bvaughn / gist:e363aa6c9c2e9e210787
Created Jul 12, 2015
JavaScript utility capable of highlighting elements matching CSS selector(s)
View gist:e363aa6c9c2e9e210787
var StyleMatcher = function() {
this.indicatorContainer_ = document.createElement('div');
StyleMatcher.DEFAULT_STYLES_ = {
position: 'absolute',
borderWidth: '1px',
borderStyle: 'solid',
bvaughn / gist:012fb525e6c819fdc9bf
Last active May 23, 2016
Debugging Angular bindings
View gist:012fb525e6c819fdc9bf

This afternoon I encountered a race condition in an Angular app I'm working on. Essentially my controller was pushing some values to an Array on its scope and something (I wasn't sure what) was asynchronously overriding the Array's contents. The Array was being used by a custom directive- written by someone else- as well as an ngModel and it wasn't clear who was making the change.

I ended up trying something I had not done before and it worked well enough that I thought I'd post it here in case it helped anyone else.

First I enabled The "Async" option in Chrome's "Sources > Call Stack" panel.

Next I set a breakpoint in my controller where I was modifying the Array. When I hit that breakpoint, I ran the following code in my console:

Object.observe(this.theArray, function(changes) {
View InfiniteLoader.example.js
/** @flow */
import React, { Component } from 'react'
import { ContentBox, ContentBoxHeader, ContentBoxParagraph } from '../demo/ContentBox'
import Immutable from 'immutable'
import InfiniteLoader from './InfiniteLoader'
import FlexTable from '../FlexTable/FlexTable'
import FlexColumn from '../FlexTable/FlexColumn'
function noop () {}
bvaughn /
Last active Apr 28, 2017
RE: Reddit Angular JS question "Advice on separating the logical parts of an application"

This gist is in response to a question asked on the Reddit Angular JS forum about how to structure an Angular app with roles and permissions.

There are many ways to approach this, but I'll share one that I've used before and maybe it will give you an idea. I'd combine all of the above into a single app and control who gets to see what using permissions. There are a few components to this approach...

A local session service

First off I'd advise creating some sort of local session management service. This should be able to track whether you have an authenticated user and- if so- what types of permissions that user has. (Lots of ways to manage permissions. I'll assume your user object has either a 'role' enum or something simple like an array of string permissions.) You could roll your own session service or you could check out something like satellizer.

Let's assume yo

View index.html
<!DOCTYPE html>
<meta charset="utf-8"/>
<title>js-search indexing</title>
<script src=""></script>
<script src="./suite.js"></script>
<h1>Open the console to view the results</h1>
bvaughn / babel-glamor-css-label-transform.js
Created Aug 22, 2017
Auto-generate css labels for Glamor components
View babel-glamor-css-label-transform.js
const hasLabelProperty = path =>
property => === "label"
const isGlamorAttribute = path => {
return === "css";
const getParentComponentName = path => {