Skip to content

Instantly share code, notes, and snippets.

View lucasteles's full-sized avatar
:shipit:
Ship it!

Lucas Teles lucasteles

:shipit:
Ship it!
View GitHub Profile
@lucasteles
lucasteles / baixo_do_tapete.ts
Created April 30, 2022 16:41
Code challenge, find char hole in typescript type system
export type AllChars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
export type ValidChar = AllChars[number]
type TupleToObject<T extends any[]> = { [K in keyof T as Exclude<K, keyof any[]>]: T[K] }
type MapTuples<
T extends any[],
N extends Record<keyof TupleToObject<T>, PropertyKey>> =
{ [K in keyof TupleToObject<T> as N[K]]: T[K] }
type IncMap = MapTuples<Tail<AllChars>, AllChars>
@lucasteles
lucasteles / baixo_do_tapete.ts
Created April 30, 2022 14:29
Find string holes in type script meta programming type system
type IncMap = { 0: 1; 1: 2; 2: 3; 3: 4; 4: 5; 5: 6; 6: 7; 7: 8; 8: 9; 9: 10;
10:11;11:12;12:13;13:14;14:15;15:16;16:17;17:18;18:19;19:20;
20:21;21:22;22:23;23:24;24:25;25:26 }
type Inc<T extends number> = T extends keyof IncMap ? IncMap[T] : never
type Head<T extends any[]> = T extends [any, ...any[]] ? T['0'] : never
type Tail<T extends any[]> = ((...t: T) => never) extends (h: any, ...rest: infer R) => never ? R : never
type Cons<V,T extends any[]> = ((h: V, ...t: T) => void) extends (...t: infer R) => void ? R : never
type IsEqual<A, B> = A extends B ? (B extends A ? true : false) : false
type IsNever<T> = [T] extends [never] ? true : false
@lucasteles
lucasteles / Program.cs
Created April 26, 2022 18:34
Minimal API EF
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<Contexto>(c => c.UseNpgsql(builder.Configuration.GetConnectionString("Default")));
var app = builder.Build();
app.MapGet("/jogador", async (Contexto contexto) => await contexto.Jogadores.ToListAsync());
app.MapGet("/jogador/{id:int}", async (Contexto contexto, int id) =>
await contexto.Jogadores.FindAsync(id) switch {
@lucasteles
lucasteles / Program.cs
Created April 26, 2022 16:48
Minimal API Dapper
using System.Data.Common;
using Dapper;
using Npgsql;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<AbrirConexão>(provider => async () => {
var conexão = new NpgsqlConnection(provider.GetRequiredService<IConfiguration>().GetConnectionString("Default"));
await conexão.OpenAsync();
return conexão;
});
@lucasteles
lucasteles / MemoryMappedFileSample.cs
Created April 19, 2022 15:03
MemoryMappedFileMemory sample
using System;
using System.Buffers;
using System.IO.MemoryMappedFiles;
unsafe class MemoryMappedFileMemory : MemoryManager<byte>
{
private readonly MemoryMappedFile mmf;
private readonly MemoryMappedViewAccessor ma;
private readonly byte* ptr;
@lucasteles
lucasteles / CpuDiagnoser.cs
Created April 13, 2022 14:30 — forked from MarkPflug/CpuDiagnoser.cs
BenchmarkDotNet CPU utilization
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Validators;

Keybase proof

I hereby claim:

  • I am lucasteles on github.
  • I am lucasteles (https://keybase.io/lucasteles) on keybase.
  • I have a public key ASDOxvp2dwZIZ5Y9-Gad-zohoMftN_f3Ub54zeB4sp22fwo

To claim this, I am signing this object:

@lucasteles
lucasteles / Program.fs
Last active October 14, 2021 15:15
Record mic in F# using OpenTK
open System
open System.Threading
open OpenTK.Audio.OpenAL
//based on
//https://github.com/opentk/opentk/blob/4.0.0-pre9.7/src/OpenAL/OpenTK.OpenAL/ALTest.cs
[<EntryPoint>]
let main argv =
let frequency = 48000
@lucasteles
lucasteles / renew-gpgkey.md
Last active October 5, 2021 21:24 — forked from krisleech/renew-gpgkey.md
Renew Expired GPG key

Renew GPG key

Given that your key has expired.

$ gpg --list-keys
$ gpg --edit-key KEYID

Use the expire command to set a new expire date:

@lucasteles
lucasteles / index.fs
Created May 19, 2021 20:22
F# Result Applicative
let listify r = r |> Result.mapError List.singleton
module Result =
let apply f x =
match f,x with
| Ok f, Ok x -> f x |> Ok
| Error f, Error x -> [f;x] |> List.concat |> Error
| Error f, Ok _ -> Error f
| Ok _, Error x -> Error x
let zip: Result<'a, _> -> Result<'b, _> -> Result<('a*'b), _> =