Skip to content

Instantly share code, notes, and snippets.

View dmkitui's full-sized avatar
💭
#CowboyCoding

Daniel Masake Kitui dmkitui

💭
#CowboyCoding
View GitHub Profile
@fibo
fibo / cache.js
Last active June 10, 2023 10:20
Service Worker implementing stale-while-revalidate caching strategy.
/* global caches, fetch, self */
// Fill here with your cache name-version.
const CACHE_NAME = 'my-cache-v1'
// This is the list of URLs to be cached by your Progressive Web App.
const CACHED_URLS = [
'/',
'/bundle.js',
'/manifest.json',
'/register.js',
@surma
surma / staleWhileRevalidate.js
Last active April 8, 2024 22:38
ServiceWorker that implements “Stale-while-revalidate”
// Implements stale-while-revalidate
self.addEventListener('fetch', event => {
const cached = caches.match(event.request);
const fetched = fetch(event.request);
const fetchedCopy = fetched.then(resp => resp.clone());
// Call respondWith() with whatever we get first.
// If the fetch fails (e.g disconnected), wait for the cache.
// If there’s nothing in cache, wait for the fetch.
// If neither yields a response, return a 404.
@Rich-Harris
Rich-Harris / service-workers.md
Last active July 10, 2024 17:04
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@jeffposnick
jeffposnick / index.html
Last active August 25, 2020 11:50
Exploration of how a service worker's fetch handler affects the DevTools Network panel
<html>
<head>
<title>DevTools Test</title>
</head>
<body>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js');
// Wait until the SW has taken control of the page before inserting the <script> elements.
// That way we can be sure the SW's fetch handler will intercept them.
@bfg100k
bfg100k / lan_monitor.sh
Last active December 20, 2023 04:35
This is a script to check for new devices on the network (regardless of connectivity type. i.e. wired, wireless, vpn). New devices (either new MAC or old MAC with new hostname) joining the network will trigger an email alert to be sent. A simple intrusion detection system for Asus routers running custom firmware by Padavan (https://code.google.c…
#!/bin/bash
# Script to monitor devices on network (regardless of connectivity type.
# i.e. wired, wireless, vpn). New devices (either new MAC or old MAC with
# new hostname) joining the network will trigger an email alert to be sent.
#
# REQUIRED ENTWARE PACKAGES :
# * msmtp - SMTP client to send mail to external email addresses
#
# Author: SidneyC <sidneyc_at_outlook_dot_com>
#
@amatellanes
amatellanes / celery.sh
Last active July 18, 2024 07:23
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@pwalsh
pwalsh / wtforms-field-macro-bootstrap3.html
Last active September 5, 2022 17:44 — forked from alienhaxor/_formhelpers.py
A macro for rending WTForm fields in Jinja2 templates with Bootstrap 3 styling.
{% macro render_field(field) -%}
{% set with_label = kwargs.pop('with_label', False) %}
{% set placeholder = kwargs.pop('placeholder', field.label.text) %}
{% set class_ = kwargs.pop('class_', '') %}
{% if field.flags.required %}
{% set class_ = class_ + ' required' %}
{% endif %}
@plentz
plentz / nginx.conf
Last active July 25, 2024 09:38
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048