This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Point2PointDistance = (lat1, lon1, lat2, lon2) => { | |
const toRad = num => num * Math.PI / 180; // Converts numeric degrees to radians | |
const R = 6371000, // earth radius, in m | |
dLat = toRad(lat2 - lat1), | |
dLon = toRad(lon2 - lon1); | |
lat1 = toRad(lat1); | |
lat2 = toRad(lat2); | |
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const commands = { | |
'ctrl+z' => History.undo, | |
'ctrl+y' => History.redo, | |
'escape': () => { alert('esc'); } | |
}; | |
$(window).on('keydown', event => { | |
let label = ''; | |
if (event.ctrlKey) { label += 'ctrl+'; } | |
if (event.altKey) { label += 'alt+'; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Select single element | |
const $ = (e, parent = document) => parent.querySelector(e); | |
// Select multiple elements | |
const $$ = (e, parent = document) => Array.from(parent.querySelectorAll(e)); | |
// Create element | |
const cE = (tagName, props) => { | |
const el = document.createElement(tagName); | |
for (let prop of ['id','name','value','className','type','href','method','action']) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('DOMContentLoaded', async () => { | |
const fonts = ['Action Man', 'Heaven', 'Weltron Urban'] | |
// First method (if you don't need to know when all fonts are finished loading) | |
fonts.forEach(font => { | |
new FontFace(font, `url(fonts/${encodeURIComponent(font)}.woff)`).load().then(font => { document.fonts.add(font) }) | |
}) | |
// Second method (if you do need to know when all fonts are finished loading) | |
const promises = [] |
OlderNewer