Skip to content

Instantly share code, notes, and snippets.

View austbot's full-sized avatar
😶‍🌫️

austbot austbot

😶‍🌫️
View GitHub Profile
uuid = require('./uuid')
merge = require('merge')
###*
# Renderable - Constructs a rederable object.
#
# @param {htmlElement} parent the parent element that the template needs to be rendered into.
# @param {handlebars_template} template a precompiles handlebars template
# @return {this}
###
Renderable = (parent, template, model) ->
@austbot
austbot / require_login.js
Created August 7, 2015 03:53
Require a login on a route easily.
//Define your route
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/private', {
templateUrl: 'privatePage.html',
controller: 'PrivateCtrl as ctrl',
requireLogin: true //Here is the extra attrbute
});
}])
// Where AuthService is your user / authentication service
@austbot
austbot / array_replace_recursive_user.php
Created November 27, 2015 22:34
Give two arrays(can be multi dimensional) that have the same structure of keys. Return a value of the two where array 2 raplaces the values of array 1 if the returned value of the specific callback is truthy.
function array_replace_uwalk($array1, $array2, $callbackArray)
{
$result = $array1;
array_walk($result, function (&$array1Item, $key) use ($array2, $callbackArray)
{
$array2Item = $array2[$key];
if (is_array($array1Item) && is_array($array1Item))
{
$array1Item = array_replace_uwalk($array1Item, $array2Item, $callbackArray);
}else{
@austbot
austbot / opbeat.js
Last active December 31, 2015 23:25
//Each one of these sections are places in different files being smashed together via babel/webpack. E2015 -> ES5 + PolyFill
//APP level route
$stateProvider
.state('app', {
url: '/',
templateUrl: 'app/app.html',
controller: 'AppController',
controllerAs: 'app',
resolve: {
curl 'https://intake.opbeat.com/api/v1/organizations/0e9e5728c4ad4cbb8f0e0048201b9504/apps/23cd35d823/client-side/errors/' -H 'Origin: http://localhost:3000' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H 'Referer: http://localhost:3000/' -H 'Connection: keep-alive' -H 'x-opbeat-client: opbeat-js/v1.2.3' --data-binary $'{"message":"SecurityError: Failed to set the \'domain\' property on \'Document\': \'bethel.tv\' is not a suffix of \'localhost\'.","culprit":"app/app.module.js","exception":{"type":"SecurityError","value":"Failed to set the \'domain\' property on \'Document\': \'bethel.tv\' is not a suffix of \'localhost\'."},"http":{"url":"http://localhost:3000/"},"stacktrace":{"frames":[{"filename":"bower_components/angular/angular.js","lineno":29013,"colno":5,"function":"<anonymous>","abs_p
@austbot
austbot / formatDuration.js
Created August 3, 2015 15:44
Format Moment Duration easily
function (duration, format) {
//Setup time
var hours = duration.hours(),
minutes = duration.minutes(),
seconds = duration.seconds();
//Iterate the format
formatStr = format;
//Replace format keys
formatStr = formatStr.replace(/hh:/, hours > 0 ? hours + ":" : '');
formatStr = formatStr.replace(/mm:/, minutes > 0 ? minutes + ":" : '');
import {Component, ViewEncapsulation, ElementRef, Inject, EventEmitter, Output, ViewChild} from 'angular2/core';
import {Input} from 'angular2/core';
import {ChangeDetectionStrategy} from 'angular2/core';
import {DatePipe} from 'angular2/common';
import {PlayerDurationPipe} from './playerDurationPipe';
import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';
import {Action} from '@ngrx/store';
import {FilmStrip} from './filmStrip/filmStrip';
export interface ScrubberHoverEvent {
@austbot
austbot / messages.pipe.ts
Created April 8, 2016 17:29
Angular 2 NgFor over an object. Specifically a firebase list.
import {Pipe, PipeTransform} from 'angular2/core';
import {Observable} from 'rxjs/Observable';
import * as R from 'ramda';
@Pipe({
name: 'messages'
})
/**
* Take an object that is key value id message and convert it to a array of ChatMessage throwing the id in the message.
*/
export class MessagesPipe implements PipeTransform {
import * as braintree from 'braintree-web';
import {Subject} from 'rxjs/Subject.js';
import 'rxjs/add/operator/do.js';
import 'rxjs/add/operator/filter.js';
import 'rxjs/add/operator/map.js';
import 'rxjs/add/operator/publish.js';
/**
* Abstract the setup of briantree hosted fields to simply give the form what it needs.
* @param $http
* @param $q
function flatten(arrInput) {
if(arrInput.length < 1 || !arrInput) return [];
var arr = [];
arrInput.map(function(e, index){
if(Array.isArray(e)) arr= arr.concat(flatten(e));
else arr.push(e);
});
return arr;
}