Skip to content

Instantly share code, notes, and snippets.

@opsJson
opsJson / check-screen.c
Last active December 18, 2021 17:23
Detect screen changes.
#include <windows.h>
#include <stdio.h>
int screenshot_border_enabled = 0;
void enable_screenshot_border(int flag) {
screenshot_border_enabled = flag;
}
static void screenshot_border(int x, int y, int width, int height) {
HDC screen;
@opsJson
opsJson / screenshot.c
Last active February 2, 2022 23:15
Easily take screenshots on Windows.
#include <windows.h>
int* screenshot(int x, int y, int width, int height) {
HDC screen = GetDC(0);
HDC memoryDC = CreateCompatibleDC(screen);
HBITMAP memoryBMP = CreateCompatibleBitmap(screen, width, height);
SelectObject(memoryDC, memoryBMP);
BITMAPINFO bitmapinfo;
@opsJson
opsJson / string_list.c
Last active December 25, 2021 23:26
Easily allocate a list of any amount of strings.
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
size_t counter(char *str) {
size_t commas = 0;
int string = 0;
@opsJson
opsJson / anonymous_functions.c
Last active December 25, 2021 23:30
Javascript anonymous functions in C.
#include <stdio.h>
#include <unistd.h>
//create a function that recieves a function pointer, and any arguments
void _foo(void (*function)()) {
function("Foo", 555);
}
void _setTimeout(void (*function)(), float time) {
sleep((float)time/1000);
@opsJson
opsJson / keyword_arguments.c
Last active December 18, 2021 05:58
Python keyword arguments in C.
#include <stdio.h>
//create your arguments list.
struct args {
char *name;
int x;
int y;
int width;
int height;
};
@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");
}
@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-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-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-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; \