Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / show-hide-console.c
Last active December 25, 2021 23:22
Re-enable console for win32 apps, or hide console for console apps.
#include <stdio.h>
#include <windows.h>
char SHOW_FLAG = 0;
void console_show() {
AllocConsole();
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
@opsJson
opsJson / easy-csv.c
Last active September 26, 2022 02:46
Easily write CSV files, without worrying about escapes.
#include <stdio.h>
#include <stdarg.h>
size_t counter(char *str) {
size_t commas = 0;
int string = 0;
while (*str) {
//escape commas inside string;
if (*str == '"' && *(str - 1) != '\\') string = !string;
@opsJson
opsJson / easy-time.c
Last active January 4, 2022 17:44
Easy time interface, with clear names. You can also execute a function with any number of arguments in a determined interval.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#else
#include <unistd.h>
#define Sleep(time) sleep(time/1000)
#endif
@opsJson
opsJson / easy-json-maker.c
Last active December 27, 2021 20:48
Easily creates json, just by passing a list of strings, numbers, jsons, etc.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
size_t counter(char *str) {
size_t commas = 0;
int string = 0;
while (*str) {
@opsJson
opsJson / makestr.c
Created December 30, 2021 01:01
Allocate formatted strings without worrying about size.
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
size_t counter(char *str) {
size_t commas = 0;
int string = 0;
while (*str) {