Skip to content

Instantly share code, notes, and snippets.

View livingston's full-sized avatar

Livingston Samuel livingston

View GitHub Profile
/* Parses JSON with function body as a string into JavaScript object */
var parseJSONwithFunctions = function (JSONdata) {
var root = document.documentElement,
sandbox = document.createElement('script'),
code = "var fn = {", i;
for (i in JSONdata) {
if( JSONdata.hasOwnProperty(i) ) {
code += i + " : " + JSONdata[i] + ",";
function getTarget (e) {
var targ;
e = e || window.event;
targ = e.target || e.srcElement;
return (targ.nodeType == 3)? targ.parentNode : targ;
}
@livingston
livingston / render_frame.js
Created July 12, 2011 21:55
Beautified render_frame.js
(function() {
function i(a) {
throw a;
}
var j = void 0,
q = null,
s;
function aa(a) {
this.t = {};
this.tick = function(a, c, d) {
<!DOCTYPE html>
<!-- Helpful things to keep in your <head/>
// Brian Blakely, 360i
// http://twitter.com/brianblakely/
-->
<head>
<!-- Disable automatic DNS prefetching.
@livingston
livingston / EventMonitor.js
Created September 30, 2011 12:20
Element event monitor, similar to Web Inspector's `monitorEvents`
(function (global) {
if ( !global.Event && !('keys' in Object) && !('bind' in Function) ) { return }
var eventProto = Event.prototype,
EVENTS = {
'mouse': [ 'click', 'dblclick', 'contextmenu', 'mousedown', 'mouseup', 'mouseover', 'mousemove', 'mouseout', 'drag', 'dragend', 'dragenter', 'dragleave', 'dragover', 'drop'],
'key': [ 'keydown', 'keypress', 'keyup', 'input'],
'res': [ 'load', 'unload', 'beforeunload', 'abort', 'error', 'resize', 'scroll', 'readystatechange' ],
'form': [ 'select', 'change', 'submit', 'reset', 'focus', 'blur' ],
'ui': [ 'DOMFocusIn', 'DOMFocusOut', 'DOMActivate', 'DOMCharacterDataModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMSubtreeModified' ],
@livingston
livingston / index.html
Last active October 13, 2015 11:28 — forked from mbostock/.block
World Countries — http://bl.ocks.org/livingston/4188825
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.country {
fill: #b8b8b8;
stroke: #fff;
stroke-width: .5px;
stroke-linejoin: round;
}

The first 15 seconds of the D3 show reel. See full video at http://vimeo.com/29862153. Includes seamless transitions between the following visualization types:

  • lines
  • horizons
  • areas
  • stacked areas
  • streamgraph
  • overlapping areas
  • grouped bars
  • stacked bars
@livingston
livingston / readme.md
Last active September 12, 2022 22:10
Vanilla JavaScript Templates

Usage

var welcome_user = new Template('#{welcome} #{name}!!');

welcome_user.parse({ welcome: "Hello", name: "John" });
//returns "Hello John!!"

welcome_user.parse({ welcome: "Hola", name: "Peter" });
(function(){
var canvas = document.getElementById('hexmap');
var hexHeight,
hexRadius,
hexRectangleHeight,
hexRectangleWidth,
hexagonAngle = 0.523598776, // 30 degrees in radians
sideLength = 36,
boardWidth = 10,
@livingston
livingston / getAllFontSizes.js
Last active August 29, 2015 14:06
Get the list of all different font sizes on a page.
//requires jQuery & lodash
(function getAllFontSizes (fontSizes) {
$('*').each(function (i, n, s) { s = getComputedStyle(n)['font-size']; (s !== '0px') && fontSizes.push(s) });
console.log(_.chain(fontSizes).uniq().sortBy(function (v) { return parseInt(v, 10); }).join(', ').value());
}([]));