Skip to content

Instantly share code, notes, and snippets.

View kennethlynne's full-sized avatar

Kenneth Lynne kennethlynne

View GitHub Profile
@kennethlynne
kennethlynne / angular-mock-backend.js
Created November 15, 2013 23:07
Mock back-end for angular for prototyping
angular.module('APP')
.config(function($provide) {
//Decorate backend with awesomesauce
$provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator);
})
.run(function ($httpBackend) {
//Pass trough views
var viewsDir = 'views/';
var viewsDirRegex = new RegExp(viewsDir.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"));
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
@kennethlynne
kennethlynne / angular-mock-backend.js
Last active February 19, 2019 10:41
High fidelity prototyping using a mock back-end. Include angular-mocks in your script includes after angular. Demo: http://codepen.io/kennethlynne/pen/lJbce
'use strict';
angular.module('yourApp')
.constant('Config', {
viewDir: 'views/',
API: {
useMocks: true,
fakeDelay: 2000,
protocol: window.location.protocol.split(':')[0],
host: window.location.hostname,
@kennethlynne
kennethlynne / url-params-to-object-parser.js
Last active December 30, 2015 19:09
Helper to transform a string with url parameters into a matching key-value object. ?thing=a&stuff=b will result in params being set to {thing:a,stuff:b}
urlParams = "?thing=a&stuff=b";
var params = {};
//Match anything that has a sequence of word characters an equalsign until next block denoted by ? or &
urlParams = urlParams.match(/[\w]+\=[^\?\&]+/g);
angular.forEach(urlParams, function (match) {
var data = match.split('=');
var key = data[0], value = data[1];
params[key]=value;
@kennethlynne
kennethlynne / offset.js
Created January 19, 2014 21:17
AngularJS Pagination filter (offset)
angular.module('Pagination', [])
.filter('offset', function () {
return function (input, offset) {
return (input instanceof Array)
? input.slice(+offset)
: input
}
})
@kennethlynne
kennethlynne / angular-on-ready.js
Created February 24, 2014 13:52
Trigger event when angular has finished loading and $http has no pending requests
'use strict';
angular.module('theApp')
.directive('onReady', function ($rootScope, $http, $timeout) {
return {
restrict: 'A',
link: function ($scope) {
console.log('Waiting.');
var to;
@kennethlynne
kennethlynne / fake-delay.js
Created March 4, 2014 09:30
mock-backend fake delay
angular.module('yourApp')
.config(function ($httpProvider, Config) {
if(!Config.useMocks) return;
$httpProvider.interceptors.push(function ($q, $timeout, Config, $log) {
return {
'request': function (config) {
$log.log('Requesting ' + config.url, config);
return config;
@kennethlynne
kennethlynne / ui-sref-fastclick-decorator.js
Created October 2, 2014 15:06
A decorator to override uiSref to trigger state change on touchstart instead of click (to remove 300ms delay on touch screens)
'use strict';
// A decorator to override uiSref to trigger state change on touchstart if the element does not have disable-fastclick attribute
// It also logs the time between state changes
angular.module('app')
.config(function ($provide) {
$provide.decorator('uiSrefDirective', function ($delegate) {
var originalUiSref, originalUiSrefLink;
originalUiSref = $delegate[0];
originalUiSrefLink = originalUiSref.link;

Mac OS X 10.10 Yosemite

Custom recipe to get OS X 10.10 Yosemite running from scratch, setup applications and developer environment. I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. On average, I reinstall each computer from scratch every 6 months, and I do not perform upgrades between distros.

This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.

You are encouraged to fork this and modify it to your heart's content to match your own needs.

Install Software

@kennethlynne
kennethlynne / js-stack-trace.js
Last active August 29, 2015 14:09
DIY javascript stack trace
// Copied from http://helephant.com/2007/05/12/diy-javascript-stack-trace/ - read more about the approach there
Function.prototype.trace = function()
{
var trace = [];
var current = this;
while(current)
{
trace.push(current.signature());
current = current.caller;