Skip to content

Instantly share code, notes, and snippets.

View adactio's full-sized avatar

Jeremy Keith adactio

View GitHub Profile
@adactio
adactio / monthmap.php
Last active December 27, 2018 07:21
Display a heat calendar for a month of data.
<?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])) {
$heatcalendar['posts'][$day][$hour]++;
@adactio
adactio / linkTwitterProfiles.php
Created February 2, 2017 23:45
A regular expression for turning a word beginning with @ into a link to a Twitter profile.
<?php
$string = preg_replace(
'/(?<=^|\s)@([a-z0-9_]+)/i',
'<a href="https://twitter.com/$1">@$1</a>',
$string
);
?>
@adactio
adactio / yourdomain.com.conf
Last active December 13, 2016 13:48
HTTPS domain settings on Apache 2.4.7: https://adactio.com/journal/10727
<VirtualHost *:80>
ServerAdmin you@yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /path/to/yourdomain
Redirect / https://yourdomain.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin you@yourdomain.com
@adactio
adactio / formProgress.js
Created May 29, 2016 15:27
Show a progress bar with every form that has a method of POST. Particularly nice if there's a file upload involved.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function (win, doc) {
'use strict';
if (!win.XMLHttpRequest || !win.FormData || !win.addEventListener || !doc.querySelectorAll) {
// doesn't cut the mustard.
return;
}
function hijaxForm (formElement) {
var progressBar;
@adactio
adactio / aria-controls.js
Last active March 8, 2024 07:07
Show and hide content with "aria-controls" buttons.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function (win, doc) {
'use strict';
if (!doc.querySelectorAll || !win.addEventListener) {
// doesn't cut the mustard.
return;
}
var toggles = doc.querySelectorAll('[aria-controls]');
var togglecount = toggles.length;
@adactio
adactio / urtext.html
Last active May 7, 2016 02:06
December 3rd, 1990: The earliest known HTML document: http://www.w3.org/2012/08/history-of-the-web/origins.htm
<h1>Standardisation</h1>
There was not a lot of discussion of this at <a href=Introduction.html>ECHT90</a>, but there seem to be two leads:
<ol>
<li><a href=People.html#newcombe>Steve newcombe's</a> and Goldfarber's "Hytime" committee
looking into SGML, and
<li>An ISO working group known as MHEG, "Multimedia/HyperText Expert Group".
led by one Francis Kretz (Thompsa SA? Rennes?).
</lo>
@adactio
adactio / blogServiceWorker.js
Last active March 27, 2023 09:26
A Service Worker to progressively enhance a blog by storing assets in a cache, and keeping limited caches of pages and images for offline browsing.
'use strict';
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function() {
// A cache for core files like CSS and JavaScript
var staticCacheName = 'static';
// A cache for pages to store for offline
@adactio
adactio / basicServiceWorker.js
Last active March 27, 2023 09:30
A basic Service Worker, for use on, say, a blog.
'use strict';
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function() {
// Update 'version' if you need to refresh the cache
var staticCacheName = 'static';
var version = 'v1::';
<?php
# Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
# http://creativecommons.org/publicdomain/zero/1.0/
function postToMedium($data=array()) {
$user_id = "XXXX";
$accessToken = "XXXX";
@adactio
adactio / ampify.php
Last active October 3, 2022 06:26
Make a chunk of markup AMP-ready
<?php
# Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
# http://creativecommons.org/publicdomain/zero/1.0/
function ampify($html='') {
# Replace img, audio, and video elements with amp custom elements
$html = str_ireplace(
['<img','<video','/video>','<audio','/audio>'],