Skip to content

Instantly share code, notes, and snippets.

View GavinRay97's full-sized avatar

Gavin Ray GavinRay97

View GitHub Profile
@GavinRay97
GavinRay97 / index.md
Last active April 12, 2024 18:31
Hasura organization permissions

Introduction

This document outlines how to model a common organization-based permission system in Hasura. Let's assume that you have some table structure like the following:

Table Name Columns Foreign Keys
User id, name, email
Organization User id, user_id, organization_id user_id -> user.id, organization_id -> organization.id
Organization id, name
@GavinRay97
GavinRay97 / extensions.json
Created June 7, 2021 18:21
VS Code "clangd" base config, with: CMake Tools extension, MS C/C++ extension (debugging), vcpkg integration
{
"recommendations": [
"twxs.cmake",
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"llvm-vs-code-extensions.vscode-clangd"
]
}
@GavinRay97
GavinRay97 / auth.module.ts
Last active February 22, 2024 10:57
Hasura Nest.js JWT Auth utils (REST + GQL)
import { Module } from '@nestjs/common'
import { AuthService } from './auth.service'
@Module({
providers: [AuthService],
exports: [AuthService],
})
export class AuthModule {}
@GavinRay97
GavinRay97 / Makefile
Last active February 17, 2024 05:06
Dump C/C++ vtable & record layout information (clang + msvc + gcc)
# Requirements:
# clang - The classes/structs you want to dump must be used in code at least once, not just defined.
# MSVC - The classes/structs you want to dump must have "MEOW" in the name for "reportSingleClass" to work.
# Usage:
# $ make dump_vtables file=test.cpp
dump_vtables:
clang -cc1 -fdump-record-layouts -emit-llvm $(file) > clang-vtable-layout-$(file).txt
clang -cc1 -fdump-vtable-layouts -emit-llvm $(file) > clang-record-layout-$(file).txt
g++ -fdump-lang-class=$(file).txt $(file)
cl.exe $(file) /d1reportSingleClassLayoutMEOW > msvc-single-class-vtable-layout-$(file).txt
@GavinRay97
GavinRay97 / mutexes.ts
Created January 29, 2023 16:30
TypeScript Node.js/Browser Mutex + Read-Write Mutex using Atomics
class AsyncLock {
private _lock = new Int32Array(new SharedArrayBuffer(4)) // SharedArrayBuffer for multi-threading, 4 bytes for 32-bit integer
static INDEX = 0
static UNLOCKED = 0
static LOCKED = 1
lock() {
while (true) {
console.log("lock")
@GavinRay97
GavinRay97 / main.cpp
Last active January 13, 2024 01:45
[C++] Atomic Tagged Pointer (uint16 version counter + 3-bit tag/storage)
#include <atomic>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <optional>
// A word-aligned, atomic tagged pointer.
// Uses both the upper 16 bits for storage, and the lower 3 bits for tagging.
//
// 64 48 32 16
private async _runK6(metadata: RunK6Metadata, config: K6Options) {
const { queryName, outputFile } = metadata
// If "debug" true, log all HTTP responses
if (this.config.debug) config.httpDebug = 'full'
// Write the K6 configuration JSON to a temp file, to pass as CLI flag
const tmpConfig = path.join(__dirname, 'tmp', `${queryName}_config.json`)
await fs.outputJSON(tmpConfig, config)
@GavinRay97
GavinRay97 / JdbcDatabaseWrappingSchema.java
Last active December 25, 2023 19:57
Apache Calcite - Schema that consumes a datasource connected to a JDBC DB and generates a schema map for all sub-schemas
package com.example;
import org.apache.calcite.adapter.jdbc.JdbcSchema;
import org.apache.calcite.avatica.AvaticaUtils;
import org.apache.calcite.schema.Schema;
import org.apache.calcite.schema.SchemaFactory;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.impl.AbstractSchema;
import javax.sql.DataSource;
@GavinRay97
GavinRay97 / flags.txt
Last active December 1, 2023 22:06
Good Clang C++ Flags
# Created with: $ diagtool tree
-Wall
-Wextra
-Wpedantic
-Warray-bounds-pointer-arithmetic
-Wbind-to-temporary-copy
-Wcalled-once-parameter
-Wcast-align
@GavinRay97
GavinRay97 / extract-hunt-weapons.js
Last active November 20, 2023 20:56
Hunt Weapon extraction script
// Script to run on https://huntshowdown.rocks/en/weapons to extract weapon info
const meleeVariantNames = [
"Precision",
"Deadeye",
"Marksman",
"Sniper",
"Bayonet",
"Riposte",
"Trauma",
"Striker",