Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

David Calhoun davidcalhoun

I may be slow to respond.
View GitHub Profile
davidcalhoun / simple-script-loader.js
Created January 4, 2020 18:51
simple script loader.js
View simple-script-loader.js
function initSyntaxHighlighting() {
// code
function loadScripts() {
const scripts = [
src: '',
callback: initSyntaxHighlighting
davidcalhoun / azimElevToXY.js
Last active November 21, 2019 04:57
satellite azim,elev to cartesian coords
View azimElevToXY.js
const elevToHypLength = (elev, canvasSize) => {
return canvasSize - (canvasSize * elev) / 89.99999999;
const deg2rad = deg => (Math.PI * 2 * deg) / 360;
const toFixedFloat = (num = 0, digitsAfterDecimal = 0) => parseFloat(num.toFixed(digitsAfterDecimal))
const getXY = (azim, elev, canvasSize) => {
const hyp = elevToHypLength(elev, canvasSize / 2);
View image-progress.js
/* Keeps track of x/y "progress" as the user mouses over an image */
imageElement.addEventListener('mousemove', e => {
const target =;
const rect = target.getBoundingClientRect();
const xProgress = Math.floor(((e.clientX - rect.x) / rect.width) * 100);
const yProgress = Math.floor(((e.clientY - rect.y) / rect.height) * 100);
/* 0,0 = mouse over top left of image, 100/100 = mouse over bottom right of image */
console.log(xProgress, yProgress);
}, false)
davidcalhoun / find-occurrances.js
Last active December 16, 2017 03:11
Find the most frequent occurrences in a list with JavaScript
View find-occurrances.js
// List of items to find occurrences in.
const list = ['Tom', 'Fluffy', 'Tom', 'Bella', 'Chloe', 'Tom', 'Chloe'];
// Creates a Map (hash) of occurrence numbers.
const counts = list.reduce((accumulator, val) => {
// Initialize entry if needed.
if (!accumulator.has(val)) accumulator.set(val, 0);
// Increment value.
accumulator.set(val, accumulator.get(val) + 1);
davidcalhoun / ES6
Last active August 30, 2018 13:10
ES6 cheatsheet
View ES6

From Learncode YouTube: Part 1, Part 2

Transpile to ES5

  • - most mainstream
  • Traceur - competitor


Destructuring: Objects

var foo = {
davidcalhoun / pascals-triangle.js
Last active December 14, 2017 17:38
pascal's triangle in javascript
View pascals-triangle.js
function pt(lineLimit, lines) {
// Seed the first value.
if(!lines || lines.length === 0) return pt(lineLimit, [[1]]);
var newLine = [];
var lastLine = lines[lines.length - 1];
// Fill out inner values
for(var i=1, len=lastLine.length; i<len; i++) {
newLine.push(lastLine[i - 1] + lastLine[i]);
View gist:59d8f7d15835938baff6
// one: passes up the error from two()
function one(cb){
two(function(err, data){
if(err) return cb('one ' + err);
return cb(null, data);
// two: passes up the error from three()
function two(cb){
davidcalhoun / gist:fd2de90593c39d21c176
Created June 30, 2014 21:07
june 30 filtered web dev links
View gist:fd2de90593c39d21c176
'A Guide to the Why and How of Full-Stack JavaScript:',
'RT @ghostalk_: We were joined by @izs for episode 19 of Ghostalk and talked about the origin of #npm #npmjs',
'building a better, faster and more secure web... HTTPS Everywhere: - our Google I/O talk on the why and the how!',
'Progressively Enhanced Single-Page Navigation +@jmmcduffie',
'DevTools Digest for Chrome 35: CSS quick-search, editor updates, network request filters, shadow DOM editability:',
'@paul_irish Hi! You shared my article on min-content; I thought you might find my piece on content-width appealing:',
'Chrome is committed to the mobile web. Here\'s what Chrome is doing to make the mobile web more awesome:',,
'RT @Paul_Kinlan: A great talk by @jennylg: Design principles for a better mobile web -',
'ngActivityIndicator.js: Preloaders for
davidcalhoun / gist:11388335
Created April 29, 2014 01:02
april 28 links
View gist:11388335
[ 'RT @businessinsider: Apple may launch two new MacBook Air models tomorrow',
'RT @willienelson: Willie getting his black belt',
'RT @hnycombinator Lessons learned from a cancelled project at GitHub (cmts )',
'RT @engadget: Worth repeating: If you\'re using Windows XP and Internet Explorer, you\'re at risk:',
'RT @conflitti: Just ran into @zeldman after day 1 of #aeabos Loved every minute of it. Thank you! That pic is for you @alisonpopp http://t.…',
'RT @drunk_casey: @marcoarment @siracusa Or this one?',
'RT @drunk_casey: @marcoarment @siracusa How about this one?',
'RT @irwindigital: @marcoarment John’s “relatively speaking” approval T-shirt. cc: @siracusa',
'RT @sippndipp: @dalmaer Hell yeah! @9elements has mullets deep in their DNA',
'Advanced bionic limbs could redefine disabilities
davidcalhoun / gist:11068525
Created April 18, 2014 23:32
april 18 links
View gist:11068525
[ 'GIF of epic',
'RT @AppleVis: New Guide: Understanding and Using VoiceOver\'s Commanders -',
'An Introduction to the MEAN Stack:',
'320° Licht: A Repurposed 112-Meter High Gas Tank Converted into a Cathedral of Light',
', you had one job: display conversations in chronological order.',
'Dollyzoom.js - - for the filmmaker in you.',
'Minicron is a system to manage and monitor (distributed) cron jobs: - nice project / handy tool!',
'RT @simevidas: With ES6 Set/Map in IE11, Safari remains the only browser that doesn\'t support them.\n\nCode demo:',
'RT @razvancaliman: CSS Shapes Editor in Brackets - A lot of time and work went into building this. I hope you find i…',
'RT @letoams: first TLS 1.3 draft RT @botstandar: [RFC-DRAFT] The Transport Layer Security (TLS) Protocol Version