Skip to content

Instantly share code, notes, and snippets.

@SeijiEmery
SeijiEmery / allocator.hpp
Last active March 15, 2017 17:32
Pooled allocator example (for context, planning on using StackAllocator as memory backend for a polymorphic vtbl-based command buffer implementation)
// Defines 2 allocators: PooledAllocator, an allocator-allocator, and StackAllocator,
// a contiguous-region-polymorphic allocator that allocates + recycles chunks from PooledAllocator.
// Note: these are both stateful, custom allocators, and do NOT conform to std::allocator.
// Note: not tested; will try compiling later. Should work.
template <typename Traits>
class MemoryChunk : public Traits::Base {
MemoryChunk () : data(traits::Allocator::malloc(Traits::size)) {}
~MemoryChunk () { traits::Allocator::free(data); }
@SeijiEmery
SeijiEmery / pi.py
Last active August 6, 2017 17:42
pi in a nutshell
#!/usr/bin/env python
import math
from math import sqrt
def pi (n):
x = 1
for i in range(n):
x = 2 - sqrt(4 - x)
return 3 * 2 ** n * sqrt(x)
@SeijiEmery
SeijiEmery / text_layouter_snippet.cxx
Created February 9, 2017 04:52
Simple text layouting algorithm
namespace layout {
class Style {
// Border
float bl, br, bb, bt;
float minw, minh, maxw, maxh;
auto bwidth () const { return bl + br; }
auto bheight () const { return bb + bt; }
};
@SeijiEmery
SeijiEmery / concept.txt
Last active February 1, 2017 01:14
Quick game concept: space battle simulator (semi-realistic space combat; VR)
Space War (Standing VR, targeting Vive, etc)
Note: not really a gist thing, but will post to blog once that's working again.
Builds on ideas in other game concepts (VR "omniscient grab-cam", etc – would be annoyed
if someone implements that before I get around to it, but so far so good...).
In a nutshell: For anyone who's read Ender's Game or watched the (pretty awesome) movie version,
remember the battle simulator / control room used to control fleet actions? Basically that.
– Symbolic 3d Vector graphics*
– User Interface: 3d Point & click**, gestural, contextual menus linked to buttons + thumbpads***
@SeijiEmery
SeijiEmery / gist:d059933a168bc7e1ceedacb4a45e4aad
Last active January 30, 2017 23:19
Significant figures + concept for lab excel replacement (had this idea floating around for a while)
Sig figs (pet peeve):
As a CS / sort-of math major, it seems like it would make much more sense to just record scientific
measurements as ranges / intervals, ie. (4.867 ± 0.0005), and treat them as algebraic pairs / 2-tuples,
with a few special rules for how the error value gets carried; a neat result would be that in exact
(infinite precision) figures the error value is zero, eg (4.25 ± 0)
Rules are quite simple, with the rule that numbers are represented by (a + be), where e is a symbolic
placeholder like i, and defined such that e^n = e^m for all n, m ≠ 0. (ie. e propagates, but e^2 = e = e^-1, etc).
// This is a snippet from https://github.com/SeijiEmery/GLSandbox/blob/master/fsevents-test/main.cpp
void fsEventCallback (
ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[]
) {
@SeijiEmery
SeijiEmery / primes.py
Last active January 30, 2017 23:32
Yet another prime sieve (and comparison w/ naive impl)
# Note: designed to be a lazy algorithm (but didn't get that working),
# which is why primeSieve() operates on "chunks" of primes and may reuse
# prev results.
#
# Todo:
# – since only arithmetic + shifts, could use python bignums (or write
# own algorithms) to hit arbitrary bounds
# – key is storage: need to store primes as deltas, and implement algorithm
# that operates w/ prime deltas and _one_ bignum instead of lots of big numbers.
# This would solve lots of issues + make massively more efficient (I think)
@SeijiEmery
SeijiEmery / asm_sandbox.c
Last active January 30, 2017 23:34
API spec for graphical x86 assembly (write directly to 2d framebuffer in RGB8 or something). Would wrap GLFW & provide alternate API.
/*
ASM Sandbox:
– A graphical sandbox for x86 assembly.
– Sandbox portion is implemented using glfw + some gui toolkit. (imgui?)
– Assembly programs are assembled, then loaded _into_ the sandbox, as opposed
to linking to + launching the sandbox themselves. Benefit is faster iteration
times and hotloading.
x86 API(s):
– Starting function is <module_name>_main
@SeijiEmery
SeijiEmery / masm_nasm_comparison.asm
Last active November 15, 2019 02:07
assembly notes, etc
;
; nasm / masm comparison.
;
; First I'm going to briefly discuss how nasm does things, because it's
; simpler, and then show how this applies to masm.
;
; This should hopefully improve your understanding of masm, and
; understand what its quirks are and why + how it does things.
;
@SeijiEmery
SeijiEmery / hello.c
Last active August 26, 2016 22:48
Commandline colored text (c stdlib); compatible with _most_ terminals
//
// see http://stackoverflow.com/questions/3219393/stdlib-and-colored-output-in-c
// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
//
// This is based on the xterm 24-bit RGB format, and from my own testing, is compatible
// with bash, fish, and zsh.
//
#include "stdio.h"