Skip to content

Instantly share code, notes, and snippets.

View dpeek's full-sized avatar

David Peek dpeek

View GitHub Profile
@dpeek
dpeek / tsconfig.json
Created August 30, 2023 01:40
Somewhat OK TSConfig defaults and explanations
/*
Enabled by "strict":
- alwaysStrict
- noImplicitAny
- noImplicitThis
- strictNullChecks
- strictBindCallApply
- strictFunctionTypes
- strictPropertyInitialization
- useUnknownInCatchVariable
@dpeek
dpeek / model.tsx
Created December 13, 2022 10:06
Replicache with Suspense
import React, {
createContext,
ReactNode,
useCallback,
useEffect,
useState,
} from 'react';
import { unstable_batchedUpdates } from 'react-dom';
import { ReadonlyJSONValue, ReadTransaction, Replicache } from 'replicache';
@dpeek
dpeek / use-subscribe-suspense.ts
Created May 2, 2022 23:23
useSubscribe that supports suspense
import { useEffect, useState } from 'react';
import { unstable_batchedUpdates } from 'react-dom';
import type {
ReadonlyJSONValue,
ReadTransaction,
Replicache,
} from 'replicache';
// We wrap all the callbacks in a `unstable_batchedUpdates` call to ensure that
// we do not render things more than once over all of the changed subscriptions.
@dpeek
dpeek / theme.ts
Created July 13, 2021 04:41
Radix Color Scale Mapper
import { createCss } from '@stitches/react';
import { mint } from '@radix-ui/colors';
type ScaleNum = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
type ScaleKey<Name extends string> = `${Name}${ScaleNum}`;
type ColorScale<Name extends string> = { [K in ScaleKey<Name>]: string };
function mapColorScale<FromName extends string, ToName extends string>(
fromScale: ColorScale<FromName>,
fromName: FromName,
@dpeek
dpeek / 05.js
Created December 5, 2019 14:44
const opcode = op => {
const str = String(op);
return parseInt(str.substr(str.length - 2));
};
const mode = (op, pos) => {
const str = String(op);
if (pos + 2 > str.length) return 0;
return parseInt(str.substr(str.length - (2 + pos), 1));
};
## dgraph query
{
person(func: uid(0x41d)) {
__typename
uid
name: Person.name
partner: Person.partner {
__typename
uid
name: Person.name
@dpeek
dpeek / clean.sh
Created February 11, 2019 18:37
Ensure consistent line-endings within files (both CRLF and LF)
# Require Swiss File Knife (sfk) (available from homebrew on macOS)
# find all files detected as CRLF and force CRLF
find . -not -path "./.git*" -type f | xargs file | grep "CRLF" | awk -F ':' '{ print $1 }' | xargs sfk addcr
# find all files detected as LF and force LF
find . -not -path "./.git*" -type f | xargs file | grep -v "CRLF" | awk -F ':' '{ print $1 }' | xargs sfk remcr
@dpeek
dpeek / bif.js
Created February 28, 2018 10:38
BIF Parser
function Buffer(a) {
this.buffer = a;
this.position = 0;
}
Buffer.prototype = {
seek: function(a) {
this.position = a;
},
skip: function(a) {
this.position += a;
@dpeek
dpeek / docker-compose.yml
Created December 17, 2017 14:43
Docker Compose Dgraph
version: '3'
services:
data:
image: dgraph/dgraph:master
volumes:
- dgraph:/dgraph
zero:
image: dgraph/dgraph:master
command: dgraph zero --port_offset -2000 --my=zero:5080
///////////////////////////////////////////////////// TAKE 1
http://localhost:8080/mutate
{ set {
_:node <__typename> "Person" .
_:node <name> "Tim" .
_:node <children> _:node0 .
_:node0 <parents> _:node .
_:node0 <__typename> "Person" .
_:node0 <name> "Jerry" .