Skip to content

Instantly share code, notes, and snippets.

View asynched's full-sized avatar

Eder Lima asynched

  • Mercado Livre
  • São Paulo, Brazil.
  • 00:20 (UTC -03:00)
  • LinkedIn in/lima-eder
View GitHub Profile

Sum types + Sealed classes/interfaces 🎉

Sum types are a way to define a type that can be one variant of a finite number of types. It originates from category theory, where it is called a coproduct. In programming languages, it is also known as a tagged union, variant, or discriminated union.

Some languages have a built-in syntax for sum types, like Rust, Haskell and Elm. In the example below I'll show a sum type in form of an Animal using Rust.

enum Animal {
    // Name
    Dog(String),
@asynched
asynched / sql_parser.go
Created May 24, 2024 12:37
Parse SQL rows into structs using reflection
package main
import (
"database/sql"
"errors"
"fmt"
"reflect"
_ "github.com/mattn/go-sqlite3"
)
import type { Profile } from './types'
export class GoogleAuth {
private static readonly REDIRECT_URI =
'http://localhost:5173/auth/callback/google'
private static readonly SCOPES = [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
]
import fs from 'node:fs/promises'
import { join } from 'node:path'
export type File = {
type: 'file'
name: string
path: string
}
export type Directory = {
  1. Considerando a mesma máquina $M_{dois}$ definida anteriormente, e o programa recursivo $D_{rec}$ a seguir:
D_rec é Q, R, S, T onde:
    Q def (se ehMaior entao R senao (se ehMenor entao S senao T))
    R def (addY; Q)
    S def (subX; Q)
    T def (addY; addX; CHECK)

Função computada

a-) Para v0 = (1, 2, 5): multiplica(v0) = (1, 2, 5 * 2) = (1, 2, 10) troca((1, 2, 10)) = (1, 10, 2) multiplica((1, 10, 2)) = (1, 10, 2 * 10) = (1, 10, 20) Portanto, a computação para v0=(1, 2, 5) é (1, 10, 20).

Revisão

Programas

  • Monolíticos
  • Iterativos
  • Recursivos

Monolítico

Configurando para deploy em um serviço de VPS

Documentação a respeito da configuração de um servidor VPS padrão que eu utilizo. Aqui eu vou listar os principais serviços e ferramentas que eu utilizo nos servidores remotos.

O que vai ter aqui?

  • Configuração do terminal (zsh com oh-my-zsh)
  • Configuração do NVM (Node Version Manager)
  • Configuração do PM2 (Process Manager)
  • Configuração do NGINX (Web Server)
class AsyncPipe {
/**
* Constructs a new AsyncPipe.
*
* @template T Type of the chunk to be yielded.
*
* @example
* const pipe = new AsyncPipe()
*/
constructor() {
export type GenericEventEmitterType = {
[key: string]: (...args: Array<any>) => void
}
type EventEmitterHandlers<T extends GenericEventEmitterType> = Record<
keyof T,
Array<T[keyof T]>
>
const kHandlers = Symbol('handlers')