Skip to content

Instantly share code, notes, and snippets.

Micha Mettke vurtun

  • Germany
View GitHub Profile
@vurtun
vurtun / com.c
Last active Mar 16, 2019
Image processing
View com.c
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
struct img {
size_t w, h;
size_t area;
size_t size;
unsigned char buf[];
};
static struct img*
View layout.c
// --- Library --------------------------------------------------------------------------
#include <string.h>
#include <assert.h>
struct ui_box {int x,y,w,h;};
typedef unsigned long long ui_id;
struct ui_node {
int parent;
int lst, end;
int nxt, cnt;
View allocator.md

This is a short post related to Opaque object representations from Our Machinery. I have to begin that my understanding of how Our Machineries tech is somewhat limit and it is currently rather late in the day, so please bear with me. As far as I understood how modules work is similar to how Quake 2 did their modules. A module has both a struct for export and one for import containing a number of function pointer. At load time the module gets a filled out import struct and fills out its own export struct with its own functions and returns it.

As for the allocators. I would have guessed tha

View _hyperlog.c
//=====================================================================================================
// HyperLog
//=====================================================================================================
#define HL_HASH32_COUNT 4
#define HL_SPACE(NUM_REGISTER_BITS) (1 << NUM_REGISTER_BITS)
static void
hl_add(unsigned char* log, size_t size, unsigned *hash4)
{
assert(size > 0);
@vurtun
vurtun / sched.c
Last active Jan 15, 2019
Greedy Schedule
View sched.c
#include <stdio.h>
#include <stdlib.h>
#if defined(__clang__) || defined(__GNUC__)
#define sort qsort_r
#define SORT_COMPARE(name) int name(const void *a, const void *b, void *arg)
typedef SORT_COMPARE(sort_cmp_f);
#elif defined(_MSC_VER)
#define sort qsort_s
#define SORT_COMPARE(name) int name(void *arg, const void *a, const void *b)
@vurtun
vurtun / pytriples.c
Last active Feb 13, 2019
Pythagorean triple
View pytriples.c
static void
pytriples(int *t)
{
do if (t[1] <= t[2])
t[1] = t[1] + 1;
else if (t[0] <= t[2])
t[0] = t[1] = t[0] + 1;
else t[2] += t[0] = t[1] = 1;
while (t[0]*t[0] + t[1]*t[1] != t[2]*t[2]);
}
View path.c
struct path_iter {
const char *begin;
const char *end;
/* internal */
const char *next;
const char *eof;
};
static void
path_begin(struct path_iter *it, const char *str, const char *end)
{
View debug_log.c
#define LIB_DEBUG 2
#if defined(LIB_DEBUG) && (LIB_DEBUG >= 2)
#include <stdio.h>
#define DEBUG_LOG(l, ...) \
if (l <= LIB_DEBUG) { \
fprintf(stderr, "%s(L:%d):, __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, " \n"); \
}
#else
View arg.h
#if 0
static void
usage(const char *app)
{
panic("\n"
"usage: %s [options]\n"
"\n"
" options:\n"
"\n"
View paq.c
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
/* ---------------------------------------------------------------------------
* ARG
You can’t perform that action at this time.