Skip to content

Instantly share code, notes, and snippets.

View Hadaward's full-sized avatar

Eduardo Gimenez Hadaward

  • 16:16 (UTC -04:00)
View GitHub Profile
@Hadaward
Hadaward / list.c
Last active March 7, 2025 00:53
Curtain Collections List
#include "list.h"
List list_instance(size_t type_size) {
return (List){
.data = malloc(0),
.size = 0,
.type_size = type_size
};
}
@Hadaward
Hadaward / avl.ts
Last active November 26, 2024 23:37
AVLTree
class AVLNode {
public left: AVLNode|null = null;
public right: AVLNode|null = null;
public height: number = 1;
constructor(
public value: number
) {}
}
@Hadaward
Hadaward / example.c
Last active October 15, 2024 15:36
Utilities for managing the memory of initialized objects. By using "use(allocator, type)" you initialize a new object pointer that calls the code defined by "default(type)" if there is one to initialize the object's default values. By using "ret value" instead of "return value" you ensure that all objects initialized with use are freed from memory.
#include "gmdutil.h"
typedef struct Point {
int x;
int y;
} Point;
default(Point) {
self->x = 0;
self->y = 0;
/**
* @summary The Result<Ok, Error> interface describes the result of a function that can occur in two different ways, being an error or a positive result.
* @summary The methods in this interface help the developer to better understand the result of the function and then deal with it directly.
* @summary Use ``Ok(value)`` or ``Err(error)`` to instantiate this.
*/
export interface Result<Ok = any, Err = Error> {
isOk(): boolean,
isErr(): boolean,
/**
* @throws "Tried to unwrap an error value but the value is ok." - When you try to unwrap an ok value as error.
@Hadaward
Hadaward / any.h
Last active May 24, 2024 13:29
Implementation of Any type in C
#ifndef ANY_H
#define ANY_H
#include <stdbool.h>
#include <stdint.h>
enum Variant {
V_ANY,
V_STRING,
V_CHAR,
@Hadaward
Hadaward / mutex-concept.ts
Last active May 8, 2024 16:08
A mutex concept implemented in javascript, to ensure you don't have unexpected value changes.
export type MutexGuard<T> = Readonly<{
id: string,
get: () => T,
set: (value: T) => void,
unlock: () => void
}>;
export type Mutex<T> = Readonly<{
lock(): Promise<MutexGuard<T>>
}>;
@Hadaward
Hadaward / typeutils.ts
Last active December 15, 2023 17:52
typeOf and typeCheck implementation for TypeScript. Now you can ensure your typings on runtime 😄
const types: Readonly<{[K: string]: any}> = Object.freeze({
NaN: 'nan',
String: 'string',
Number: 'number',
Boolean: 'boolean',
Object: 'object',
Undefined: 'undefined',
Null: 'null',
Function: 'function',
Class: 'class',
@Hadaward
Hadaward / config-vscode.bat
Last active August 29, 2023 20:13
Um arquivo para pré-configurar o VSCode para rodar projeto C
@echo off
title Configurando VSCode
echo Adicionando C:\MinGW\bin ao PATH
powershell -Command "function Add-Path($path) { $pathContent = [Environment]::GetEnvironmentVariable('path', 'user'); if ($pathContent -ne $null) { if (!($pathContent -split ';' -contains $path)) { $pathContent = $pathContent + [IO.Path]::PathSeparator + $path; [Environment]::SetEnvironmentVariable('Path', $pathContent, 'User'); } } } Add-Path('C:\MinGW\bin')"
echo Instalando pacotes do VSCode
cmd /c code --force --install-extension MS-CEINTL.vscode-language-pack-pt-BR --install-extension ms-vscode.cpptools --install-extension ms-vscode.cpptools-extension-pack --install-extension danielpinto8zz6.c-cpp-compile-run --install-extension danielpinto8zz6.c-cpp-project-generator
echo Iniciando VSCode
code --locale pt-BR | exit
@Hadaward
Hadaward / unicode.h
Last active August 22, 2023 23:29
A unicode header to allow printing and scanning unicodes from terminal (Emojis may work but you need a terminal who can represent them)
#ifndef UNICODE_H
#define UNICODE_H
#include <locale.h>
#include <wchar.h>
#include <stdarg.h>
#include <stdio.h>
#include <wctype.h>
#include <stdlib.h>
@Hadaward
Hadaward / read_string.c
Created August 16, 2023 04:33
read_string
#include <stdio.h>
#include <stdlib.h>
/*
Essa é uma função que eu criei parecida com o scanf
O intuito é ler um texto digitado pelo teclado com um tamanho máximo determinado
Recebe como parâmetro:
1. uma mensagem pedindo para o usuário digitar
2. um limite máximo de caracteres