Skip to content

Instantly share code, notes, and snippets.

View etscrivner's full-sized avatar
🦋

Eric Scrivner etscrivner

🦋
View GitHub Profile
@etscrivner
etscrivner / render_hiero_font.cc
Last active December 1, 2019 20:55
Parse and render text from SDF font generated by Hiero.
#include <SDL.h>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <scaffold/types.h>
#include <scaffold/gl.h>
#include <scaffold/memory_arena.h>
#include <scaffold/matrix.h>
@etscrivner
etscrivner / bulk_list.c
Created November 23, 2019 20:57
Bulk list data structure.
#include "bulk_list.h"
#include <stdio.h>
#include <stdlib.h>
bulk_list_t bulk_list_create(int32_t initial_capacity, bulk_list_item_id_t item_size)
{
bulk_list_t result = { NULL, item_size, initial_capacity, 1, 0, 0, 1 };
result.items = (uint8_t*)realloc(result.items, result.capacity * result.item_size);
((bulk_list_item_t*)&result.items[0])->next = 0;
@etscrivner
etscrivner / audio_mixer.cc
Created November 15, 2019 16:38
Simple audio mixer in SDL2
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <SDL.h>
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
@etscrivner
etscrivner / Makefile
Last active November 15, 2023 19:49
Pixel-perfect 2D collision detection in SDL.
.PHONY: run
CXXFLAGS=-Wall -g -fno-exceptions -fno-rtti $(shell pkg-config sdl2 --cflags)
LDFLAGS=-lm $(shell pkg-config sdl2 --libs)
game: game.cc
$(CXX) $(CXXFLAGS) -o game game.cc $(LDFLAGS)
run: game
./game
@etscrivner
etscrivner / feature_package_relay.py
Last active October 2, 2019 14:29
Add test that three transaction package relay fails.
#!/usr/bin/env python3
# Copyright (c) 2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test processing of two-transaction packages"""
from decimal import Decimal
from test_framework.messages import FromHex, CTransaction, msg_witness_tx
from test_framework.mininode import P2PInterface
from test_framework.test_framework import BitcoinTestFramework
set title 'Change Frequency By File'
set ylabel '# Changes'
set xlabel 'File'
plot 'output.txt' using 0:1
@etscrivner
etscrivner / cartographer_data_model.als
Created April 17, 2019 18:44
Alloy model of PSP data model
sig Defect {
phase : one Phase,
performance : one Performance,
type : one DefectType,
}
sig DefectType {}
fact DefectsBelongToAPhaseOfTheSameProcessAsItsPerformance {
all d : Defect | d.phase.process = d.performance.process
@etscrivner
etscrivner / peterson_multi.tla
Last active January 26, 2019 20:57
TLA+ implementation of Peterson's mutual exclusion algorithm. Demonstrates absence of deadlock and liveness given fair processes.
--------------------------- MODULE peterson_multi ---------------------------
EXTENDS TLC, Integers, Sequences
CONSTANT ThreadCount
Threads == 1..ThreadCount
AllOtherFlagsLessThan(item, flags) ==
\A q \in Threads \ {item}: flags[q] < item
(*--algorithm peterson_multi
variables
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Point<T> {
pub a : T,
pub b : T,
pub x : Option<T>,
pub y : Option<T>
}
impl<T> Point<T> {
pub fn infinity(a: T, b: T) -> Self {
@etscrivner
etscrivner / rpc_doctest.cpp
Last active October 5, 2018 04:12
Bitcoin RPC API documentation helper object prototype.
#include <iostream>
#include <string>
#include <vector>
class RPCArgument {
public:
RPCArgument(const std::string& name,
const std::string& type,
const std::string& description,
bool required=false,