Skip to content

Instantly share code, notes, and snippets.

View MrBogomips's full-sized avatar
🐋
I may be a whale in responding you…

Giovanni Costagliola MrBogomips

🐋
I may be a whale in responding you…
  • Nexus Advanced Technologies
View GitHub Profile
@MrBogomips
MrBogomips / DictionaryKeyValueJsonConverterFactory.cs
Created August 2, 2023 09:45
.NET JsonConverterFactory for Dictionary<string, T>.
/*
* JsonConverterFactory to serialize Dictionary with string as keys.
* This serializer will produce a json where the key becomes the property of the json item.
*/
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Bogoware.Common.JsonConverters;
/// <summary>
@MrBogomips
MrBogomips / ExceptionExtensions.cs
Last active July 23, 2023 17:34
C# Exception Util for Json Serialization
using System.Text.Json.Serialization;
namespace MyAwesomeProject.Shared.Utils;
public static class ExceptionExtensions
{
public class ExceptionInfo
{
public ExceptionInfo() { }
static readonly byte[] _oddMap = new byte[] { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 };
static bool PartitaIvaCheckSum(string value)
{
Debug.Assert(value is not null);
Debug.Assert(value.Length == 11);
// ASSERT: value is a string of digits
var c0 = (byte) '0';
int acc = 0;
byte[] codes = Encoding.ASCII.GetBytes(value);
/// <summary>
/// Italian fiscal id for companies
/// </summary>
public class PartitaIva: SimpleValueObject<string>
{
public const int MaxLength = 255;
public PartitaIva(string value) : base(value) { }
private static readonly int[] _oddMap = new int[] { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 };
public static class JsonUtils
{
/// <summary>
/// Indent a string containing a valid Json
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static async Task<string> GetIndentedAsync(string json)
{
@MrBogomips
MrBogomips / CSharp_EnvironmentVariablesLoggerFunction.cs
Created December 5, 2020 11:00
C# Environment Variables Logger Function
private static void LogEnvironmentInfo(ILogger<YOUR_CLASS> log) {
var envs = Environment.GetEnvironmentVariables();
StringBuilder sb = new StringBuilder();
foreach (var k in envs.Keys) sb.AppendLine($"{k}: {envs[k]}");
log.LogInformation(sb.ToString());
}
@MrBogomips
MrBogomips / # gradle - 2019-10-23_14-03-29.txt
Created October 23, 2019 12:12
gradle on macOS 10.15 - Homebrew build logs
Homebrew build logs for gradle on macOS 10.15
Build date: 2019-10-23 14:03:29
@MrBogomips
MrBogomips / RandomWeightedPicker.cs
Created May 11, 2016 22:44
A Random Weighted Picker in C#
// Author: Giovanni Costagliola <giovanni.costagliola@gmail.com>
using System;
using System.Collections.Generic;
using System.Linq;
namespace Utils
{
/// <summary>
/// Represent a Weighted Item.
@MrBogomips
MrBogomips / .gitignore
Last active August 29, 2015 14:14
Scala Generic .gitignore
*.class
*.log
# sbt specific
.cache
.history
.lib/
dist/*
target/
lib_managed/
@MrBogomips
MrBogomips / .gitignore_keepdir
Created February 3, 2015 16:30
A .gitignore file suitable to keep a directory in a git repository while discarding all the contents.
# ATTENTION: rename this file to .gitignore!!!
# Ignore everything in this directory
*
# Except this file
!.gitignore