Skip to content

Instantly share code, notes, and snippets.

View garth's full-sized avatar

Garth Williams garth

View GitHub Profile
@garth
garth / connect-emmiter.ts
Last active February 29, 2024 01:43
Connect emitter interface for Fireproof
import {
type DownloadMetaFnParams,
type DownloadDataFnParams,
type UploadMetaFnParams,
type UploadDataFnParams,
type ChannelEmitter,
} from './types'
import { Connection } from '@fireproof/connect'
export type ConnectEmitterParams = {
@garth
garth / readme.md
Last active January 18, 2024 21:58
A Yjs provider for socketsupply

You can use it the same as you do with other yjs providers, but you have to pass it a socket which can be created with someting like this:

// set the peer id
const peerId = window.localStorage.getItem('peerId') ?? (await Encryption.createId())
window.localStorage.setItem('peerId', peerId)

// set the signing keys
const keySeed = window.localStorage.getItem('keySeed') ?? createId()
@garth
garth / README.md
Last active April 8, 2022 09:02
Split DOM nodes

Simple DOM splitter

I couln't find a simple function to split DOM nodes by some child, so here is.

Split any node by a child maintaining all nested nodes across the split. The child node is not included in the split.

To see how it works and what it can do, have a look at the tests.

/* CYCLONE_CONSTANTS */
var VlxDevConstants = VlxDevConstants || {};
/* g_cyclone_general_info */
VlxDevConstants.A_CYC_APPL_SW_VERSION = 1;
VlxDevConstants.A_CYC_APPL_SW_VERSION_1 = 2;
VlxDevConstants.A_CYC_APPL_SW_VERSION_2 = 3;
VlxDevConstants.A_CYC_APPL_SW_VERSION_3 = 4;
VlxDevConstants.A_CYC_APPL_SW_VERSION_4 = 5;
VlxDevConstants.A_CYC_APPL_SW_VERSION_5 = 6;
@garth
garth / volta.docker
Created May 24, 2021 15:18
Docker image roughly based on the offical node images, but with support for projects with mixed node versions via Volta
FROM debian:buster
# curl and ca-certificates are needed for volta installation
# git, python and build-essential are needed for legacy package dependencies
RUN apt-get update \
&& apt-get install -y \
curl \
ca-certificates \
git \
python \
// This would be the client in the npm package
export const plausible: (arg: 'page' | 'trackPushState') => void = (window['plausible'] =
window['plausible'] ||
function(
...args: any[] // eslint-disable-line
) {
;(window['plausible'].q = window['plausible'].q || []).push(args)
})
const js = document.createElement('script')
js.id = 'plausible'
@garth
garth / Login.tsx
Created November 23, 2018 13:46
A simple form manager with react hooks
import React from 'react'
import { useForm } from './forms-hook'
const formDefinition = {
username: { value: '', isValid: value => value.length > 0 },
password: { value: '', isValid: value => value.length > 0 }
}
const Login: React.StatelessComponent = () => {
const [form, setField] = useForm(formDefinition)
@garth
garth / App.tsx
Last active November 29, 2018 10:22
A simple router using page.js and applied using react hooks
import React, { useState } from 'react'
import { routes } from './routes'
import { useRouter } from './router-hook'
const App: React.StatelessComponent = () => {
const route = useRouter(routes)
return (
<div>
<h1>{route.name}</h1>
</div>
@garth
garth / gnome_terminal_settings.txt
Created October 28, 2018 20:54
Nova gnome terminal settings
[legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9]
foreground-color='rgb(197,212,221)'
visible-name='Nova'
palette=['rgb(60,76,85)', 'rgb(223,140,140)', 'rgb(168,206,147)', 'rgb(218,218,147)', 'rgb(131,175,229)', 'rgb(154,147,225)', 'rgb(127,193,202)', 'rgb(197,212,221)', 'rgb(137,155,166)', 'rgb(242,195,143)', 'rgb(168,206,147)', 'rgb(218,218,147)', 'rgb(131,175,229)', 'rgb(209,142,194)', 'rgb(127,193,202)', 'rgb(230,238,243)']
default-size-rows=40
default-size-columns=140
cursor-background-color='rgb(127,193,202)'
cursor-shape='block'
cursor-colors-set=true
highlight-colors-set=false
@garth
garth / settings.json
Last active May 14, 2021 15:15
VS Code
{
"cSpell.language": "en-GB",
"editor.autoClosingBrackets": "never",
"editor.autoClosingQuotes": "never",
"editor.cursorStyle": "line",
"editor.emptySelectionClipboard": false,
"editor.folding": false,
"editor.fontFamily": "MonoLisa, 'JetBrains Mono', 'Fira Code Retina', 'Cascadia Code', Menlo, Monaco, 'Courier New', monospace",
"editor.fontLigatures": true,
"editor.fontSize": 13,