Skip to content

Instantly share code, notes, and snippets.

@opsJson
opsJson / colador.py
Created April 19, 2024 19:02
Colador de Prova em Python
import openai
from doctr.models import ocr_predictor
from doctr.io import DocumentFile
from telegram.ext import ApplicationBuilder, MessageHandler, filters
TELEGRAM_TOKEN = "telegram_token_here"
OPENAI_TOKEN = "openai_token_here"
def image_to_text(image_path):
image = DocumentFile.from_images(image_path)
@opsJson
opsJson / webdriver.c
Last active November 13, 2023 18:33
Webdriver Interface in C
#ifndef _WEBDRIVER_H_
#define _WEBDRIVER_H_
#include "cmdl.h" /* https://gist.github.com/opsJson/515644eff27b29ad91b79522ca3b2c40 */
#include "makestr.h" /* https://gist.github.com/opsJson/ce29f980360713b74e4abc152217849a */
#include "json_parser.h" /* https://gist.github.com/opsJson/d79503f7b206c6697f20d8c979e3e74a */
#include "json_maker.h" /* https://github.com/opsJson/json-maker */
#include <stdbool.h>
#define STRINGIFY(...) #__VA_ARGS__
@opsJson
opsJson / json_parser.c
Last active May 2, 2024 18:24
Simple JSON parser in C. Parse until find the values you want. Allocate just the values you want.
#ifndef _JSON_PARSER_H_
#define _JSON_PARSER_H_
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifndef JSON_ALLOC
#define JSON_ALLOC malloc
#endif
@opsJson
opsJson / cmdl.c
Created June 7, 2023 01:22
Pipe output of any command line program to buffer in C.
#ifndef CMDL_H_
#define CMDL_H_
#ifdef _WIN32
#include <windows.h>
static const char *cmdl_errlist[] = {
"No Error.",
"CreatePipe() failed: could not create a pipe.",
"CreateProcessA() failed: could not create child process.",
#ifndef LIST_H_
#define LIST_H_
#define LIST(TYPE, SIZE) \
\
static TYPE list_##TYPE[SIZE]; \
static int list_start_##TYPE = 0; \
static int list_end_##TYPE = 0; \
int list_##TYPE_size = SIZE; \
\
@opsJson
opsJson / hashtable.c
Created May 28, 2023 03:40
Hashtable macro in C. TYPE is the variable type, KEY_SIZE is the maximum key string size, TABLE_SIZE is the maximum table size. (must be a prime number)
#ifndef HASHTABLE_H_
#define HASHTABLE_H_
#include <string.h>
unsigned int djb2(const char *str){
unsigned long hash = 5381;
int c;
while ((c = *str++)) {
@opsJson
opsJson / autobuild.c
Last active May 22, 2023 21:00
Automatically rebuild your program when you run it
#ifndef _AUTO_BUILD_H_
#define _AUTO_BUILD_H_
#include <stdlib.h>
#ifndef AUTOBUILD_TARGET
#ifdef _WIN32
#define AUTOBUILD_TARGET "autobuild.exe"
#else
#define AUTOBUILD_TARGET "./autobuild"
@opsJson
opsJson / makestr.c
Last active February 9, 2024 10:39
Easily allocate strings with a printf-like function.
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <wchar.h>
char *makestr(char *format, ...) {
va_list args;
int size;
char *result;
@opsJson
opsJson / go.c
Last active June 6, 2023 22:15
C interface for libcurl.
#ifndef _GO_H_
#define _GO_H_
#include <curl/curl.h>
typedef struct {
char *headers;
char *body;
CURL *handle;
long int statuscode;
@opsJson
opsJson / cbprint.c
Last active May 4, 2024 03:17
Easy win32 GDI Print API interface with callbacks.
#ifndef _PRINTER_PAGE_H_
#define _PRINTER_PAGE_H_
#include <windows.h>
/* compile with flags -lgdi32 and -lwinspool */
int PrintPage(wchar_t *printer_name, void (*callback)(HDC printer, void *userdata), void *userdata) {
HDC printer;
DOCINFOA docinfo;