Skip to content

Instantly share code, notes, and snippets.

View catchouli's full-sized avatar
💭
type 2 invested entity

Caitlin Wilks catchouli

💭
type 2 invested entity
View GitHub Profile
@catchouli
catchouli / back
Last active October 26, 2024 21:49
Anki chessground card with pgn seeking
{{FrontSide}}
<hr id=answer>
<div id="controls">placeholder text</div>
<script type="module">
import {
init,
classModule,
module Main where
import Control.Monad.Random
import Data.Char
-- | Get all word ranges in string
accumWords :: (Char -> Bool) -> String -> [String]
accumWords pred str = allWords
where (last, others, _) = foldl accumWords' ("", [], True) str
allWords = others ++ [last]
module Main where
import Control.Monad.Random.Strict
import Data.Array.MArray
import Data.Array.IO
import Data.Char
-- | Swap two elements in an array
swap :: (MArray a e m, Ix i) => a i e -> i -> i -> m ()
swap arr i j = do
@catchouli
catchouli / example
Last active March 29, 2018 14:24
scala simple scenegraph
val hexapod = new AssemblyNode {
transform.scale(0.1f, 0.1f, 0.1f)
// Body
children += new AssemblyNode {
children += new ModelNode(assets.get("assets/Base.obj"))
}
// Legs
(1 to 6).foreach(i => {
@catchouli
catchouli / header.hpp
Created June 18, 2015 19:30
pimpl - dont forget your copy constructors and shit
#pragma once
class SomeClass
{
public:
SomeClass();
~SomeClass();
SomeClass(const SomeClass&);
SomeClass& SomeClass(const SomeClass&);
@catchouli
catchouli / gist:68a91251009dcfcccfa8
Created June 14, 2015 16:45
WinMain w/o windows.h
#ifndef _INC_WINDOWS
struct HINSTANCE__;
typedef struct HINSTANCE__ *HINSTANCE;
#endif
int __stdcall WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
char* lpCmdLine,
int nCmdShow);
vec3 interpolate(vec3 tri[3], vec3 vals[3], vec3 intersection)
{
// Calculate barycentric coordinates
float one_over_tri_area = 2.0f / length(cross(tri[1] - tri[0], tri[2] - tri[1]));
float u = 0.5f * one_over_tri_area * length(cross(tri[1] - intersection, tri[2] - intersection));
float v = 0.5f * one_over_tri_area * length(cross(tri[0] - intersection, tri[2] - intersection));
float w = 0.5f * one_over_tri_area * length(cross(tri[0] - intersection, tri[1] - intersection));
return vals[0] * u + vals[1] * v + vals[2] * w;
@catchouli
catchouli / 1. usage
Last active August 29, 2015 14:14
Signal/Socket C++ test
Signal<int> sig;
sig.connect(staticFunctionTest);
sig.connect([](int i){ printf("lambda function test %d\n", i); });
sig.connect(&test, &Test::test);
sig.emit(5);
@catchouli
catchouli / offset
Created January 4, 2015 14:57
a relic from the deepest darkest corners of c++
template <typename T, typename F>
size_t offset(F T::* ptr)
{
T* typePtr = (T*)nullptr;
F* memberPtr = &(typePtr->*ptr);
uintptr_t offset = (uintptr_t)memberPtr - (uintptr_t)typePtr;
return offset;
}
@catchouli
catchouli / test.cpp
Created January 4, 2015 03:32
coment_rewrite interface example
World world;
EntityManager& em = *world.getManager<EntityManager>();
ComponentManager& cm = *world.getManager<ComponentManager>();
Entity e = em.createEntity();
auto positionMap = cm.getEntityMap<Position>();
auto velocityMap = cm.getEntityMap<Velocity>();
auto radiusMap = cm.getEntityMap<Radius>();
auto moverMap = cm.getEntityMap<Position, Velocity>();