Skip to content

Instantly share code, notes, and snippets.

View nelson-parente's full-sized avatar
💭
If it walks like a duck and it quacks like a duck, then it must be a duck

Nelson Parente nelson-parente

💭
If it walks like a duck and it quacks like a duck, then it must be a duck
View GitHub Profile
package main
import (
"crypto/sha256"
"encoding/binary"
"flag"
"fmt"
"math/rand"
"os"
@nelson-parente
nelson-parente / TheOffice.cs
Last active December 14, 2021 10:59
Simple the reference types
public static void Main()
{
var jim = new Person("Jim", "Halpert");
var dwight = jim;
Mutate(dwight);
Console.WriteLine($"Hello! I'm {jim.FirstName} {jim.LastName}.");
Console.WriteLine($"Hello! I'm {dwight.FirstName} {dwight.LastName}.");
}
@nelson-parente
nelson-parente / ValueType.cs
Last active December 14, 2021 11:59
ValueTypeOutput
public class Program
{
public static void Main()
{
int x = 10;
Update(x);
Console.WriteLine($"x is {x}");
}
@nelson-parente
nelson-parente / Program.cs
Created November 11, 2021 10:30
Minimal Api Program
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();
private static async Task Main(string[] args)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var janeTask = DoWorkAsync("Jane", 1000);
var exceptionTask1 = WaitAndThrowExceptionAsync(1, 500);
var johnTask = DoWorkAsync("John", 2000);
var exceptionTask2 = WaitAndThrowExceptionAsync(2, 1500);
private static async Task Main(string[] args)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var janeTask = DoWorkAsync("Jane", 1000);
var exceptionTask1 = WaitAndThrowExceptionAsync(1, 1500);
var johnTask = DoWorkAsync("John", 2000);
var exceptionTask2 = WaitAndThrowExceptionAsync(2, 500);
private static async Task Main(string[] args)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var janeTask = DoWorkAsync("Jane", 1000);
var johnTask = DoWorkAsync("John", 2000);
await Task.WhenAll(janeTask, johnTask);
private static async Task Main(string[] args)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
await DoWorkAsync("Jane", 1000);
await DoWorkAsync("John", 2000);
stopwatch.Stop();
Console.WriteLine($"Total Work took {stopwatch.ElapsedMilliseconds} ms");
public class Shapes
{
private static readonly AsyncLocal<string> _asyncLocal = new AsyncLocal<string>();
static void Main(string[] args)
{
SetValue("Square");
Circle().GetAwaiter().GetResult();
}