Skip to content

Instantly share code, notes, and snippets.

View Hadaward's full-sized avatar

Eduardo Gimenez Hadaward

  • 10:59 (UTC -04:00)
View GitHub Profile
@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
@Hadaward
Hadaward / extends.js
Created May 20, 2023 03:59
Make class extend HTMLElement
export class ExtendableHTMLElement {
/**
* Creates a new class that inherits all of the element's properties and methods
* @param {string} tagName - HTML Tag name
*/
constructor(tagName) {
const element = document.createElement(tagName);
const constructor = Object.getPrototypeOf(this);
const extraConstructors = [Object.getPrototypeOf(constructor) ?? null];
@Hadaward
Hadaward / tfm.events.lua
Created April 27, 2023 04:46
An example of a basic event system to override transformice's event system.
tfm.events = {
_handlers = {},
handle = function (self, events)
for _, event in next, events do
if not _G[event] then
self._handlers[event] = {}
_G[event] = function(...)
self:emit(event, table.unpack(arg))
end
end
@Hadaward
Hadaward / table-utils.lua
Last active May 4, 2023 19:45
This gist contains useful functions for lua tables inspired directly from the JavaScript documentation.
function table.every(self, predicate)
for key, value in next, self do
if not predicate(value, key) then
return false
end
end
return true
end
@Hadaward
Hadaward / ArrayUtil.go
Created June 17, 2022 20:34
A simple package to implement utility functions for arrays
package ArrayUtil
import (
"sort"
"golang.org/x/exp/constraints"
)
// The IndexOf method returns the index of the first occurrence of a value in an array. If not found, it returns -1.
func IndexOf[T comparable](array []T, value T) int {