Skip to content

Instantly share code, notes, and snippets.

View kevinmarquesp's full-sized avatar
🐧
Optimizing my slow machine to work...

Kevin Marques kevinmarquesp

🐧
Optimizing my slow machine to work...
View GitHub Profile
@kevinmarquesp
kevinmarquesp / coalesce-exaple.sql
Created July 3, 2024 17:48
Exemplo de como mudar os detalhes de um perfil de um usuário numa única query pro banco.
CREATE TABLE IF NOT EXISTS Users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
public_id TEXT UNIQUE NOT NULL,
fullname TEXT NOT NULL,
username TEXT UNIQUE NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
@kevinmarquesp
kevinmarquesp / genserver_explaination.ex
Last active June 24, 2024 02:00
Lista de conceitos que fui escrevendo e colando no terminal rodando om IEX pra entender, certinho, como funciona um GenServer por baixo dos panos.
# Concept 1:
# Elixir can spawn process to run functions.
spawn(fn ->
"Hello world!"
end)
# Concept 2:
# Elixir can send messages to other process, including the current IEX one.
# At the same time, it can stop the runtime and wait to recieve a message
@kevinmarquesp
kevinmarquesp / homemade_genserver.ex
Created June 24, 2024 01:56
Um pequeno servidor em Elixir que criei do zero, usando apenas os recursos fundamentais da linguagem. Fiz isso pra estudar e entender plenamente como funciona e, principalmente, pra que serve os tais GenServes. Tentei refletir no código abaixo a API que um GenServer de verdade usaria.
defmodule Counter do
def new(state) do
spawn(Counter, :listener, [state])
end
def arun(pid, args) do # Async run.
send(pid, {:arun, args})
end
def srun(pid, args) do # Sync run.