Skip to content

Instantly share code, notes, and snippets.

View jon-whit's full-sized avatar

Jonathan Whitaker jon-whit

View GitHub Profile

Setup

  1. Start a Postgres instance, for example
docker run -p 5432:5432 -e POSTGRES_PASSWORD=password -d docker
  1. Open a psql client shell
psql -h localhost -p 5432  -U postgres -d postgres
Password for user postgres: <enter password>
@jon-whit
jon-whit / example1-tuples.sql
Last active April 10, 2024 17:51
FGA Indexes and Cyclical Behavior
INSERT INTO tuples VALUES ('document', '1', 'viewer', 'editor', 'document', '1');
@jon-whit
jon-whit / docker-compose.yml
Last active April 9, 2024 23:36
FGA Exclusion Query to Materialize MUTUALLY RECURSIVE
version: "3"
services:
postgres:
image: postgres
ports:
- 5432:5432
restart: always
environment:
POSTGRES_PASSWORD: password
command:
fga index create \
--name group_member_user_index \
--user-type=user \
--relation=member \
--object-type=group \
--out views.sql
Output:
--- views.sql
@jon-whit
jon-whit / check_test.go
Created February 22, 2024 23:56
Dispatch Count Test
t.Run("dispatch_direct_userset_lookups", func(t *testing.T) {
ds := memory.New()
ctx := storage.ContextWithRelationshipTupleReader(context.Background(), ds)
storeID := ulid.Make().String()
model := parser.MustTransformDSLToProto(`model
schema 1.1
type user
package lookup
import (
"context"
"fmt"
"sync/atomic"
openfgapb "go.buf.build/openfga/go/openfga/api/openfga/v1"
"golang.org/x/sync/errgroup"
)
package lookup
import (
"fmt"
openfgapb "go.buf.build/openfga/go/openfga/api/openfga/v1"
"golang.org/x/sync/errgroup"
)
func Lookup(req *openfgapb.LookupRequest, srv openfgapb.OpenFGAService_LookupServer) error {
@jon-whit
jon-whit / pubsub-swagger.yaml
Last active July 13, 2021 18:19
Pubsub API Definition
swagger: "2.0"
info:
description: |
A simple Pubsub messaging API that allows clients to:
* Publish messages to a Topic
* Create Subscriptions to a Topic
* Pull messages from Subscriptions
* Acknowledge receipt of the messages delivered to a Subscription.
Example:
int solve(formula* form)
{
/* Create the structures to store the state of the
* algorithm */
bool *assigned = (bool *) calloc(form->nvars + 1, sizeof(bool));
bool *vals = (bool *) calloc(form->nvars + 1, sizeof(bool));
stack_item **sitems = (stack_item **) malloc(form->nvars * sizeof(stack_item*));
stack s;
s.items = sitems;
// Get a pointer to the literal that needs assignment, if one exists
if ((lp = is_unitclause(form->clauses[i], assigned, vals)) != NULL)
{
assert_literal(lp, vals, assigned);
stack_item si = {lp, i, 0};
push_stack(&s, &si);
}