Skip to content

Instantly share code, notes, and snippets.

Jeremy Keith adactio

Block or report user

Report or block adactio

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
adactio / indyMap.js
Created Oct 21, 2019
Scrape the current page for h-geo data and plot the result as a polyline on a Stamen watercolour map.
View indyMap.js
(function (win, doc) {
win.addEventListener('load', function() {
var latlons = [];
doc.querySelectorAll('.h-geo').forEach( function(geo) {
var lat = geo.querySelector('data.p-latitude').getAttribute('value');
var lon = geo.querySelector('data.p-longitude').getAttribute('value');
if (lat && lon) {
latlons.push([lat, lon]);
adactio / timestampComparison.js
Last active Jul 30, 2019
Compare server and client timestamps
View timestampComparison.js
// Generate a timestamp (in seconds) on the server. This won't change if the page is served from a cache.
var serverTimestamp = <?php echo time(); ?>;
// Create a new Date object from the local date and time on the client.
var localDate = new Date();
// Convert the local date and time to Universal Time (same as the server).
var localUTCString = localDate.toUTCString();
// Create a new Date object from the UTC date and time on the client.
var UTCDate = new Date(localUTCString);
// Generate a timestamp (in seconds) from the UTC date and time on the client.
var clientTimestamp = UTCDate.getTime() / 1000;
adactio / beforeInstallPrompt.js
Created Aug 3, 2018
Show a dismissable option to add The Session to the home screen (only shown to logged in users).
View beforeInstallPrompt.js
(function (win, doc) {
win.addEventListener('beforeinstallprompt', function (e) {
var deferredPrompt = e;
var insertionPoint = doc.querySelector('main .contents');
<div class="feedback" role="dialog" aria-labelledby="homescreen">
<h2 id="homescreen">Install The Session</h2>
<p>Would you like to add The Session to your home screen?</p>
<button class="back">No, thanks</button>
adactio / trimCache.js
Last active Jun 27, 2019
A recursive function to limit the number of items in a specified cache.
View trimCache.js
// Limit the number of items in a specified cache.
function trimCache(cacheName, maxItems) {
.then( cache => {
.then(keys => {
if (keys.length > maxItems) {
.then( () => {
trimCache(cacheName, maxItems)
adactio / minimal-serviceworker.js
Last active Nov 14, 2019
An attempt at a minimal viable service worker.
View minimal-serviceworker.js
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// HTML files: try the network first, then the cache.
// Other files: try the cache first, then the network.
// Both: cache a fresh version if possible.
// (beware: the cache will grow and grow; there's no cleanup)
const cacheName = 'files';
adactio / playSparkline.js
Last active May 14, 2018
A function to convert numbers into sound.
View playSparkline.js
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// Pass in an array of numbers ranging from 0 to 20.
function playSparkline(notes) {
if (!window.AudioContext && !window.webkitAudioContext) {
var playing = null;
adactio / boilerplate.html
Created Aug 17, 2017
My boilerplate for HTML
View boilerplate.html
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
adactio / monthmap.php
Last active Dec 27, 2018
Display a heat calendar for a month of data.
View monthmap.php
// Create an array of timestamps for posts
// and put them into an array called $timestamps.
foreach ($timestamps as $timestamp) {
$day = date("j", $timestamp);
$hour = date("G", $timestamp);
if (isset($heatcalendar['posts'][$day][$hour])) {
adactio / linkTwitterProfiles.php
Created Feb 2, 2017
A regular expression for turning a word beginning with @ into a link to a Twitter profile.
View linkTwitterProfiles.php
$string = preg_replace(
'<a href="$1">@$1</a>',
adactio /
Last active Dec 13, 2016
HTTPS domain settings on Apache 2.4.7:
<VirtualHost *:80>
DocumentRoot /path/to/yourdomain
Redirect /
<VirtualHost *:443>
You can’t perform that action at this time.