Skip to content

Instantly share code, notes, and snippets.

@nichoth
nichoth / web-components.md
Last active August 9, 2024 21:35
web components TIL

web components

CSS

Use the ::part selector

sl-dialog::part(close-button) {
  display: none;
}
@nichoth
nichoth / json-set-map.md
Created August 4, 2024 05:46
JSON + Set & Map

JSON + Set & Map

Serialize + deserialize sets and maps. See this blog post.

function replacer(key, value) {
  if (value instanceof Map) {
    return { __type: 'Map', value: Object.fromEntries(value) }
  }
 if (value instanceof Set) {
@nichoth
nichoth / FOUC.js
Last active August 1, 2024 17:12
FOUC — flash of unstyled content
// see https://stackoverflow.com/questions/3221561/eliminate-flash-of-unstyled-content
//
// The problem with using a css style to initially hide some page
// elements, and then using javascript to change the style back to
// visible after page load, is that people who don't have javascript
// enabled will never get to see those elements.
//
// so, use javascript to both initially hide as well as redisplay
// those elements after page load
//
@nichoth
nichoth / CSS.md
Last active July 19, 2024 06:00
CSS — tips and things
@nichoth
nichoth / bash.md
Created July 18, 2024 20:47
Bash commands cli

bash

tar + gzip

tar -czvf my-new-file-name.tar.gz my-existing-folder
@nichoth
nichoth / node.js
Last active September 19, 2024 05:41
Node tips
#!/usr/bin/node // shebang
//
// mkdir -p
//
const fs = require('node:fs/promises')
// Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
await fs.mkdir('/tmp/a/apple', { recursive: true }, (err) => {
if (err) throw err;
@nichoth
nichoth / building-sync-systems.md
Created June 24, 2024 17:28 — forked from pesterhazy/building-sync-systems.md
Building an offline realtime sync engine

So you want to write a sync system for a web app with offline and realtime support? Good luck. You might find the following resources useful.

Overview articles

@nichoth
nichoth / CYPHERLINK.md
Created March 15, 2024 22:40 — forked from dominictarr/CYPHERLINK.md
Cypherlinks
@nichoth
nichoth / markdown-tips.md
Last active August 4, 2024 05:42
Github markdown

markdown tips

## Table of Contents

<details><summary>Click to expand</summary>

- [Background](#background)
- [Example](#example)
- [Browser Support](#browser-support)
@nichoth
nichoth / sleep.ts
Last active March 28, 2024 19:58
Async sleep — return a promise that waits for ms
/**
* Sleeps for `ms` milliseconds.
* @param {number} ms
* @return {Promise}
*/
async function sleep (ms:number) {
await new Promise((resolve) => {
if (!ms) {
process.nextTick(resolve)
} else {