Skip to content

Instantly share code, notes, and snippets.

View stefalie's full-sized avatar

Stefan Lienhard stefalie

View GitHub Profile
@stefalie
stefalie / pandoc-pygmentize
Created December 13, 2021 22:40 — forked from DoomHammer/pandoc-pygmentize
Quick-and-dirty pandoc filter to pass all code blocks through pygments highlighter
#!/usr/bin/env python
"""
Pandoc filter to pass all code blocks through pygments highlighter.
"""
from pandocfilters import toJSONFilter, RawBlock
from pygments import highlight
from pygments.lexers import (get_lexer_by_name, guess_lexer, TextLexer)
from pygments.formatters import get_formatter_by_name
@stefalie
stefalie / morton.h
Created September 30, 2021 18:30 — forked from JarkkoPFC/morton.h
Faster 16/32bit 2D Morton Code encode/decode functions
uint16_t encode16_morton2(uint8_t x_, uint8_t y_)
{
uint32_t res=x_|(uint32_t(y_)<<16);
res=(res|(res<<4))&0x0f0f0f0f;
res=(res|(res<<2))&0x33333333;
res=(res|(res<<1))&0x55555555;
return uint16_t(res|(res>>15));
}
//----
@stefalie
stefalie / svd_glsl.glsl
Created September 28, 2021 22:59 — forked from alexsr/svd_glsl.glsl
SVD and other matrix decompositions on 3x3 matrices written in GLSL
// This is a GLSL implementation of
// "Computing the Singular Value Decomposition of 3 x 3 matrices with
// minimal branching and elementary floating point operations"
// by Aleka McAdams et.al.
// http://pages.cs.wisc.edu/~sifakis/papers/SVD_TR1690.pdf
// This should also work on the CPU using glm
// Then you probably should use glm::quat instead of vec4
// and mat3_cast to convert to mat3.
@stefalie
stefalie / rubix.py
Created August 14, 2021 19:59 — forked from fogleman/rubix.py
Simple 2x2x2 Rubik's Cube Solver in Python
import sys
# -------
# | 16 17 |
# | Y |
# | 18 19 |
# ------- ------- ------- -------
# | 12 13 | 00 01 | 04 05 | 08 09 |
# | X | Z | X | Z |
# | 14 15 | 02 03 | 06 07 | 10 11 |
@stefalie
stefalie / _GJK.md
Created November 8, 2020 19:22 — forked from vurtun/_GJK.md
3D Gilbert–Johnson–Keerthi (GJK) distance algorithm

Gilbert–Johnson–Keerthi (GJK) 3D distance algorithm

The Gilbert–Johnson–Keerthi (GJK) distance algorithm is a method of determining the minimum distance between two convex sets. The algorithm's stability, speed which operates in near-constant time, and small storage footprint make it popular for realtime collision detection.

Unlike many other distance algorithms, it has no requirments on geometry data to be stored in any specific format, but instead relies solely on a support function to iteratively generate closer simplices to the correct answer using the Minkowski sum (CSO) of two convex shapes.

@stefalie
stefalie / zigzag-encoding.README
Created October 25, 2020 13:59 — forked from mfuerstenau/zigzag-encoding.README
ZigZag encoding/decoding explained
ZigZag-Encoding
---------------
Maps negative values to positive values while going back and
forth (0 = 0, -1 = 1, 1 = 2, -2 = 3, 2 = 4, -3 = 5, 3 = 6 ...)
(i >> bitlength-1) ^ (i << 1)
with "i" being the number to be encoded, "^" being
XOR-operation and ">>" would be arithemtic shifting-operation
#include <windows.h>
#include <GL/gl.h>
#include <stdio.h>
#pragma comment(lib, "opengl32.lib")
void glview()
{
HWND hWnd = CreateWindow(L"ListBox", L"Title", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
HDC hDC = GetDC(hWnd);
@stefalie
stefalie / glx.cpp
Created May 4, 2020 09:50 — forked from rygorous/glx.cpp
GLX
GLuint glx_compile_shader_source( GLenum type, char const * source )
{
if ( !source )
return 0;
// explicitly copy the source together so we can dump it as one string
size_t source_len = strlen( source );
char * fused_source = new char[shader_header_len + source_len + 1];
strcpy( fused_source, shader_header );
strcpy( fused_source + shader_header_len, source );
#if _WIN32
// measure the time in seconds to run f(). doubles will retain nanosecond precision.
template<typename F>
double timeit(F f) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
LARGE_INTEGER start;
QueryPerformanceCounter(&start);
f();
LARGE_INTEGER end;
#if _WIN32
struct Timer {
LARGE_INTEGER win32_freq;
LARGE_INTEGER win32_start;
Timer() {
QueryPerformanceFrequency(&win32_freq);
win32_start.QuadPart = 0;
}