Skip to content

Instantly share code, notes, and snippets.


Jeremy Keith adactio

View GitHub Profile
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 / lettering.html
Created Jan 26, 2012
A quick'n'dirty way of doing some lettering.js stuff without jQuery.
View lettering.html
<!DOCTYPE html>
<html lang="en">
.slogan span:nth-child(odd) {
color: red;
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 / sendWebmention.php
Last active Dec 27, 2018
Search a web page for a webmention endpoint and, if one exists, send a webmention to it.
View sendWebmention.php
# Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
function sendWebmention($source, $target) {
$endpoint = false;
$options = array(
adactio / Twig-critical-CSS-test.twig
Last active Jul 9, 2019
Twig template for inlining critical CSS on first visits.
View Twig-critical-CSS-test.twig
{% set cssupdate = '20150309' %}
{% if _cookie.csscached == cssupdate %}
<link rel="stylesheet" href="/css/global-min.{{ cssupdate }}.css">
{% else %}
{% include 'global/critical.css' %}
(function (win, doc) {
'use strict';
adactio / sectioningcontenttest.html
Created Nov 12, 2011
Illustration of sectioning content and the outline algorithm in HTML5.
View sectioningcontenttest.html
<!DOCTYPE html>
<html lang="en">
<title>Sectioning Content test</title>
<h1>This is an h1</h1>
<p>That h1 is the heading for the body (a sectioning root).</p>
<h1>This is another h1</h1>
<p>That h1 is inside a div so it is no different than the first h1.</p>
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 / 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]);
View postToMedium.php
# Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
function postToMedium($data=array()) {
$user_id = "XXXX";
$accessToken = "XXXX";
adactio / getEmbedCode.php
Created Mar 24, 2020
A PHP function to return an oEmbed result from a URL.
View getEmbedCode.php
function getEmbedCode($url="") {
$return = '';
$providers = array(
'' => '',
'' => '',
'' => '',