Skip to content

Instantly share code, notes, and snippets.

View ricealexander's full-sized avatar

Alex Rice ricealexander

View GitHub Profile
@ricealexander
ricealexander / getFractions.js
Created March 30, 2021 22:05
Returns an array of all fractions of N
function getFractions (n) {
return Array.from({length}, (_, index) => (index + 1) / n)
}
// Example, all fractions of 16 (1/16, 2/16, 3/16, 4/16...)
getFractions(16) // [0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625, 0.625, 0.6875, 0.75, 0.8125, 0.875, 0.9375, 1]
@ricealexander
ricealexander / persistance-checker.js
Created March 30, 2021 22:02
Determine which elements were persisted on Grove SPA
(()=> {
let blockLevelElements = [
'address', 'article', 'aside', 'blockquote', 'canvas', 'dd', 'div',
'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'footer', 'form',
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'li', 'main',
'nav', 'noscript', 'ol', 'p', 'pre', 'section', 'table', 'tfoot',
'ul', 'video'
]
const elements = document.querySelectorAll(blockLevelElements.join(','))
@ricealexander
ricealexander / transcript-extractor.js
Created March 25, 2021 19:02
Rigging a Shared Module for Transcripts
// Transcripts
// One possible way to associate transcripts with Grove posts may involve Shared Modules
// 1. Insert a Module at the bottom of the news post.
// 2. Select Shared Module and create a new Shared Module.
// 3. Select RichText Module and give it a subhead at the top titled "Transcript".
// 4. Copy/Paste the transcript from Google Docs into the RichText body.
// 5. Publish!
//
// This provides some benefits for us over other strategies:
// * Text is the most accessible format for our audience.
@ricealexander
ricealexander / grove-embeddable-audio-player.html
Created February 5, 2021 18:26
A demo, built for Grove, that creates an audio player that can be embedded on websites
<!doctype html>
<html>
<head>
<title>Audio Player</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/aplayer/1.10.1/APlayer.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/aplayer/1.10.1/APlayer.min.js"></script>
</head>
<body>
<!--
This demo is built on top of APlayer
@ricealexander
ricealexander / talk-toast-taste-ticket-table.html
Last active January 25, 2021 21:00
Talk Toast Taste Ticket Table for Allegiance (TTTTT)
<table id="talk-toast-tickets-table" border="1">
<style>
#talk-toast-tickets-table {
background-color: white;
border: 1px solid #d5dce1;
margin: 1rem 0;
}
#talk-toast-tickets-table th {
background-color: #e1e6ea;
@ricealexander
ricealexander / un-allcaps-ifier.js
Created December 24, 2020 21:55
When you receive a list of sponsors in ALL CAPS
const sponsors = [
'BARNES JEWISH HOSPITAL',
'BARNES JEWISH WEST COUNTY HOSPITAL',
'BELLEVILLE NEWS DEMOCRAT',
'BESPOKE APPAREL',
'BETTER BUSINESS BUREAU',
'BIG BOW EVENTS',
'BIG O LIQUEUR',
]
@ricealexander
ricealexander / grove.css
Last active December 9, 2020 00:46
Grove doesn't support links in image captions. This workaround converts Markdown-style links into HTML links
.Figure-content .Link {
color: var(--linkColor);
}
.Figure-content .Link:hover {
color: var(--linkHoverColor);
}
@ricealexander
ricealexander / transcript-instructions-template.html
Last active December 4, 2020 21:52
A template for Transcript Instructions for STLPR Podcasts
<div class="box">
<h3>Request a Transcript</h3>
<p>
Transcripts for St. Louis Public Radio produced programming are available upon request.
<br><br>
To request a transcript for <em>{PROGRAM NAME}</em>,
let us know the episode date and contact {CONTACT NAME}
at <a href="mailto:{CONTACT EMAIL}">{CONTACT EMAIL}</a>.
</p>
@ricealexander
ricealexander / getFacebookStats.js
Created December 2, 2020 22:29
Given Facebook Insights Reactions/Comments/Shares State, return an object with their sums
// This function simplifies totalling up Reactions, Comments, and Shares in Facebook Insights
// To get the Reactions/Comments/Shares state, you must have the React Developer Tools Extension
// 1. Navigate to Page Insights > Reach
// 2. Set the date range at the top right of the view to the target range
// 3. Inspect the "Reactions, Comments, Shares and More" chart
// 4. In the React Components tool, navigate to c [from HubbleAreaLineChart] within HubbleChart
// 5. In the props, right click on "lines" and "Copy value to clipboard"
// The state of Reactions/Comments/Shares is now a nested array within your clipboard
@ricealexander
ricealexander / getItem.js
Last active December 2, 2020 00:02
Gets an item from an array by its index. For indexes outside of the array, it loops the index.
function getItem (array, index) {
if (typeof index !== 'number' || Number.isNaN(index)) {
throw new TypeError(`Expected index to be a Number. Instead got "${index}"`)
}
if (Math.abs(index) === Infinity) {
throw new ReferenceError(`Cannot access item at index "${index}"`)
}
const {length} = array
let wrappedIndex = index