Skip to content

Instantly share code, notes, and snippets.

View GavinRay97's full-sized avatar

Gavin Ray GavinRay97

View GitHub Profile
@GavinRay97
GavinRay97 / main.cpp
Created December 12, 2022 16:09
Linux 6.1 new Direct IO (DIO) "statx" file information example
#include <fcntl.h> // open, O_CREAT, O_RDWR, AT_FDCWD, AT_STATX_SYNC_AS_STAT
#include <stdio.h> // printf
#include <sys/stat.h> // statx, STATX_ALL
#include <unistd.h> // pwrite
#define TMPFILE "test.txt"
int
main()
{
@GavinRay97
GavinRay97 / main.cpp
Created December 9, 2022 19:00
P2590R2: "Explicit lifetime management" (start_lifetime_as) implementation
// How can we make this program well-defined without sacrificing efficiency? If the destination type
// is a trivially-copyable implicit-lifetime type, this can be accomplished by copying the storage
// elsewhere, using placement new of an array of byte-like type, and copying the storage back to its
// original location, then using std::launder to acquire a pointer to the newly-created object, and
// finally relying on the compiler to optimise away all the copying. However, this would be very
// verbose and hard to get right. For expressivity and optimisability, a combined operation to
// create an object of implicit-lifetime type in-place while preserving the object representation
// may be useful. This is exactly what std::start_lifetime_as is designed to do
template<class T>
@GavinRay97
GavinRay97 / Makefile
Created December 8, 2022 21:21
A Makefile to compile a Maven/Gradle-style project layout using a custom JDK (for use w/ IE, Valhalla)
# Makefile to compile and run Java sources manually
# because JDK 20 Valhalla support is not yet available in IntelliJ IDEA
JAVA_VERSION = 20
JAVAC = /home/user/downloads/jdk-20-vahalla-20-75/bin/javac
JAVA = /home/user/downloads/jdk-20-vahalla-20-75/bin/java
JAVA_COMPILE_OPTIONS = --enable-preview --release $(JAVA_VERSION)
JAVA_OPTIONS = --enable-preview
JAVA_MAIN_CLASS = org.example.Database
@GavinRay97
GavinRay97 / dump-clang-format-flags.js
Last active December 4, 2022 19:54
Dump "clang-format" flags (name, arg-type, initial version, and description) from LLVM website using browser or Node.js
// If in Node.js, need DOMParser.
if (typeof DOMParser === "undefined") {
global.DOMParser = require("xmldom").DOMParser;
}
// If Node.js is pre-v17.5, need fetch from node-fetch too.
if (typeof fetch === "undefined") {
global.fetch = require("node-fetch");
}
const CLANG_FORMAT_FLAG_URL = "https://clang.llvm.org/docs/ClangFormatStyleOptions.html"
@GavinRay97
GavinRay97 / clang-dump-warnings.sh
Last active December 3, 2022 19:41
Clang Warning Flag Dumper + Diff Viewer script
#!/bin/bash
# This script is used to dump the warnings from the clang compiler
# into a file, and let you view/dump the diff between the warnings.
# $ clang-dump-warnings.sh <enable-diffs> <compiler-flags>
# Example:
# $ clang-dump-warnings.sh true -Wall -Wextra -Werror -Wno-unused-parameter
@GavinRay97
GavinRay97 / CMakePresets.json
Created November 23, 2022 03:21
CMake Presets
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"patch": 0
},
"configurePresets": [
{
"hidden": true,
@GavinRay97
GavinRay97 / vtable.zig
Created November 21, 2022 01:08
Zig VTable example
pub fn HeapPage_init(self: *HeapPage) void {
self.page.header.lsn = 0;
self.page.header.num_records = 0;
self.page.header.free_space_end = @intCast(u16, PAGE_SIZE);
}
pub fn HeapPage_getFreeSpace(self: *HeapPage) u16 {
return self.page.header.free_space_end - HEADER_SZ - self.page.header.num_records * SLOT_SZ;
}
@GavinRay97
GavinRay97 / main.sh
Last active December 10, 2022 21:03
Compile GCC from source
$ sudo dnf install flex
$
$ git clone git://gcc.gnu.org/git/gcc.git gcc-dev
$ cd gcc-dev
$
$ ./contrib/download_prerequisites
$ mkdir build && cd build
$
$ ../configure -v \
--build=x86_64-linux-gnu \
@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 / build.sh
Last active December 20, 2022 20:45
LLVM CMake Fast Build
# From ~/projects/llvm-project/
# "compiler-rt" is needed so that you can link against it, otherwise you'll get errors when using -fsanitizer about libclang_rt.san
$ cmake -S llvm -B build -G Ninja \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb" \
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi" \
-DLLVM_TARGETS_TO_BUILD=X86 \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_CCACHE_BUILD=ON \
-DLLVM_USE_LINKER=mold \
-DCMAKE_BUILD_TYPE=Release \