Skip to content

Instantly share code, notes, and snippets.

@opsJson
opsJson / base64.c
Last active July 21, 2024 22:41
Base64 codec in C
#ifndef _BASE64_H_
#define _BASE64_H_
#ifndef BASE64_ALLOC
#include <stdlib.h>
#define BASE64_ALLOC malloc
#endif
#ifndef BASE64_STRLEN
#include <string.h>
@opsJson
opsJson / fetch.lua
Last active June 23, 2024 03:39
Curl interface for lua
function fetch(url, options)
local command = "curl \"" .. url .. "\" --silent"
if options.method then
command = command .. " -X \"".. options.method .. "\""
end
if options.body then
local body = options.body:gsub("\"", "\\\"")
command = command .. " --data \"".. body .. "\""
@opsJson
opsJson / json.lua
Last active June 23, 2024 03:32
JSON Parser in lua
function jsonParse(str)
if not str then return nil end
str = str:match("^%s*(.-)%s*$")
if #str == 0 then return nil end
local t = str:sub(1, 1)
str = str:sub(2, -2):match("^%s*(.-)%s*$") .. ','
local obj = {}
local depth = 0
local last = 0
@opsJson
opsJson / Colador.js
Created June 14, 2024 21:23
Colador de Prova usando GPT-4o Vision e NodeJs
const TelegramBot = require("node-telegram-bot-api");
const OPENAI_TOKEN = "openai_token";
const TELEGRAM_TOKEN = "telegram_token";
const bot = new TelegramBot(TELEGRAM_TOKEN, { polling: true });
bot.on("message", async msg => {
bot.sendMessage(msg.chat.id, "Pensando...");
if (msg.photo) {
const link = await bot.getFileLink(msg.photo[msg.photo.length-1].file_id);
@opsJson
opsJson / wtoa_atow.c
Created May 5, 2024 01:56
Widechar to Multibyte and Multibyte to Widechar in Windows
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <windows.h>
wchar_t *atow(char *str) {
wchar_t *result;
int length;
if (str == NULL) return NULL;
@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; \
\