Skip to content

Instantly share code, notes, and snippets.

View ricealexander's full-sized avatar

Alex Rice ricealexander

View GitHub Profile
@ricealexander
ricealexander / comment-stripper.txt
Last active May 21, 2020 19:31
Regex for stripping comments in a file
# Match all comments
\n?\s*\/\/\s.*
# \n? optional-linebreak for matching comments on their own line
# \s* matches any number of spaces preceeding //
# \/\/ matches //
# \s matches a single space after //. Lack of a space may indicate non-comment usage of //
# .* matches the content of the comment until the end of the current line
@ricealexander
ricealexander / isolateEventListener.js
Last active April 7, 2020 23:05
SPA can load custom scripts. We do not have control of the SPA otherwise. These files can isolate recurring code so it does not persist from page to page
(function() {
// Isolate Event Listener so it is safe to use
// current URL is checked each time the event listener is activated
// if a different page is loaded, the event will destroy itself the next time it is active
// In this demo, we are able to completely isolate this behavior inside
// an abstraction called createIsolatedEvent, which is fully reusable
@ricealexander
ricealexander / google-site-customization.css
Created April 3, 2020 18:53
A few rules which drastically improves the appearance of Google Sites theme
#sites-chrome-everything {
background: #f9fbfc;
}
#sites-header-title {
height: 80px;
}
#sites-chrome-page-wrapper-inside #sites-chrome-header-wrapper {
background: none;
@ricealexander
ricealexander / remove-promotions.js
Created April 3, 2020 18:49
Remove promoted content on different platforms
// Remove Twitter Promoted Tweets
window.addEventListener('scroll', _event => {
[ ...document.querySelectorAll('h2') ]
.filter(heading => heading.textContent.includes("Promoted Tweet"))
.map(heading => heading.parentElement.parentElement)
.forEach(promotion => promotion.remove())
})
// Remove LinkedIn Promoted Posts
window.addEventListener('scroll', _event => {
@ricealexander
ricealexander / collect-corepub-links.js
Created April 3, 2020 18:34
Instructions for gathering URLs from CorePub's limited feed
@ricealexander
ricealexander / matchesCaseInsensitive.js
Created April 3, 2020 18:29
Compares strings to determine whether they are all the same, case-insensitively
const matchesCaseInsensitive = (first, ...rest) => {
if (rest.length === 0) {
throw new Error(`Expected at least 2 arguments`)
}
const target = first.toLowerCase()
return rest.every(value => value.toLowerCase() === target)
}
@ricealexander
ricealexander / stlpr-analytics-bundle.js
Last active February 14, 2020 20:07
Bundle Analytics
(function(){
var scriptOrder = 0
function loadScript (src) {
// create script
var script = document.createElement("script")
script.async = true
script.src = src
// insert script into the top of the document
@ricealexander
ricealexander / top-navigation.json
Created February 6, 2020 21:21
A hacky, but straight-forward and flexible, representation of STLPR's navigation
[
{"News Topics": {
"dropdown": [
{"Arts & Culture": "https://news.stlpublicradio.org/term/arts-culture"},
{"Economy & Innovation": "https://news.stlpublicradio.org/term/economy-innovation"},
{"Education": "https://news.stlpublicradio.org/term/education-0"},
{"Health, Science, Environment": "https://news.stlpublicradio.org/term/health-science"},
{"Politics & Issues": "https://news.stlpublicradio.org/term/politics-issues"},
{"Metro East Coverage": "https://news.stlpublicradio.org/topic/metro-east-coverage"},
{"Rolla-Region Coverage": "https://news.stlpublicradio.org/topic/rolla-region-coverage"},
@ricealexander
ricealexander / stripTags.js
Created January 31, 2020 21:15
Strip HTML Tags
const stripTags = string => {
const temp = document.createElement('div')
temp.innerHTML = string.replace(/<br[^>]*>/gi, ' ')
return temp.textContent
}
@ricealexander
ricealexander / real_javascript_names.js
Last active January 2, 2021 00:29
A collection of prototype methods that have a different name than their original proposal
// Array.prototype.contains: https://esdiscuss.org/topic/having-a-non-enumerable-array-prototype-contains-may-not-be-web-compatible
// Array.prototype.flatten: https://developers.google.com/web/updates/2018/03/smooshgate
// String.prototype.contains: https://bugzilla.mozilla.org/show_bug.cgi?id=1102219
// globalThis: https://github.com/tc39/proposal-global/blob/master/NAMING.md
Array.prototype.all = Array.prototype.every
Array.prototype.any = Array.prototype.some
Array.prototype.contains = Array.prototype.includes
Array.prototype.flatten = Array.prototype.flat