Skip to content

Instantly share code, notes, and snippets.

View BRonen's full-sized avatar
:shipit:
Working on functions

Brenno Rodrigues BRonen

:shipit:
Working on functions
View GitHub Profile
@BRonen
BRonen / cond-as->.clj
Created May 8, 2025 05:27
cond-as-> macro definition
(defmacro cond-as->
[value sym & clauses]
(when (odd? (count clauses))
(throw (IllegalArgumentException. "cond-as-> requires an even number of clauses")))
(let [steps (partition 2 clauses)]
(loop [val value, steps steps]
(if (empty? steps)
val
(let [[test expr] (first steps)
var isValidSudoku = function(board) {
const rows = new Array(9).fill(0).map(() => new Set());
const cols = new Array(9).fill(0).map(() => new Set());
const boxes = new Array(9).fill(0).map(() => new Set());
for (let i = 0; i < 9; i++) {
for (let j = 0; j < 9; j++) {
const num = board[i][j];
if (num === '.') continue;
@BRonen
BRonen / interpretador.ts
Created March 5, 2025 21:14
Interpretador feito com e sem parsing para árvores de sintaxe.
const example = "1 - 1 + 3 + 44 / 2";
const lexer = (source: string): string[] => {
const tokens: string[] = [];
let currentToken = "";
for (const char of source) {
if ([" ", "+", "-", "*", "/"].includes(char)) {
if (currentToken) tokens.push(currentToken);
@BRonen
BRonen / MathInterpreter.hs
Created June 23, 2024 22:16
5 minutes math expression interpreter
module MathInterpreter (mathInterpreter) where
import Data.Char
data Token = Number Integer
| Plus
| Dash
| Star
| Slash
deriving Show
+-assoc-proof : ∀ (x y z : ℕ) → x + (y + z) ≡ (x + y) + z
+-assoc-proof zero y z = refl
+-assoc-proof (suc x) y z = cong suc (+-assoc-proof x y z)
@BRonen
BRonen / fibonacci.sql
Created April 26, 2024 00:27
fibonnaci with sql recursive queries
with recursive fib as (
select 0 as a, 1 as b
union
select b, a + b from fib
) select a from fib limit 5;
@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"