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 static IEnumerable<Memory<char>> TryReadLine(TextReader reader)
{
var bufferLength = (int)Math.Pow(2, 16);
var buffer = ArrayPool<char>.Shared.Rent(bufferLength);
var i = 0;
var j = 0;
var state = State.BeforeField;
int c;
private enum State
{
BeforeField,
InField,
InQuotedField,
LineEnd,
}
public static IEnumerable<Memory<char>> TryReadLine(TextReader reader)
{
@leandromoh
leandromoh / TryFormat for Enum.cs
Last active December 19, 2021 05:00
TryFormat for Enum with Span.cs
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
// ``` ini
//
using var bulkCopy = new SqlBulkCopy(
_connection,
SqlBulkCopyOptions.TableLock |
SqlBulkCopyOptions.FireTriggers |
SqlBulkCopyOptions.UseInternalTransaction,
null
);
bulkCopy.DestinationTableName = "table";
bulkCopy.BatchSize = 150_000;
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
const fii = { };
fii["XPTO"] = { qtd: 1 };
for(const ticker in fii){
@leandromoh
leandromoh / C# Além do basico pauta - leandro.txt
Created August 10, 2021 16:27
C# Além do basico pauta - leandro.txt
- Function first class citizen (guardar em variavel, função receber ou retornar outra função)
- Delegates (funções anonimas ou não)
- Actions/Func
- Lambda/Delegate
- LINQ
- Iterators (yield return, yield break)
- Expression Tree
- Baixo nivel (Class vs Struct, Span, ranges, ArrayPool, stackallock)
- Regex
colections array, list, queue, stack, dictionary, hashset
concurrent collections (ConcurrentBag, ConcurrentStack, ConcurrentQueue, etc)
imutabilidade
transparency referential
side-effects
pure functions
span, readOnlySpan, stackalloc, arrayPool, IOPipeline
ref, out, in
pattern match
@leandromoh
leandromoh / post_json_array.cs
Created June 12, 2021 21:48
reads json file with array of objects and post them in batches (example: post 6 requests in parallel, each time)
using MoreLinq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
@leandromoh
leandromoh / ClosureVisitor.cs
Created February 28, 2021 05:16
ExpressionVisitor that resolve closures for primitive types
using System;
using System.Linq.Expressions;
using System.Reflection;
namespace RecordParser.Generic
{
public class ClosureVisitor : ExpressionVisitor
{
protected override Expression VisitMember(MemberExpression member)
{
@leandromoh
leandromoh / Spread operator c#.cs
Last active February 19, 2021 21:51
Spread operator csharp
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
namespace Playground
{
public class Program