Skip to content

Instantly share code, notes, and snippets.

Dashboard.Format = {
types: {
bytes: ['b', 'kb', 'MB', 'GB', 'TB', 'PB'],
integer: ['', 'K', 'M', 'B', 'T', 'P']
},
abbreviate: function(metric, value){
var i = value ? Math.floor(Math.log(value)/Math.log(metric.devisor)) : 0;
return (value/Math.pow(metric.devisor, Math.floor(i))).round(2).format({
group: ',',
@fat
fat / gist:859445
Created March 7, 2011 22:58
make this better.
function __tailingFn () {
for (var i = arguments.length; i--;) {
if (typeof arguments[i] == 'function') {
var fn = arguments[i];
arguments[i] = undefined;
return fn;
}
}
}
/* this shit is the dumb... ignore pls */
function clone(obj){
if(obj == null || typeof(obj) != 'object')
return obj;
var temp = {};
for(var key in obj) temp[key] = clone(obj[key]);
return temp;
}
@fat
fat / gist:956180
Created May 4, 2011 22:28
better contains
var ALEX = ['foo', 'bar'];
//n00bs write:
if (ALEX.indexOf('foo') > -1) {
//ALEX contains foo
}
//pros write:
if (~ALEX.indexOf('foo')) {
//ALEX contains foo
@fat
fat / gist:1217433
Created September 14, 2011 18:55
tabs with history support
/* ========================================================
* bootstrap-tabs.js v1.3.0
* http://twitter.github.com/bootstrap/javascript.html#tabs
* ========================================================
* Copyright 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@fat
fat / gist:1407045
Created November 29, 2011 23:03
Async Loading
!function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (!d.getElementById(id)) {
js = d.createElement(s); js.id = id;
js.src = "//script.js";
fjs.parentNode.insertBefore(js, fjs);
}
}(document, "script", "uniqueID")
@fat
fat / gist:1484342
Created December 16, 2011 03:39
Simple Template
<div class="timeline">
<!-- load more button -->
<button>{{message}}</button>
<!-- tweet object -->
{{#tweets}}
{{> tweet}}
{{/tweets}}
@fat
fat / gist:1575714
Created January 7, 2012 19:23 — forked from sayrer/gist:1504888
Rendering
// require hogan
var hogan = require("hogan.js");
// compile template
var template = hogan.compile("@{{name}}");
var team = ['dhg', 'fat', 'jimio', 'nickgreen', 'sayrer'];
team.map(function (twitterer) {
@fat
fat / index.js
Created January 12, 2012 17:43
Bootstrap Build Server
// ========================================================================
// bootstrap-builder v0.1.0
// http://twitter.github.com/bootstrap
// ========================================================================
// Copyright 2011 Twitter, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
@fat
fat / gist:1933910
Created February 28, 2012 17:44
Looping using Recursive Guards in LESS
.spanX (@gridColumns) when (@gridColumns = 0) {}
.spanX (@gridColumns) when not (@gridColumns = 0) {
.span1 { .span(@gridColumns); } // need to find out a way to change .span1 into ".span@{gridcolumns}"
#grid .spanX(@gridColumns - 1);
}
.spanX(12); // this actually works