Skip to content

Instantly share code, notes, and snippets.

@zerodevx
zerodevx / svelte-persist.js
Created October 5, 2022 08:25
Gist for simple persistent stores for SvelteKit
import { writable } from 'svelte/store'
import { browser } from '$app/environment'
function persist(name) {
const _store = browser && sessionStorage.getItem(name)
const store = writable(_store ? JSON.parse(_store) : '')
if (browser) {
store.subscribe((i) => sessionStorage.setItem(name, JSON.stringify(i)))
}
return store
@zerodevx
zerodevx / gist:59186234e93daa6240253dce4d1b69a0
Last active April 15, 2021 17:26
By far the easiest way to create an orphan branch in git - hands down 👐
# Checkout a new branch with all files removed
git switch --orphan <branch name>
@zerodevx
zerodevx / jsdom-gotchas.md
Last active February 7, 2020 07:05
JSDOM gotchas (ref: `jsdom v16.1.0`)
  1. fetch() is unsupported.

  2. XMLHttpRequest does not pass through JSOM.ResourceLoader. (jsdom/jsdom#1393)

  3. Does not respect synchronous execution of <script> tags. For eg.

<script src="run-first.js"></script>
<script src="run-second.js"></script>
@zerodevx
zerodevx / gist:9f71a4530f70d4947747ad170c67cd25
Last active August 15, 2019 17:02
Best practice to copy static website files from /build to /public correctly using rsync.
# Works well for static sites - where tooling generates the distribution into a build directory,
# and you want to synchronise this with the public deployment directory.
# Add the --dry-run flag to perform a dry run.
cd <source>
rsync -rlpgoDci --del --exclude=.DS_Store . <destination>