Skip to content

Instantly share code, notes, and snippets.

"""
Contém utilitários para capturar e/ou indicar interrupções em processos.
"""
from __future__ import annotations
import signal
from typing import Any, Callable, Mapping, Sequence, Set
@flisboac
flisboac / static-convert-path.ts
Created September 22, 2021 21:45
static-convert-path.ts
type ToPathIndexArray<S extends string> =
S extends `${infer N}[${infer P}]` ? [N, P] : [S];
type ToPathArray<P extends string, _R extends string[] = []> =
P extends `${infer NS}.${infer N}`
? NS extends `${infer IN}[${infer I}]`
? [IN, I, ...ToPathArray<N>, ..._R]
: [...ToPathIndexArray<NS>, ...ToPathArray<N>, ..._R]
: P extends `${infer IN}[${infer I}]`
? [IN, I, ..._R]
@flisboac
flisboac / dod.cpp
Created July 17, 2021 01:46
Differences between OOP vs DOD approaches in software design (only examples here, actually)
// Working snippet at: https://glot.io/snippets/g0jhgoope4
// "DOD" stands for data-oriented design
#include <vector>
#include <cstddef>
#include <iostream>
#include <algorithm>
#include <queue>
#include <emmintrin.h>
#include <xmmintrin.h>
import { ContextId } from '@nestjs/core';
import { Abstract, INestApplicationContext, Type } from '@nestjs/common';
import { Transform, TransformFnParams, TransformOptions } from 'class-transformer';
/**
* A class-based property transformer.
*
* Functionally, the call to `this.transform` is what substitutes the transformer
* function passed into the default `Transform` decorator. This means that it must
* return the correct value, and NOT be asynchronous. If you DO return promises, be
<!doctype html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
</head>
<body>
<div id="options">
<label for="cellSize">Cell size</label>
<input type="number" id="cellSize" name="cellSize" min="10" max="9999" step="5" value="20">
@flisboac
flisboac / CalculateFlywayChecksum.java
Last active March 22, 2020 09:14
Creates a new INSERT line for a Flyway SQL migration. Useful for patching migration information in the schema_version table (I won't judge, don't worry). Parts of this code were extracted from Flyway v6.1.4.
import java.io.BufferedReader;
import java.io.FileReader;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.zip.CRC32;
public class CalculateFlywayChecksum {
@flisboac
flisboac / ..parcel-class-self-ref.md
Last active January 29, 2020 03:26
Gist for a possible bug in parcel.js (report TBD)

Gist for a possible bug in parcel.js (report TBD)

See https://stackoverflow.com/questions/38335668/how-to-refer-to-typescript-enum-in-d-ts-file-when-using-amd
Run with `npm run exec`, will install all dependencies as needed.
/**
* Models a type guard function.
*/
export interface Guard<T> {
readonly name: string;
(value: any): value is T;
}
/**

O que segue é um breve resumo, aplicável a ambos C e C++, na medida do possível.

Em C e C++, há o conceito de translation unit (TU) (C, C++). Cada arquivo que vc compila para um arquivo-objeto (com extensao .o, ou no Windows com extensao .obj), é oriundo de uma TU.

Primeiro, sua TU é preprocessada -- é neste estágio que o seu arquivo externo é incluído, via diretiva de processador #include (C, C++). Uma vez preprocessada, sua TU é compilada para um arquivo-objeto. Ao contrário do Python, que considera "arquivos externos" como módulos, a inclusão de arquivos no C++ é feita no pré-processamento, e por isso é uma inclusão meramente textual.

Depois o linker une todos os arquivos-objeto em um único binário, seja executável ou não.

No C/C++, também é p