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
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();
@leandromoh
leandromoh / demostration how task works.cs
Created January 25, 2023 19:02
demostration how task works, C# and F#
// https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUKgBgAJVMA6AGQEsoBHAbj0JMwFZHcmAOEgNgB4awAHxEA4gFNgAMQD2sgBRCiVAJR4A3niI6SATj5kAIhIA2AQwCeCzAVUddLPUvvbdqAOwqOAXzx4AN3MwIgAPAGciAF4iAFEoCABbCTBzACNTCTIAJXMoAHMJGxgiW1UyAGUzCQBjYAVJGXlXXEc2vAAzWTAJcxqACwUgkNCVKDDwlqYDVF5jMysbAH0CVan8TGcAIkAeDcAQfa2WoA==
using System;
using System.Linq;
using System.Threading.Tasks;
async Task<int> GetFoo(int i)
{
await Task.Delay(10);
Console.WriteLine(i);