Skip to content

Instantly share code, notes, and snippets.

@joaopgrassi
joaopgrassi / Dockerfile
Last active July 16, 2018 20:13
Docker image that creates, builds and runs a simple .net core console app using multi-stage build
# A simple test using multi-stage builds in Docker to create a simple console app using dotnet core
# if only using the sdk, the image size is 1.7GB. Using multi-stage build the size is reduced to 180mb
FROM microsoft/dotnet:2.1-sdk AS build
## creates and builds the app
RUN dotnet new console -lang "c#" -n testapp
RUN cd testapp
WORKDIR /testapp/
RUN dotnet build -c Release -o output
@joaopgrassi
joaopgrassi / Program.cs
Last active July 24, 2018 13:15
Playing around with SelectMany and Lookup(TKey, TElement). This example shows a List of Marvel Super Heroes and in which Universes they appear. The initial collection is composed by Universes that contains characters. The objective is to find out in which universes a character appeared.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("List of Marvel universes where some famous super heroes appear");
var universes = new[]
{
new Universe("Earth-616", "Main Continuity", new[]
{
param (
[Parameter(Mandatory = $true)]
[string]
$compareConfigFile
)
# Gladly copied from: https://info.sapien.com/index.php/scripting/scripting-how-tos/how-to-find-installation-directory
function Get-InstallPath
{
[CmdletBinding()]
@joaopgrassi
joaopgrassi / Flags Enum to String array Json Converter
Last active October 14, 2018 20:23
An example of an JsonConverter that converts a Flags enum to an string[]. Also converters string[] and int[] back to Flags enum type. Supports generic types
public class FlagsEnumToStringArrayJsonConverter<T> : JsonConverter
where T: struct
{
public override bool CanConvert(Type objectType)
{
return objectType.IsEnum && objectType.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0;
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
@joaopgrassi
joaopgrassi / FlagsEnumToStringArrayJsonConverter.cs
Last active October 14, 2018 20:24
An example of a JsonConverter that converts a Flags Enum to a string[]. Also converters string[] and int[] back to Flags Enum type. Supports generics.
public class FlagsEnumToStringArrayJsonConverter<T> : JsonConverter
where T: struct
{
public override bool CanConvert(Type objectType)
{
return objectType.IsEnum && objectType.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0;
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
@joaopgrassi
joaopgrassi / ExpandableController.cs
Last active October 24, 2018 07:24
A sample of a controller action receiving an "expand" query parameter that enable returning detailed data
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace WebApplication2.Controllers
{
[Route("api/entities")]
public class ExpandableController : ApiController
{
[HttpGet]

Keybase proof

I hereby claim:

  • I am joaopgrassi on github.
  • I am joaopgrassi (https://keybase.io/joaopgrassi) on keybase.
  • I have a public key ASAIS_44lltPJNobFcHIm63uCIpdP1WIUHz9uOnMPLQDTAo

To claim this, I am signing this object:

@joaopgrassi
joaopgrassi / .gitconfig
Last active June 6, 2019 18:36
My custom git shortcuts and merge tool settings.
[alias]
co = checkout
cob = checkout -b
cm = !git add -A && git commit -m
b = branch
pu = push -u origin HEAD
st = status
[merge]
tool = p4merge
[mergetool "p4merge"]
@joaopgrassi
joaopgrassi / randomrsa.cs
Created July 31, 2019 13:20
Creates a random RSA key used for signing jwt tokens. Also exports the public key in PEM format.
private static (string publicKeyPem, SigningCredentials signingCredentials) GenerateRamdomRsaKeyPair()
{
SigningCredentials signingCredentials = null;
string publicKeyPem;
using (RSA rsa = RSA.Create())
{
rsa.KeySize = 4096;
var rsaParams = rsa.ExportParameters(false);
@joaopgrassi
joaopgrassi / ConEmu.xml
Created November 3, 2019 11:43
My pallet colors from material theme
<key name="Colors" modified="2019-09-20 22:17:06" build="190526">
<value name="Count" type="long" data="1"/>
<key name="Palette3" modified="2019-09-20 22:12:13" build="190526">
<value name="Name" type="string" data="Oceans16 Dark"/>
<value name="ExtendColors" type="hex" data="00"/>
<value name="ExtendColorIdx" type="hex" data="10"/>
<value name="TextColorIdx" type="hex" data="10"/>
<value name="BackColorIdx" type="hex" data="10"/>
<value name="PopTextColorIdx" type="hex" data="10"/>
<value name="PopBackColorIdx" type="hex" data="10"/>