This file contains 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
// It's hard to find good examples of overlay usage for react's wrapper for mapbox gl. this little snippet is a component | |
// that will display points on a map and allow the parent to render HTML. The positioning has to be absolute for the | |
// projection to render the images in the right spot on the map (Adjust for image height/width centering). - Sony | |
import React, {PureComponent} from 'react'; | |
import {HTMLOverlay} from 'react-map-gl'; | |
const ICON_HEIGHT = 32; | |
const ICON_WIDTH = 32; | |
const iconUrl = 'https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg'; |
This file contains 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
(function (url, onLoad) { | |
var script = document.createElement('script'); | |
script.addEventListener('load', onLoad); | |
script.src = url; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
}('https://cdn.jsdelivr.net/npm/[email protected]/moment.min.js', function () { | |
const fmt = 'MM/DD/YYYY'; | |
function getBroadcastWeek(momentDate) { |
This file contains 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
var str = '\"hello world\" arg1 arg2 \'multi arg that has nested strings \"haha hehe\"\' arg3 anotherArg _arg4_\''; | |
function tokenizer (str) { | |
var tokens = []; | |
var k, i, temp; | |
var strLen = str.length; | |
for (i = 0; i < strLen; i++) { | |
if (str[i] === '\"') { | |
for (temp = [], k = i+1; k < strLen && str[k] !== '\"'; k++) { |
This file contains 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
// Infinitely generate all odd numbers or whatever the MAX Number is | |
function* oddNumbers() { | |
let i = 1 | |
// Infinite loop. But thanks to the yield keyword, we exit this | |
// loop and return a value. On the next call back in, we resume | |
// where we left off. | |
while(1) { | |
yield i; | |
This file contains 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
// Test tree with contrived data | |
let testTree = { | |
value: 1, | |
child: [ | |
{value: 2, child: [ | |
{value: 7, child: []}, | |
{value: 8, child: []}, | |
{value: 9, child: []}, | |
]}, | |
{value: 3, child: []}, |
This file contains 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
// Test tree with contrived data | |
let testTree = { | |
value: 1, | |
child: [ | |
{value: 2, child: [ | |
{value: 7, child: []}, | |
{value: 8, child: []}, | |
{value: 9, child: []}, | |
]}, | |
{value: 3, child: []}, |
This file contains 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
// Example Usage: evalTempl("Hello {name}", {name: "sdg"}) | |
function evalTempl (str, context) { | |
return str.replace(/\{(.*?)\}/g, function(match, key) {return context[key];}); | |
} |
This file contains 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
(function (url, onLoad) { | |
var script = document.createElement('script'); | |
script.addEventListener('load', onLoad); | |
script.src = url; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
}('https://cdnjs.cloudflare.com/ajax/libs/q.js/0.9.2/q.js', function () { | |
// Load the Q promises library dynamically and print out the object | |
console.log(Q); | |
})) |
This file contains 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
// Get an existing child element that is not the passed in element | |
function getFirstChildThatIsNot(parent, child) { | |
return parent.children[0] != child ? parent.children[0] : parent.children[1]; | |
} | |
// Get the parent node and delete everything except the passed in element | |
function deleteSiblingsOf(element) { | |
var parent = element.parentNode; | |
while (getFirstChildThatIsNot(parent, element)) { |