Skip to content

Instantly share code, notes, and snippets.

@opsJson
opsJson / easy-auto-heap.c
Last active January 15, 2022 02:15
every time malloc/calloc is called again, the memory is automatically freed.
#include <stdio.h>
#include <stdlib.h>
#ifndef HEAP_MAX
#define HEAP_MAX 1
#endif
struct HeapMap_s {
void *memory;
char *file;
@opsJson
opsJson / file-buffer.c
Last active September 11, 2022 19:46
Write variables to file and read file to variable, easily.
#include <stdio.h>
#include <stdlib.h>
void *ftob(const char *file, unsigned int *size, ...) {
FILE *fp;
unsigned char *buffer;
long int _size;
if ((fp = fopen(file, "rb")) == NULL) {
fprintf(stderr, "ERROR: Could not open '%s'\n", file);
@opsJson
opsJson / c-autogui.c
Last active March 26, 2024 18:10
PyAutoGui, but in C, for Windows.
#include <windows.h>
#include <stdarg.h>
int counter(wchar_t* str) {
int i = 0;
while (*str) {
if (*str == ',') i++;
str++;
}
return i+1;
@opsJson
opsJson / type-checker.c
Last active December 26, 2021 00:46
Easily gets the type of a variable.
#include <stdio.h>
#include <limits.h>
#define typeof(x) \
(((x == 0) ? (x = 0.00000000001) : (x)) / INT_MAX == 0) \
? ("0cs0i0000"[sizeof(x)]) \
: ("0000f000d"[sizeof(x)])
int main() {
char c;
@opsJson
opsJson / easy-thread.c
Last active March 4, 2022 23:56
Easily async and resync any function, casts are automatically made. You can pass any number of arguments, and can get the return value. Easy interface for mutex.
#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include <stdarg.h>
#define thread_local _Thread_local
#ifndef THREAD_MAX
#define THREAD_MAX 50
#endif
@opsJson
opsJson / easy-string.c
Last active January 17, 2022 20:49
Minimal set of string functions.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define str_assert(condition) \
{ \
if (!(condition)) { \
fprintf(stderr, "Expression: '%s' failed at %s:%i\n", \
#condition, file, line); \
return 0; \
@opsJson
opsJson / easy-http-server.c
Last active March 20, 2022 21:38
Easily create web apps on Windows.
#include <winsock2.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*///////////////////////////////////
easy-string
@opsJson
opsJson / easy-http-client.c
Last active January 7, 2022 03:49
Easily make HTTP requests over internet, on Windows.
#include <winsock2.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
/*///////////////////////////////////
easy-strings
@opsJson
opsJson / easy-leaks-finder.c
Last active January 17, 2022 01:24
Easily find memory leaks, at runtime.
#include <stdio.h>
#include <stdlib.h>
#ifndef HEAP_MAX
#define HEAP_MAX 50
#endif
struct HeapMap_s {
void *memory;
char *file;
@opsJson
opsJson / easy-man-in-the-middle.c
Last active December 25, 2021 23:32
Execute code before and after main function.
#include <stdio.h>
void before_main() {
printf("code before main here.\n");
}
void after_main() {
printf("code after main here.\n");
}