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 / UdpSocket.fsx
Last active March 13, 2024 14:32
F# UDP Socket
open System.Net.Sockets
open System.Net
open System
open System.Text
open System.Threading
let localPort = 8800
let serverPort = 8888
let serverUri = Uri("http://localhost")
@lucasteles
lucasteles / DateTimeForceLocalJsonConverter.cs
Last active February 28, 2024 15:42
Force UTC AspNet Core
using System.Text.Json;
using System.Text.Json.Serialization;
/// <summary>
/// Json converter for DateTime forcing local time
/// </summary>
public sealed class DateTimeForceLocalJsonConverter : JsonConverter<DateTime>
{
readonly TimeSpan offset;
@lucasteles
lucasteles / CircularBuffer.cs
Last active February 8, 2024 22:46
C# Circular Buffer
public sealed class CircularBuffer<T>(int capacity = 64) : IReadOnlyList<T>
where T : notnull
{
readonly T[] elements = new T[capacity];
int head, tail;
public int Capacity => elements.Length;
public int Length { get; private set; }
@lucasteles
lucasteles / README.md
Last active February 2, 2024 17:29
Desafio App Transações

App de Transações

Criar um app console SEM persistencia (nao precisa de banco de dados)

O que é?

Um programa que receberá linhas de um json como entrada stdin e deverá fornecer uma saída com a conta resultante para cada uma das operações em json

Como funciona?

@lucasteles
lucasteles / ValusList.cs
Last active February 1, 2024 17:40
C# ValueList - non-alloc stack list
using System;
using System.Runtime.CompilerServices;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
ValueList<int> nums = new();
nums.Add(10);
nums.Add(20);
@lucasteles
lucasteles / MemoryBuffer.cs
Created February 1, 2024 14:42
Disposable memory buffer
readonly struct MemoryBuffer<T> : IDisposable
{
readonly bool clearArray;
readonly T[] array;
public int Length { get; }
public Memory<T> Memory { get; }
internal MemoryBuffer(int size, bool clearArray = false)
{
@lucasteles
lucasteles / baixo-do-tapete.ts
Last active January 15, 2024 20:37
QuickSort in typescript type system
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 IsNever<T> = [T] extends [never] ? true : false
type Numbers = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
type IncMap = MapTuples<Tail<Numbers>, Numbers>
type Inc<T extends number> = T extends keyof IncMap ? IncMap[T] : never
export type Reverse<T extends any[], R extends any[] = []> = {
return: R
next: Reverse<Tail<T>, Cons<Head<T>, R>>
@lucasteles
lucasteles / capcom.fsx
Last active November 9, 2023 19:08
Capcom Sells FSharp
#r "nuget: FSharp.Data"
#r "nuget: Humanizer.Core"
#r "nuget: EluciusFTW.SpectreCoff"
open FSharp.Data
open SpectreCoff
open Humanizer
open System
open System.Globalization
open Spectre.Console
@lucasteles
lucasteles / Program.cs
Created November 1, 2023 16:37
DynamicProperties
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Text.Json;
using static System.Console;
Document[] docs =
{
new(
@lucasteles
lucasteles / Program.cs
Last active September 20, 2023 19:56
C# UDP Socket
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using static System.Text.Encoding;
using static System.Console;
const int MaxUdpByteSize = 65527;
static Socket CreateSocket(int port)
{