Skip to content

Instantly share code, notes, and snippets.

View BRonen's full-sized avatar
:shipit:
ora et labora

Brenno Rodrigues BRonen

:shipit:
ora et labora
View GitHub Profile
@BRonen
BRonen / iterable.ts
Created March 7, 2024 20:26
A brief snippet doing an iterable structure with recursion instead of loops
type Iter<A> = () => A | null;
const array_to_iter = <A>(arr: A[]): Iter<A> => {
let index = 0;
return () => {
const el = arr[index];
index += 1;
return el;
}

Thinking About Database Anomalies

When working on relational databases there are some guarantees called ACID, but these guarantees are not as safe as we usually think.

Let's start with a simple situation, imagine that you have a system that holds a balance of each user in some SQL database.

user A user B
id: 1 id: 2
balance: 100 balance: 50
@BRonen
BRonen / binary_tree.ts
Created January 4, 2024 01:23
Brief example about binary trees made in typescript
const useState = <A>(a: any): any => { };
type Tree = [number, Tree, Tree] | null
type UUID = string;
type Edge = { from: UUID, to: UUID }
type NNode = { nodes: NNode[], id: UUID, label: string }
const [nodes, setNodes] = useState<NNode | null>(null);
@BRonen
BRonen / zero.idr
Last active December 22, 2023 18:53
module Main
import Network.Socket.Data
data Fin : Nat -> Type where
FZ : Fin (S k)
FS : Fin k -> Fin (S k)
Show (Equal x y) where
show _ = "Equality"
@BRonen
BRonen / RealtimeEditCss.html
Created August 1, 2023 18:21
Realtime editable css
<html>
<body>
<style contenteditable>
style { display: block; }@keyframes animat { 0% { background-color: pink; } 50% { background-color: orange; } 100% { background-color: red; } }body { animation: animat 750ms infinite alternate; }
</style>
</body>
</html>
@BRonen
BRonen / ReversePolishNotationInterpreter.ts
Created July 30, 2023 04:29
Evaluates an expression in Reverse Polish Notation
/**
* Evaluates an expression in Reverse Polish Notation.
*
* @param {string} expression - The input expression.
* @returns {number} The result of the RPN expression.
*/
// This script parses the expression into a tree and then evaluates, should be something like O(n) because iterates once on the parsing and once in the evaluating
type Operator = {op: string, left: Operator | number, right: Operator | number};
@BRonen
BRonen / MorseAutocompleteSuggestions.ts
Created July 30, 2023 04:10
A script that handles incomplete morse signals and gives the original source possibilities
/**
* Finds the number in an array with the most digits.
*
* @param {string} signals - The incomplete source.
* @returns {string[]} Suggestions of possible complete sources.
*/
const MORSE_DICTIONARY: Record<string, string> = {
".": "E",
"-": "T",
@BRonen
BRonen / RomanNumerals.ts
Created July 30, 2023 04:06
Script to parse roman numerals to equivalent integer
/**
* Decodes a Roman numeral to a number.
*
* @param {string} roman - The Roman numeral to decode.
* @returns {number} The decoded Roman numeral.
*/
const numerals: Record<string, number> = {
'I': 1,
'V': 5,
@BRonen
BRonen / README.md
Created July 30, 2023 03:56
Desafio mentoria

Requisitos

Os requisitos desse projeto não são especificos de nenhuma linguagem nem framework, as integrações podem acontecer tanto no frontend quanto no backend. O foco principal é na usabilidade do projeto pelo usuário. A base da aplicação é baseada em 3 etapas:

  • a busca de um perfil na api do github;
  • a listagem dos resultados da busca;
  • a visualização desse perfil;
@BRonen
BRonen / LinkedList.hs
Created June 4, 2023 06:14
An example of linked list made in haskell for fun
module Main where
data List a = End a | Node a (List a) deriving (Show)
prepend :: a -> List a -> List a
prepend value x = Node value x
append :: a -> List a -> List a
append value (End x) = Node x (End value)
append value (Node x y) = Node x (append value y)