Skip to content

Instantly share code, notes, and snippets.

View freshface's full-sized avatar

Frederik Heyninck freshface

View GitHub Profile
@ireade
ireade / sw.js
Last active May 28, 2024 19:17
Handle broken images with the service worker
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open("precache").then((cache) => cache.add("/broken.png"))
);
});
function isImage(fetchRequest) {
return fetchRequest.method === "GET" && fetchRequest.destination === "image";
}
@bramus
bramus / isSunSup.php
Last active November 27, 2018 13:23
PHP: Is The Sun Up (standalone version)?
<?php
function sunIsUp(\DateTime $when, $lat, $lon): bool {
$whenTimestamp = $when->getTimestamp();
$sunriseTimestamp = date_sunrise(
$whenTimestamp,
SUNFUNCS_RET_TIMESTAMP,
$lat,
$lon
@mcnamee
mcnamee / instagram-feed.php
Last active February 11, 2021 08:59
Fetch an Instagram Feed with PHP and Cache it locally
<?php
/**
* Fetches and Caches a Instagram Feed
*
* - Get an Instagram Developer Account here: https://www.instagram.com/developer/
* - Create a new client, using the 'redirect URI' as https://rudrastyh.com/tools/access-token
* - Get an access token here: https://rudrastyh.com/tools/access-token
* - This file will return JSON - so use some AJAX on the front-end to display
* - Add the instagram-feed-cache.json file as ignored, to .gitignore
*/
@adactio
adactio / minimal-serviceworker.js
Last active August 18, 2023 09:15
An attempt at a minimal viable service worker.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
// 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';