Skip to content

Instantly share code, notes, and snippets.

View camel-cdr's full-sized avatar

Camel Coder camel-cdr

  • 12:55 (UTC +02:00)
View GitHub Profile
@camel-cdr
camel-cdr / gen.c
Last active February 19, 2022 12:09
C code that is syntactically correct only on Fridays
#include <stdio.h>
#include <time.h>
static const char mon_name[12][3] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
int
main(void)
#include <stdio.h>
#define E2(...) E1(E1(E1(E1(E1(E1(E1(E1(E1(E1(__VA_ARGS__))))))))))
#define E1(...) __VA_ARGS__
#define EMPTY()
#define DEFER1(m) m EMPTY()
#define APPLY3(F,a,m,k) F(a,0,m,k), F(a,1,m,k), F(a,2,m,k), \
F(a,3,m,k), F(a,4,m,k), F(a,5,m,k), \
F(a,6,m,k), F(a,7,m,k), F(a,8,m,k), \
@camel-cdr
camel-cdr / main.c
Last active June 18, 2021 12:33
ranged designated initializers in c99
#include <stdio.h>
#define E2(...) E1(E1(E1(E1(E1(E1(E1(E1(E1(E1(__VA_ARGS__))))))))))
#define E1(...) __VA_ARGS__
#define EMPTY()
#define DEFER1(m) m EMPTY()
#define APPLY3(F,a,x,y,v) F(a,0,x,y,v), F(a,1,x,y,v), F(a,2,x,y,v), \
F(a,3,x,y,v), F(a,4,x,y,v), F(a,5,x,y,v), \
F(a,6,x,y,v), F(a,7,x,y,v), F(a,8,x,y,v), \
@camel-cdr
camel-cdr / torus.c
Last active December 19, 2022 15:30
obfuscated raymarcher
i,j,k,L;
#include <time.h>
float X,Y,Z,l,t,x,y,z,
A,S,C;r(X,Y)float*X,*Y;{A
=*X,S=sin(l),C=cos(l);*X=A*C
-*Y*S,*Y=A*S+*Y *C;}main()
{char*p,s[L=( W+1)*H];
printf("\x1b" "[2J");r
:p=s;for(i=0; i<H;++i,
*p++=10)for(j =0;j<W;
@camel-cdr
camel-cdr / list.c
Created March 5, 2021 21:51
Remember kids, C's got namespaces.
struct list { struct list *list; };
struct list *
list(struct list *list)
{
list:
if (list->list && (list = list->list))
goto list;
return list;
}
@camel-cdr
camel-cdr / random.h
Last active March 5, 2021 21:48
How to generate unbiased uniform random floating-point numbers including all representable values. An excerpt from the random number library I'm currently developing.
/*
* 5.2 Uniform real distribution -----------------------------------------------
*
* Generating uniform random floating-point numbers might seem easy at first
* glance, just cast the output of a PRNG to the desired float type and divide
* by the biggest possible output of the PRNG to obtain a random float between
* 0 and 1 that can now be scaled up.
* Though as before this straightforward approach is biased.
*
* For the next part, I assume you are already acquainted with the IEEE 754