Skip to content

Instantly share code, notes, and snippets.

👀
Currently looking, ideally for a good cause!

David Calhoun davidcalhoun

👀
Currently looking, ideally for a good cause!
Block or report user

Report or block davidcalhoun

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 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 Nov 21, 2019
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 = 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 Dec 16, 2017
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);
View ES6 cheatsheet.md

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 Dec 14, 2017
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
davidcalhoun / gist:fd2de90593c39d21c176
Created Jun 30, 2014
june 30 filtered web dev links
View gist:fd2de90593c39d21c176
'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
View gist:11388335
[ '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
View gist:11068525
[ '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
You can’t perform that action at this time.