Skip to content

Instantly share code, notes, and snippets.

View cornedriesprong's full-sized avatar

Corné cornedriesprong

View GitHub Profile
@cornedriesprong
cornedriesprong / ring_buffer.c
Created May 18, 2024 09:29
a simple, thread-safe, single producer-single consumer ring buffer in plain c
#include <assert.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
void *data;
atomic_int head, tail, num_entries, size;
} ring_buffer;
@cornedriesprong
cornedriesprong / spaces.json
Last active November 21, 2018 15:45
spaces.json
[
{
"type":"basics",
"sections": [
{
"identity":
[
{
"type": "drivers_license",
"first_name": "Corné",
[
{
"header": "yo",
"body": "boo",
"date": "2018-11-21T10:14:13+00:00",
"state": "verified",
"image_name": ""
},
{
"header": "wow",
// infix flatMap operator - copied verbatim from http://www.objc.io/blog/2014/10/27/functional-snippet-4-flattening-and-mapping-arrays/
infix operator >>= {}
func >>=<A, B>(xs: [A], f: A -> [B]) -> [B] {
return xs.map(f).reduce([], combine: +)
}
// decomposes array xs into a tuple containing the first element and the rest of the array. copied and edited from http://www.objc.io/blog/2014/10/06/functional-snippet-1-decomposing-arrays/
func decompose<T>(xs: [T]) -> (T, [T])? {
return xs.count > 0 ? (xs[0], Array(xs[1..<xs.count])) : nil