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
function eventAll(eventName) { | |
// https://support.google.com/analytics/answer/1033068?hl=en | |
// non_interaction/nonInteraction to avoid raising bounce rate | |
// when there's an event that fires every page load. | |
if (window.gtag) { | |
gtag('event', eventName, { | |
non_interaction: true, | |
}); | |
} else if (window.ga) { | |
ga('send', { |
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
// Paste the following into your js console while viewing images, e.g. on your facebook feed. | |
// It will show the "alt" attributes that facebook assigned your images. | |
// It's an interesting peek into how facebook analyzes your images. | |
setInterval(function() { | |
var imgs = document.querySelectorAll("img"); | |
for (var i = 0; i < imgs.length; i++) { | |
var alt = imgs[i].alt; | |
if (alt && !imgs[i].getAttribute("alted")) { | |
var div = document.createElement("div"); |
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
// An example race condition in JavaScript | |
// When you run this script using Node or in a browser, you'll find it | |
// does not print "Ended with 0", but a random number. Even though the functions running | |
// simply loop 100 iterations of adding and subtracting. The reason the end result is random | |
// is because the sleeps are of random duration and the time between the read of the variable | |
// causes the eventual write to be incorrect when `adder` and `subber` interleave. | |
// This problem is similar to https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use | |
let number = 0; | |
const times = 100; |
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
// E.g used on | |
// https://www.crunchbase.com/search/principal.investors/8ff469dfad43f418bb327da3508ebddf | |
// Crunchbase hides search results behind a darker element and blurs the rows. This removes that | |
// so you can see the top 15 results instead of just 5. Though you won't be able to see beyond that. | |
document.querySelector('.all-results-upsell-wrapper').remove() | |
document.querySelectorAll('grid-row').forEach((it) => { it.setAttribute("class", "") }) |
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
import glob | |
import os | |
unknown_location_acronym = 'tbd' | |
# https://gist.github.com/rogerallen/1583593 | |
us_state_to_abbrev = { | |
'Alabama': 'AL', | |
'Alaska': 'AK', | |
'American Samoa': 'AS', |
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
/* | |
From 2020-11-29 [email protected] newsletter challenge | |
Given an array of integers and a target value, return the number of pairs of array | |
elements that have a difference equal to a target value. | |
Examples: | |
$ arrayDiff([1, 2, 3, 4], 1) | |
$ 3 // 2 - 1 = 1, 3 - 2 = 1, and 4 - 3 = 1 |
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
javascript: function findNodes(el) { | |
return el.querySelectorAll('#metadata-line'); | |
} | |
function isDigit(str) { | |
return str.length === 1 && str.match(/[0-9]/i); | |
} | |
function metricVal(el) { | |
let modifiers = { |
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
""" | |
The Simplest Math Problem No One Can Solve - YouTube - https://www.youtube.com/watch?v=094y1Z2wpJg | |
Collatz Conjecture | |
3x + 1 | |
x / 2 | |
(3x + 1) / 2 = 1.5x + 0.5 | |
3(x/2) + 1 = 1.5x + 1 |
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
// The Simplest Math Problem No One Can Solve | |
// https://www.youtube.com/watch?v=094y1Z2wpJg | |
// https://en.wikipedia.org/wiki/Collatz_conjecture | |
// I'm looking for loops by checking every positive integer (1, 2, 3...) | |
// and I'm using the binary representation (0b0, 0b10, 0b11, 0b100, ...) | |
// as an up and down path of a collatz loop where '1' means (3x+1)/2 and | |
// '0' means x/2 . `frac_follow_path` calculates what should be the starting | |
// value based on that collatz loop path, and if that's an integer - | |
// we found a loop. | |
// Problems so far: |
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
dateEls = [...document.querySelectorAll('relative-time')] | |
dates = dateEls.map(it => new Date(it.attributes['datetime'].textContent)); | |
durations = []; | |
for (const [i, dt] of dates.entries()) { | |
const hours = Math.round((dates[i] - dates[i + 1]) / 3600e2) / 10; | |
const newNode = document.createTextNode("- took hours " + hours); | |
dateEls[i].parentNode.appendChild(newNode); | |
durations.push(hours) | |
} |