Skip to content

Instantly share code, notes, and snippets.

View davidcalhoun's full-sized avatar
🐢
may be slow to respond; PRs welcomed

David Calhoun davidcalhoun

🐢
may be slow to respond; PRs welcomed
View GitHub Profile
@davidcalhoun
davidcalhoun / simple-script-loader.js
Created January 4, 2020 18:51
simple script loader.js
function initSyntaxHighlighting() {
// code
}
function loadScripts() {
const scripts = [
{
src: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js',
callback: initSyntaxHighlighting
}
@davidcalhoun
davidcalhoun / azimElevToXY.js
Last active November 21, 2019 04:57
satellite azim,elev to cartesian coords
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);
/* Keeps track of x/y "progress" as the user mouses over an image */
imageElement.addEventListener('mousemove', e => {
const target = e.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
davidcalhoun / find-occurrances.js
Last active December 16, 2017 03:11
Find the most frequent occurrences in a list with JavaScript
// 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
davidcalhoun / ES6 cheatsheet.md
Last active August 30, 2018 13:10
ES6 cheatsheet

From Learncode YouTube: Part 1, Part 2

Transpile to ES5

  • babeljs.io - most mainstream
  • Traceur - competitor

Destructuring

Destructuring: Objects

var foo = {
@davidcalhoun
davidcalhoun / pascals-triangle.js
Last active December 14, 2017 17:38
pascal's triangle in javascript
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]);
// 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
davidcalhoun / gist:fd2de90593c39d21c176
Created June 30, 2014 21:07
june 30 filtered web dev links
'A Guide to the Why and How of Full-Stack JavaScript: http://t.co/GXiQtM4GNY',
'RT @ghostalk_: We were joined by @izs for episode 19 of Ghostalk and talked about the origin of #npm #npmjs http://t.co/XPvhQs1k1F',
'building a better, faster and more secure web... HTTPS Everywhere: http://t.co/Xn51hBWbqe - our Google I/O talk on the why and the how!',
'Progressively Enhanced Single-Page Navigation http://t.co/kABarqGh8Q +@jmmcduffie',
'DevTools Digest for Chrome 35: CSS quick-search, editor updates, network request filters, shadow DOM editability: http://t.co/JfbdtMypCK',
'@paul_irish Hi! You shared my article on min-content; I thought you might find my piece on content-width appealing: http://t.co/3cHQoYNaPp',
'Chrome is committed to the mobile web. Here\'s what Chrome is doing to make the mobile web more awesome: http://t.co/GEMtlQJark',,
'RT @Paul_Kinlan: A great talk by @jennylg: Design principles for a better mobile web - http://t.co/81Ly6tcOyH',
'ngActivityIndicator.js: Preloaders for
@davidcalhoun
davidcalhoun / gist:11388335
Created April 29, 2014 01:02
april 28 links
[ 'RT @businessinsider: Apple may launch two new MacBook Air models tomorrow http://t.co/h6dyw0w4ZT',
'RT @willienelson: Willie getting his black belt http://t.co/hVkdRytonE',
'RT @hnycombinator Lessons learned from a cancelled project at GitHub (cmts http://t.co/GkeA8kX0J1 ) http://t.co/ur6MzGqfSq',
'RT @engadget: Worth repeating: If you\'re using Windows XP and Internet Explorer, you\'re at risk: http://t.co/60YJb5smFL',
'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? http://t.co/Q2KxIEdxsQ',
'RT @drunk_casey: @marcoarment @siracusa How about this one? http://t.co/3d1LB1UHXA',
'RT @irwindigital: @marcoarment John’s “relatively speaking” approval T-shirt. cc: @siracusa http://t.co/esTSCPzw9U',
'RT @sippndipp: @dalmaer Hell yeah! @9elements has mullets deep in their DNA http://t.co/FSlwwUKS1V',
'Advanced bionic limbs could redefine disabilities
@davidcalhoun
davidcalhoun / gist:11068525
Created April 18, 2014 23:32
april 18 links
[ 'GIF of epic http://t.co/x4nh6yKdSd',
'RT @AppleVis: New Guide: Understanding and Using VoiceOver\'s Commanders - http://t.co/yei98LzzKv',
'An Introduction to the MEAN Stack: http://t.co/EWkNytsO5w',
'320° Licht: A Repurposed 112-Meter High Gas Tank Converted into a Cathedral of Light http://t.co/17nYDz6dV5',
'Messages.app, you had one job: display conversations in chronological order. http://t.co/lFObSsT0oj',
'Dollyzoom.js - http://t.co/VD8nvzPoNP - for the filmmaker in you.',
'Minicron is a system to manage and monitor (distributed) cron jobs: http://t.co/Os5aTlxBY4 - 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: http://t.co/lgFEh90pXc',
'RT @razvancaliman: CSS Shapes Editor in Brackets - http://t.co/DF2j2O4RgG 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