Skip to content

Instantly share code, notes, and snippets.

View GavinRay97's full-sized avatar

Gavin Ray GavinRay97

View GitHub Profile
GavinRay97 / Makefile
Last active July 7, 2024 06:17
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
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 / flags.txt
Last active May 31, 2024 10:34
Good Clang C++ Flags
# Created with: $ diagtool tree
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": [
GavinRay97 /
Last active May 16, 2024 22:11
Arrow Java DataFrame proof-of-concept
package com.example;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.BitVector;
import org.apache.arrow.vector.FieldVector;
import org.apache.arrow.vector.FloatingPointVector;
import org.apache.arrow.vector.IntVector;
import org.apache.arrow.vector.VarBinaryVector;
import org.apache.arrow.vector.VarCharVector;
import org.apache.arrow.vector.VectorSchemaRoot;
GavinRay97 /
Last active April 12, 2024 18:31
Hasura organization permissions


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 ->, organization_id ->
Organization id, name
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'
providers: [AuthService],
exports: [AuthService],
export class AuthModule {}
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) {
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 /
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;