Skip to content

Instantly share code, notes, and snippets.

View GavinRay97's full-sized avatar

Gavin Ray GavinRay97

View GitHub Profile
@GavinRay97
GavinRay97 / Makefile
Last active January 16, 2025 18:35
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 / Makefile
Last active September 29, 2024 02:00
WASM copy structs to memory from host -> module
WASI_VERSION_FULL = 20.0
WASMTIME_DIR = ../third-party/wasmtime-dev-x86_64-linux-c-api
WASI_SDK_PATH = ./wasi-sdk-$(WASI_VERSION_FULL)
CC = clang++
WASM_CC = $(WASI_SDK_PATH)/bin/clang++ --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot
CFLAGS = -std=c++20 -I$(WASMTIME_DIR)/include -L$(WASMTIME_DIR)/lib
LIBS = -lwasmtime
@GavinRay97
GavinRay97 / write-ahead-log.cpp
Created February 8, 2023 15:28
C++ Database Write-Ahead-Log simple proof of concept
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <optional>
#include <span>
#include <string>
// A write-ahead log is a log of all the operations that have been performed on the database.
struct LogEntryHeader
@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 / readme.md
Last active August 22, 2024 01:23
Making Apache Calcite work in SQuirreL SQL Client

Making Apache Calcite work in SQuirreL SQL Client

Recently I wanted to test some Calcite functionality, and thought it might be nice to use a GUI instead of sqlline. It turns out, it is:

image

I figured you could just use something like SquirreL, which lets you import arbitrary JDBC drivers. This was less straightforward than I thought.

@GavinRay97
GavinRay97 / flags.txt
Last active May 31, 2024 10:34
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 / DataFrame.java
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
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 / 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 / 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")