Skip to content

Instantly share code, notes, and snippets.

View dhigginbotham's full-sized avatar
😸
happycat

David Higginbotham dhigginbotham

😸
happycat
View GitHub Profile

##Silly recursion Some of these may actually suprise you, they suprised me so much I felt the need to actually put this together in some fashion.

###Recursive Fib Can cute code win?

(function(n, w, t) {
  var fib = function(n,arr) { 
    if (!arr) { arr = [1,1]; n=n-2; };
var fib = function(n,arr) {
if (!arr) { arr = [1,1]; n=n-2; };
if (n==-1) return [arr[0]];
if (n==0) return arr;
arr.push(arr[arr.length-1] + arr[arr.length-2]);
return fib(n-1,arr);
};
fib(10);
@dhigginbotham
dhigginbotham / .alias
Created February 16, 2015 02:27
Alias taken from https://github.com/mathiasbynens/dotfiles that I use personally
# Detect which `ls` flavor is in use
if ls --color > /dev/null 2>&1; then # GNU `ls`
colorflag="--color"
else # OS X `ls`
colorflag="-G"
fi
# List all files colorized in long format
alias l="ls -lF ${colorflag}"
var supported = [
{
name: 'Html',
regex: /\.(html?)/gi
},{
name: 'Css',
regex: /\.(css)/gi
},{
name: 'Js',
regex: /\.(js)/gi
function parseQueryString() {
var params = {}, queries, temp, i, l;
var query = window.location.search;
var queryString = query.substring( query.indexOf('?') + 1 );
// Split into key/value pairs
queries = queryString.split("&");
// Convert the array of strings into an object
for ( i = 0, l = queries.length; i < l; i++ ) {
temp = queries[i].split('=');
var _ = require('lodash');
var bodyParser = require('body-parser');
function Rest(opts, app) {
//public options
this.prefix = '/api';
this.path = null;
this.key = 'collection';
this.preware = [];
@dhigginbotham
dhigginbotham / compileHtml.js
Created October 23, 2014 14:18
Angular likes to santize and escape all the things, this will help when you really need your api responses compiled as HTML
var app = app || {};
app.directive( 'compileHtml', ['$compile', '$sce',
function($compile, $sce) {
return {
scope: true,
link: function ( scope, element, attrs ) {
var el;
attrs.$observe( 'template', function ( tpl ) {
if ( angular.isDefined( tpl ) ) {
el = $sce.trustAsHtml(tpl);
var roles = {
optin: 1,
user: 3,
admin: 10
};
function canPlayRoleOf(user, role) {
if (roles.hasOwnProperty(role)) {
return (user.role >= roles[role] ? true : false);
} else {
@dhigginbotham
dhigginbotham / mockperf.js
Last active August 29, 2015 14:06
mockup perf tool
var perf = (function(root) {
var keys = [];
var i = -1;
// internal api
function setter() {
if (i > -1) {
keys[i].stop = new Date().getTime();
keys[i].dist = keys[i].stop - keys[i].start;
ErrorEvent {
error: ReferenceError,
colno: 7,
lineno: 8,
filename: "..path/to/file.js",
message: "Uncaught ReferenceError: foobar is not defined"
}