Skip to content

Instantly share code, notes, and snippets.

View bbrown's full-sized avatar

Bill Brown bbrown

View GitHub Profile
var player = document.createElement('audio');
player.src = 'data:audio/mp3;base64,SUQzAgAAAAAQO1RUMgAACgB0cm9tYm9uZQBDT00AABAAZW5naVR1blBHQVAAMAAAVEVOAAAPAGlUdW5lcyAxMC42LjEAQ09NAABoAGVuZ2lUdW5OT1JNACAwMDAwMEEzRSAwMDAwMEFCQiAwMDAwMjk3MCAwMDAwMkI5RCAwMDAwMDFCQyAwMDAwMDFCQyAwMDAwNzdDQyAwMDAwN0FDQyAwMDAwMDFCQyAwMDAwMDFCQwBDT00AAIIAZW5naVR1blNNUEIAIDAwMDAwMDAwIDAwMDAwMjEwIDAwMDAwN0M2IDAwMDAwMDAwMDAwMjk5MkEgMDAwMDAwMDAgMDAwMTVCQzIgMDAwMDAwMDAgMDAwMDAwMDAgMDAwMDAwMDAgMDAwMDAwMDAgMDAwMDAwMDAgMDAwMDAwMDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
@bbrown
bbrown / keybase.md
Created August 14, 2014 21:12
Keybase verification

Keybase proof

I hereby claim:

  • I am bbrown on github.
  • I am bbrown (https://keybase.io/bbrown) on keybase.
  • I have a public key whose fingerprint is 920C A521 90DF 388D 4DF3 7150 786D 1268 5515 5268

To claim this, I am signing this object:

@bbrown
bbrown / jsdateformat
Created December 1, 2014 17:38
Formatting function for dates in JS (for those times when Moment.js isn't feasible)
function yyyymmddhhmm(date)
{
// Modified from http://stackoverflow.com/a/3067896/20595
var yyyy = date.getFullYear().toString();
var mm = (date.getMonth()+1).toString(); // getMonth() is zero-based
var dd = date.getDate().toString();
var hh = date.getHours().toString();
var min = date.getMinutes().toString();
return yyyy + (mm[1]?mm:"0"+mm[0]) + (dd[1]?dd:"0"+dd[0]) + (hh[1]?hh:"0"+hh[0]) + (min[1]?min:"0"+min[0]); // padding
};
@bbrown
bbrown / must-be-third-friday
Created March 12, 2015 16:10
Angular directive and service that validates that a particular date is on the third Friday of the month
angular.module("theModuleName").directive("mustBeThirdFriday", function(timeService)
{
return {
require: "ngModel",
link: function(scope, element, attrs, ngModel)
{
ngModel.$validators.mustBeThirdFriday = function(modelValue)
{
return timeService.isThirdFriday(new Date(modelValue + " 0:00"));
};
@bbrown
bbrown / meta-filter
Created March 20, 2015 18:51
Angular filter to dynamically call another filter
angular.module("app").filter("meta", function($filter)
{
return function()
{
var filterName = [].splice.call(arguments, 1, 1)[0] || "filter";
var filter = filterName.split(":");
if (filter.length > 1)
{
filterName = filter[0];
for (var i = 1, k = filter.length; i < k; i++)
@bbrown
bbrown / percentage
Created March 20, 2015 18:54
Angular filter to format a percentage
angular.module("app").filter("percentage", ["$filter", function($filter)
{
return function(input, decimals, alreadyConverted)
{
var number = (alreadyConverted) ? input : input * 100;
return $filter("number")(number, decimals) + "%";
};
}]);
@bbrown
bbrown / ensmallen-number
Created March 20, 2015 18:55
Angular filter to convert a big number into a smaller one
angular.module("hedge").filter("ensmallenNumber", function()
{
return function(number)
{
var billion = 1000000000;
var million = 1000000;
if (number >= billion)
{
return number / billion + "B";
}
@bbrown
bbrown / custom-currency
Created March 20, 2015 18:56
Angular filter to replace parentheses with a negative and round big numbers
angular.module("app").filter("customCurrency", ["$filter", function($filter)
{
return function(amount, currencySymbol, fractionSize)
{
var currency = $filter("currency");
if (Math.abs(amount) > 1000)
{
fractionSize = 0;
amount = Math.round(amount);
}
@bbrown
bbrown / exception-decorator
Created April 21, 2015 19:59
Angular decorator to handle unhandled exceptions, if necessary.
// All unhandled exceptions in an AngularJS application are passed to a service $exceptionHandler,
// which logs the error message in the browser's console. In large business applications, you may want
// to log the error details on the server by calling an API. This can be done by decorating the $exceptionHandler service.
// #49 - http://www.dotnetcurry.com/showarticle.aspx?ID=1115
app.config(function($provide)
{
$provide.decorator('$exceptionHandler', ['$log', '$http', '$delegate', function ($log, $http, $delegate)
{
return function (exception, cause)
{
(function () {
var root = angular.element(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) {
if (element.data() && element.data().hasOwnProperty(scopeProperty)) {
angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) {
watchers.push(watcher);