Skip to content

Instantly share code, notes, and snippets.

View lholmquist's full-sized avatar

Lucas Holmquist lholmquist

View GitHub Profile
@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 April 9, 2024 08:18
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.

@paoloantinori
paoloantinori / keycloak.sh
Created January 26, 2016 15:59
Keycloak Admin API Rest Example
#!/bin/bash
export TKN=$(curl -X POST 'http://localhost:8080/auth/realms/master/protocol/openid-connect/token' \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=admin" \
-d 'password=admin' \
-d 'grant_type=password' \
-d 'client_id=admin-cli' | jq -r '.access_token')
curl -X GET 'http://localhost:8080/auth/admin/realms' \
@wei-lee
wei-lee / dev.json
Created August 7, 2015 08:40
enabled fh-digger in fhcap
{
"name": "dev",
"description": "Development role",
"json_class": "Chef::Role",
"default_attributes": {
"host_src_dir": "/Users/weili/work/fh/eng/",
"feedhenry_common": {
"src": "/mnt/src"
},
"vm": {
Map<String, Object> criteria = new LinkedHashMap<>();
criteria.put("categories", Arrays.asList("feedhenry"));
Map<String, Object> jsonContainer = new LinkedHashMap<>();
jsonContainer.put("alert", "Hello Luke, This is from MQTT");
jsonContainer.put("criteria", criteria);
String jsonPayload = new Gson().toJson(jsonContainer);
@sebastienblanc
sebastienblanc / gist:9615439c67968ecb92da
Last active December 4, 2018 08:02
Add a new platform in the UnifiedPush Server

Add a new platform in the UnifiedPush Server

This is simple checklist for those who would like to add a new Push Platform support to UPS (like Blackberry hint for the community hint).

Adapt the Model

  • Start by updating the Variant Enum class by adding your platform

  • Create a subclass of the Variant base class , add any properties that are specific to this platform (like API keys, secrets etc ...)

@joyrexus
joyrexus / README.md
Last active August 3, 2023 22:56
Form/file uploads with hapi.js

Demo of multipart form/file uploading with hapi.js.

Usage

npm install
npm run setup
npm run server

Then ...

@1wErt3r
1wErt3r / SMBDIS.ASM
Created November 9, 2012 22:27
A Comprehensive Super Mario Bros. Disassembly
;SMBDIS.ASM - A COMPREHENSIVE SUPER MARIO BROS. DISASSEMBLY
;by doppelganger (doppelheathen@gmail.com)
;This file is provided for your own use as-is. It will require the character rom data
;and an iNES file header to get it to work.
;There are so many people I have to thank for this, that taking all the credit for
;myself would be an unforgivable act of arrogance. Without their help this would
;probably not be possible. So I thank all the peeps in the nesdev scene whose insight into
;the 6502 and the NES helped me learn how it works (you guys know who you are, there's no
@andreyvit
andreyvit / tmux.md
Created June 13, 2012 03:41
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a