Skip to content

Instantly share code, notes, and snippets.

View dpzmick's full-sized avatar

David Zmick dpzmick

View GitHub Profile
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#if defined(__x86_64__)
// fakes a read+write to register
// using 'r' means that the value will be placed into a _general_ register for
// the read if it not already in one, then possible re-read into another
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <stdint.h>
#include <pthread.h>
N = 1000
# make two scripts to pass to clickhouse client to demonstrate sadness with
# materialized columns
with open('create.sql', 'w') as f:
f.write("DROP DATABASE IF EXISTS test;")
f.write("CREATE DATABASE test;")
# --- fast table as a baseline
# simple error correcting code
# assume that data is transmitted over a channel which
# sometimes corrupts the data stream
#
# for example, if we sent the bits 10110011
# we might receive 10110010 on the other side
#
# Consider a channel which has a 1% chance of incorrectly transmitting each bit
# that is sent.
# Additionally, assume messages we send contain 100 bits.

Understanding Pin for C and C++ developers

My initial impression of Pin was that it said “hey there’s something sitting at this memory location. Feel free to use it, even though, in this context, the compiler can’t lexically prove that it is actually still there.” My understanding of Pin was roughly that it was a backdoor through the lifetime system.

Opening up the documentation, the page starts with a discussion about Unpin. Unpin is weird. Basically, Unpin says “yeah I know this

@dpzmick
dpzmick / rb_move_semantics.cpp
Created November 10, 2019 21:34
possibly incorrect ring buffer move semantics explanation
#include <array>
#include <iostream>
#include <stdexcept>
template <typename T, size_t N>
struct ring_buffer {
std::array<T, N+1> entries;
T* head = entries.data(); // pop from here
T* tail = head+1; // push to here, one past the end
@dpzmick
dpzmick / 0_test.c
Last active October 10, 2019 06:18
get wrecked clang
#include <stdlib.h>
int test() {
int *x = NULL;
int y = rand();
int z = rand();
int v = 4;
if (z == 8) x = &v;
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <x86intrin.h>
/*
@dpzmick
dpzmick / topsort.cpp
Last active October 6, 2017 04:55
fragile topological sort in c++ templates
#include <cstddef>
#include <iostream>
#include <sstream>
#include <type_traits>
struct nil { };
template <typename H, class T>
struct cons
{
#include <cstddef>
#include <iostream>
#include <type_traits>
struct nil { };
template <typename H, class T>
struct cons
{
using head = H;