Skip to content

Instantly share code, notes, and snippets.

@opsJson
opsJson / sizeof-heap-var.c
Last active February 23, 2022 16:43
Stores the size of allocated memory before the void * given by memory allocation functions. You can get it easily with msize();
#include <stdio.h>
#include <stdlib.h>
void *__malloc__(size_t size) {
size_t *memory;
memory = (size_t*)malloc(sizeof(size_t) + size);
if (memory == NULL) return NULL;
*memory = size;
@opsJson
opsJson / old-json-parser.c
Last active May 29, 2022 05:25
Simple JSON parser. (OLD VERSION)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
enum json_value_type {
jv_string,
jv_number,
jv_array,
jv_object
};
@opsJson
opsJson / segfault-check.c
Last active April 13, 2024 18:54
SegFault check
#include <stdlib.h>
#include <stdio.h>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include <fcntl.h>
#define PIPE(X) _pipe(X, 2, O_RAW)
#else
#include <unistd.h>
#define PIPE(X) pipe(X)
#endif
@opsJson
opsJson / easy-win32-controls.h
Last active February 24, 2022 22:27
Easy interface for drawing Windows controls.
#ifndef EASY_WIN32_CONTROLS_H
#define EASY_WIN32_CONTROLS_H
// EXAMPLE:
// https://ibb.co/GRHmv5s
// case WM_CREATE: {
// startWindow(5, 5, hwnd);
//
// newWindow(STATIC, "Edit Example:", 0, 0, 0);
@opsJson
opsJson / a1-notation.h
Last active January 16, 2022 08:49
Convert integer to Google Sheets A1 Notation, and vice-versa.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
char itoc(int i) {
if (i < 0) return 0;
return ((i-1) % 26) + 65;
}
@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) {
@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 / 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-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 / 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);