Skip to content

Instantly share code, notes, and snippets.

@calebmer
calebmer / postgrest-auth.md
Last active November 2, 2023 17:53
PostgREST Auth Protocol

This document is a work in progress. Any comments would be extremely helpful and appreciated!

PostgREST Auth Protocol

This document will describe an authentication framework very loosely based on the OAuth2 specification for a seperate authentication server to be used with the main PostgREST resource server. As PostgREST is going in a layered direction, this authentication layer must be interchangeable with other authentication implementations.

Options

  • The first parameter (same as PostgREST) must be a PostgreSQL database connection string.
  • -p, --port [number]: The port on which the server will listen for HTTP requests. Defaults to 3001.
  • -u, --user-relation [relation]: The relation (table or view) which PostgREST Auth will use for generating JWTs. If the relation is a view, it is recommend that it be auto-updateable. Must be user defined. The default is postgrest.users.
  • -r, --refresh-relation [relation]: The relation where PostgREST Auth will st
@calebmer
calebmer / results
Last active October 29, 2023 05:13
Object.setPrototypeOf vs Object.create benchmark test
Iteration(s): 0
==================================
Object.create: 0
Object.setPrototypeOf: 0
Iteration(s): 1
==================================
Object.create: 0
Object.setPrototypeOf: 0.04
import {
Dimensions,
LayoutChangeEvent,
Platform,
ScrollEvent,
ScrollView,
StyleSheet,
View,
} from "react-native";
import {Font, Space} from "../atoms";
@calebmer
calebmer / _utils.scss
Created February 26, 2015 12:15
A set of utilities I use with my sass
// ==================
// Misc
// ==================
$infinity: 9999;
@mixin clearfix() {
&:before,
&:after {
content: "";
@calebmer
calebmer / Emitter.ts
Last active February 27, 2020 21:21
Caleb’s Collection of utilities
import queueUncaughtException from './queueUncaughtException';
export default class Emitter<T> {
private readonly _listeners = new Set<(data: T) => void>();
emit(data: T) {
this._listeners.forEach(callback => {
try {
callback(data);
} catch (error) {
import {AccountID, GroupID, PostID} from "@connect/api-client";
import {GroupMemberTable} from "./GroupMemberTable";
import {PGTable} from "../pg/PGTable";
import {PGType} from "../pg/PGType";
export const PostTable = PGTable.define({
name: "post",
columns: {
id: PGType.int as PGType<PostID>,
group_id: PGType.int as PGType<GroupID>,
// Heavily inspired by my (Caleb’s) old [`pg-sql`][1] module. Updated now that
// I’ve learned a thing or two. Main differences include:
//
// - A more efficient implementation.
// - Symbol stamps to avoid SQL injection attacks using JSON.
//
// Also takes inspiration from Benjie’s fork, [`pg-sql2`][2].
//
// [1]: https://github.com/calebmer/pg-sql
// [2]: https://github.com/graphile/pg-sql2
@calebmer
calebmer / proof.txt
Last active February 15, 2019 00:30
∀(∅) ∀b.T b ⊑ ∀b.T b
───────────────────────── (Eq-Free)
∀(∅) ∀(b, b).T b ⊑ ∀b.T b
───────────────────────── (R-Context)
∀(b) ∀b.T b ⊑ T b
─────────────────────────────────────── (I-Context)
∀(b) ∀(a ≥ ∀b.T b).T a ⊑ ∀(a ≥ T b).T a
───────────────────────────────────────────── (R-Context)
∀(∅) ∀(b, a ≥ ∀b.T b).T a ⊑ ∀(b, a ≥ T b).T a
───────────────────────────────────────────── (Eq-Free)
@calebmer
calebmer / proof.txt
Last active February 5, 2019 17:28
fresh(a') fresh(s')
(row-var) ─────────────────────────────────────────
s ≃ { p: a' | s' } : [s ↦ { p: a' | s' }] q ≠ p a ∉ ftv(a') r ∉ ftv({ q: b | s' })
(row-swap) ─────────────────────────────────────────────────────────────── (uni-varl) ───────────────── (uni-varl) ───────────────────────────────────────
{ q: b | s } ≃ { p: a' | { q: b | s' } } : [s ↦ { p: a' | s' }] a ∼ a' : [a ↦ a'] r ∼ { q: b | s' } : [r ↦ { q: b | s' }]
(uni-row) ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
{ p: a | r } ∼ { q: b | s } : [r ↦ { q: b | s' }, s ↦ { p: a | s' }]
function MyComponent() {
// 40 conditions
if (c) {} else {}
if (c) {} else {}
if (c) {} else {}
if (c) {} else {}
if (c) {} else {}
if (c) {} else {}
if (c) {} else {}
if (c) {} else {}