Skip to content

Instantly share code, notes, and snippets.

Micha Mettke vurtun

  • Germany
View GitHub Profile
View lay.c
/* Layout */
enum gui_lay_dir {
GUI_ROW,
GUI_COL,
};
struct gui_lay_sol {
int fix_siz;
int fix_cnt;
int dyn_siz;
int dyn_cnt;
View ui.c
struct gui_bnd {int min, mid, max, ext;};
struct gui_box {
struct gui_bnd x;
struct gui_bnd y;
};
#define gui_box(x,y,w,h) (struct gui_box){{x,x+(w>>1),x+w,w},{y,y+(h>>1),y+h,h}}
#define gui_min_max(a,b) (struct gui_bnd){a,a+((b-a)>>1),b,b-a}
#define gui_min_ext(m,e) (struct gui_bnd){m,m+(e>>1),m+e,e}
#define gui_max_ext(m,e) (struct gui_bnd){m-e,m-(e>>1),m,e}
#define gui_mid_min(c,m) (struct gui_bnd){m,c,m+c-m,(m-c)<<1}
View prng.c
static unsigned
wang_hash(unsigned u)
{
u = ((u ^ 61) ^ (u >> 16)) * 9;
u = (u ^ (u >> 4)) * 0x27d4eb2d;
return u ^ (u >> 15);
}
static unsigned
rand_lcg(unsigned *rng)
{
View utf.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define UTF_INVALID 0xFFFD
static const char*
utf_dec(unsigned *dst, const char *p, const char *e)
{
View fuzzy_match.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
static int
str_fzy(const char *str, const char *ptn)
{
const char *pat = ptn;
@vurtun
vurtun / zoom.c
Last active Jan 7, 2020
Zoom to point
View zoom.c
static float
scalbnf(float x, int n)
{
union {float f; unsigned i;} u;
float y = x;
if (n > 127) {
y *= 0x1p127f;
n -= 127;
if (n > 127) {
y *= 0x1p127f;
@vurtun
vurtun / x11_clipboard.c
Last active Dec 15, 2019
X11 clipboard
View x11_clipboard.c
static char*
sys_clip_get(struct sys *s, Atom selection, Atom target)
{
assert(s);
struct sys_x11 *x11 = s->platform;
/* blocking wait for clipboard data */
XEvent notify;
XConvertSelection(x11->dpy, selection, target, selection, x11->helper, CurrentTime);
while (!XCheckTypedWindowEvent(x11->dpy, x11->helper, SelectionNotify, &notify)) {
@vurtun
vurtun / math.c
Last active Jun 3, 2020
Linear Algebra
View math.c
#include <math.h>
#define op(r,e,a,p,b,i,s) ((r) e (a) p ((b) i (s)))
#define lerp(r,a,b,t) ((r)=(a)+(t)*((b)-(a)))
#define rad(x) ((x)*3.141592653f/180.0f)
#define op3(r,e,a,p,b,i,s)\
do{op((r)[0],e,(a)[0],p,(b)[0],i,s), op((r)[1],e,(a)[1],p,(b)[1],i,s),\
op((r)[2],e,(a)[2],p,(b)[2],i,s);} while(0)
#define op3s(r,e,a,p,s)\
do{op((r)[0],e,(0),+,(a)[0],p,s), op((r)[1],e,(0),+,(a)[1],p,s),\
View arena_tbl_buf.c
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>
#define cast(t,p) ((t)(p))
#define szof(a) ((int)sizeof(a))
View jsn.c
enum jsn_type {
JSN_OBJ,
JSN_ARY,
JSN_NUM,
JSN_STR,
JSN_TRUE,
JSN_FALSE,
JSN_NULL
};
struct jsn_val {
You can’t perform that action at this time.