Skip to content

Instantly share code, notes, and snippets.

SimeonGriggs / useListeningQuery.ts
Last active November 30, 2022 05:59
A custom hook for making and listening to document changes
View useListeningQuery.ts
import React, {useEffect, useState, useRef} from 'react'
import documentStore from 'part:@sanity/base/datastore/document'
import {catchError, distinctUntilChanged} from 'rxjs/operators'
import isEqual from 'react-fast-compare'
type Params = Record<string, string | number | boolean | string[]>
interface ListenQueryOptions {
tag?: string
apiVersion?: string
geball / customArrayFunctions.js
Created June 4, 2021 15:14
Custom snippet to override the array function in
View customArrayFunctions.js
// Ported from and adapted to a functional component.
// Overrides the array's Add item button based on an integer-based validation rule.
// Add the following to sanity.json:
// {
// "implements": "part:@sanity/form-builder/input/array/functions",
// "path": "./src/components/customArrayFunctions.js"
// }
adactio / minimal-serviceworker.js
Last active August 18, 2023 09:15
An attempt at a minimal viable service worker.
View minimal-serviceworker.js
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// 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';
ceejbot /
Last active July 17, 2023 02:45
npm's proposal for supporting ES modules in node

ESM modules in node: npm edition

The proposal you’re about to read is not just a proposal. We have a working implementation of almost everything we discussed here. We encourage you to checkout and build our branch: our fork, with the relevant branch selected. Building and using the implementation will give you a better understanding of what using it as a developer is like.

Our implementation ended up differing from the proposal on some minor points. As our last action item before making a PR, we’re writing documentation on what we did. While I loathe pointing to tests in lieu of documentation, they will be helpful until we complete writing docs: the unit tests.

This repo also contains a bundled version of npm that has a new command, asset. You can read the documentation for and goals of that comma

Rich-Harris /
Last active November 16, 2023 20:46
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

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.

ksrb / index.ejs
Last active March 10, 2021 05:58
jquery.inputmask webpack configuration and package.json
View index.ejs
<!DOCTYPE html>
<meta charset="UTF-8">
<title><%= htmlWebpackPlugin.options.title %></title>
<input id="float"/>
View meh.js
// All the transform types.
const types = [
View combine-reducers.js
// Straight from documentation.
const reducer = combineReducers({
a: doSomethingWithA,
b: processB,
c: c
// This is functionally equivalent.
function reducer(state, action) {
return {
ygotthilf /
Last active November 24, 2023 20:16
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out
cat jwtRS256.key
dominictarr /
Last active July 29, 2016 17:06
ideas for a modular database


we've had great success building modular database stuff on top of leveldb with node, but as I have learnt more about databases it's become apparent to me that the idea of a modular database would be better implemented at a slightly lower level.

Level db provides a sorted key:value store, which, because of the sorted property, many things can be implemented on top of. For example, for replication, or for consistent materialized views, we often need a write ahead log. This can easily be implemented via a batch write to level, and writing the log into a section of the leveldb key space which is treated as append only.