Skip to content

Instantly share code, notes, and snippets.

View threaded.c
#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>
View sad_ch_perf.py
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
View p1.py
# 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.
View rs-cpp.org

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 Nov 10, 2019
possibly incorrect ring buffer move semantics explanation
View rb_move_semantics.cpp
#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 Oct 10, 2019
get wrecked clang
View 0_test.c
#include <stdlib.h>
int test() {
int *x = NULL;
int y = rand();
int z = rand();
int v = 4;
if (z == 8) x = &v;
View quadtree.c
#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 Oct 6, 2017
fragile topological sort in c++ templates
View topsort.cpp
#include <cstddef>
#include <iostream>
#include <sstream>
#include <type_traits>
struct nil { };
template <typename H, class T>
struct cons
{
View views.cpp
#include <cstddef>
#include <iostream>
#include <type_traits>
struct nil { };
template <typename H, class T>
struct cons
{
using head = H;
View apply.cpp
#include <tuple>
#include <iostream>
class LoudCopy
{
public:
LoudCopy() { }
LoudCopy(const LoudCopy&) = delete;
LoudCopy(LoudCopy&&) {}
};