Skip to content

Instantly share code, notes, and snippets.

View leandromoh's full-sized avatar
💭
Talk is Cheap, Show me the code!

Leandro Fernandes leandromoh

💭
Talk is Cheap, Show me the code!
View GitHub Profile
@leandromoh
leandromoh / group values by time.cs
Created September 10, 2024 17:29
group values by time.cs
using System;
using System.Collections.Generic;
using System.Linq;
var series = new List<Sample>();
series.Add(new (){ timestamp = DateTime.Now.AddMinutes(-3) });
series.Add(new (){ timestamp = DateTime.Now.AddMinutes(0) });
series.Add(new (){ timestamp = DateTime.Now.AddMinutes(3) });
series.Add(new (){ timestamp = DateTime.Now.AddMinutes(4) });
series.Add(new (){ timestamp = DateTime.Now.AddMinutes(5) });
public class PipelineStageDefinitionBuilderSet<TDocument>
{
private UpdateDefinition<TDocument> current;
public PipelineStageDefinitionBuilderSet()
{
current = new BsonDocument();
}
public IPipelineStageDefinition ToPipelineStageDefinition()
@leandromoh
leandromoh / HashGenerator.cs
Created December 24, 2023 02:37
serialize objects to json then get md5 hashes without too much string allocations
using System.Buffers;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
public interface IHashGenerator
{
void GenerateHashes<T>(IEnumerable<T> source, Action<T, string> action);
void GenerateHashes<T, TKey>(IEnumerable<T> source, Func<T, TKey> selector, Action<T, string> action);
}
@leandromoh
leandromoh / join array json file.cs
Created September 23, 2023 16:34
downlods array json file with paginating GET request & join multiples array json files into one
using ConsoleApp2;
using MoreLinq;
using System.Buffers;
using System.IO.Compression;
using System.Reflection;
using System.Text;
namespace ConsoleApp3
{
public class Program
@leandromoh
leandromoh / MongoExtensions.cs
Created September 14, 2023 21:53
C# extensions for MongoDB BsonDocument
public static class MongoExtensions
{
public static readonly Regex Indexer = new Regex(@"\[\d+\]", RegexOptions.Compiled);
public static void FullMerge(this BsonDocument b1, BsonDocument b2)
{
for (int i = 0; i < b2.ElementCount; i++)
{
var e2 = b2.ElementAt(i);
if (b1.TryGetElement(e2.Name, out var e1))
public static string ToMd5(this string input)
{
var inputBytes = Encoding.ASCII.GetBytes(input);
return inputBytes.ToMd5(0, inputBytes.Length);
}
public static string ToMd5(this byte[] inputBytes, int offset, int count)
{
Span<char> chars = stackalloc char[32];

Distributed Computing

  • Brewers’ Theorem ― a distributed computer system cannot provide consistency, availability and partition tolerance, all at optimal levels.

8 Fallacies of Distributed Computing (L. Peter Deutsch)

  • The network is reliable.
  • Latency is zero.
  • Bandwidth is infinite.
  • The network is secure.
  • Topology doesn’t change.

problema 1:

  • PRs grandes solução:
  • 1 PBI as vezes pode virar mais de 1 PR que entrega valor (quando fizer sentido), exemplo CRUD pode ser 4 PR
  • eh muito mais facil 4 pessoas terem tempo de revisar 1 PR de 30m, do que 1 pessoa revisar 1 PR de 2h
  • mergear eventuais branch de release antes de ficarem muito grandes (vide cash-reserve ou gestão de contas)
  • exceto quando for irrisório, nao implementar features que vão subir comentadas ou testes desligados pra adiantar algo

problema 2:

  • muitas idas e vindas durante o review
using System;
using System.Collections.Generic;
using System.Linq;
var values = GenerateRandomNumber(200);
foreach(var x in MergeSort(values))
Console.WriteLine(x);
static int[] GenerateRandomNumber(int size)
@leandromoh
leandromoh / currying x objects.cs
Last active April 28, 2023 16:32
demonstrates how we use currying to fixe values in FP as well we do with object fields in OOP
using System;
var greeting = (string me, int age, string friend) =>
$"Hello {friend}, my name is {me} and I am {age} years old";
var f = greeting.Curry()("Ana")(13);
Console.WriteLine(f("Bob"));
Console.WriteLine(f("Carla"));
Console.WriteLine();