Skip to content

Instantly share code, notes, and snippets.

@kevinAlbs
kevinAlbs / test-unaligned.c
Created April 23, 2025 12:05
Example of UBSan error from unaligned access
/*
Example of UBSan error from unaligned access. To run:
$ clang -std=c11 -fsanitize=undefined -o test-unaligned test-unaligned.c
$ ./test-unaligned
alignof(size_t) is 8
unaligned address: 0x146606951
test-unaligned.c:16:4: runtime error: store to misaligned address 0x00013e606951 for type 'size_t' (aka 'unsigned long'), which requires 8 byte alignment
*/
cmake_minimum_required(VERSION 3.25)
project(HelloAmongoc)
add_executable(hello-amongoc hello-amongoc.c)
find_package(amongoc REQUIRED)
target_link_libraries(hello-amongoc amongoc::amongoc)
"""
Test inserting 100,000 documents with bulkWrite, w:0 write concern, and ordered:false.
Observe final count of 99,999 on sharded clusters.
To run, start a sharded cluster with:
mlaunch init \
--replicaset \
--nodes=1 \
--sharded=1 \
--mongos=1 \
@kevinAlbs
kevinAlbs / cares-example.c
Created July 18, 2024 02:20
Example using c-ares to try DNS lookup to a non-listening local port.
/*
To build:
cc -o example example.c -g -I $INSTALL_PATH/include -L $INSTALL_PATH/lib -Wl,-rpath $INSTALL_PATH/lib -lcares
To run:
./example
*/
#include <stdio.h>
#include <stdlib.h> // getenv
#include <string.h>
@kevinAlbs
kevinAlbs / calc_release_version_selftest.sh
Created May 25, 2023 21:50
Proposed self tests of calc_release_version.py
# calc_release_version_selftest.sh is used to test output of calc_release_version.py.
# run with:
# cd build
# ./calc_release_version_selftest.sh
function assert_eq () {
a="$1"
b="$2"
if [[ "$a" != "$b" ]]; then
echo "Assertion failed: $a != $b"
@kevinAlbs
kevinAlbs / validate.py
Created May 21, 2023 14:05
Validate that all tasks in an Evergreen config are used.
import sys
import yaml
try:
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader
# Load evaluated Evergreen config.
# `evaluated.yml` was created by running: `evergreen evaluate ./.evergreen/config.yml > evaluated.yml`
with open("evaluated.yml", "r") as file:
@kevinAlbs
kevinAlbs / getMore-changestream.json
Created March 3, 2023 14:47
Sample change stream reply
{
"cursor": {
"nextBatch": [
{
"_id": {
"_data": "826402082C000000022B042C0100296E5A1004F5EE0D4649F9441FBB3F8068DB145455463C6F7065726174696F6E54797065003C64656C6574650046646F63756D656E744B657900461E5F69640029000004"
},
"operationType": "delete",
"clusterTime": {
@kevinAlbs
kevinAlbs / openssl_static.py
Last active February 8, 2023 19:43
Suggested alternative for OpenSSL static testing. See https://github.com/mongodb/mongo-c-driver/pull/1201
from shrub.v3.evg_build_variant import BuildVariant
from shrub.v3.evg_task import EvgTaskRef
from config_generator.etc.distros import find_large_distro
from config_generator.etc.distros import make_distro_str
from config_generator.etc.distros import to_cc
from config_generator.etc.utils import EvgTaskWithRunOn
from config_generator.etc.sasl.compile import CompileCommon
from config_generator.components.funcs.upload_build import UploadBuild
PR=${PR:-}
REPO=${REPO:-}
ORG=${ORG:-mongodb}
if [[ "$(basename $(pwd))" != "review" ]]; then
echo "Must be in 'review' directory";
exit 1;
fi
if [[ -z "$PR" ]]; then
PR=${PR:-}
REPO=${REPO:-}
ORG=${ORG:-mongodb}
if [[ "$(basename $(pwd))" != "review" ]]; then
echo "Must be in 'review' directory";
exit 1;
fi
if [[ -z "$PR" ]]; then