Skip to content

Instantly share code, notes, and snippets.

View skarllot's full-sized avatar
💭
I may be slow to respond.

Fabrício Godoy skarllot

💭
I may be slow to respond.
View GitHub Profile
@skarllot
skarllot / ChangeErrorsSubject.cs
Created April 7, 2024 21:18
Subject class for using INotifyDataErrorInfo with Avalonia UI
using System.Collections;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Reactive.Subjects;
using CSharpFunctionalExtensions;
namespace Example;
public sealed class ChangeErrorsSubject : ISubject<ImmutableList<PropertyDataError>>, INotifyDataErrorInfo, IDisposable
{
@skarllot
skarllot / replacer.tf
Created March 22, 2024 17:27
Terraform multiple replaces
# Ref: https://stackoverflow.com/a/67392622/23266117
locals {
input = file("./sample.txt")
map = {
food = "Sushi"
name = "Data_sniffer"
}
out = join("\n", [
@skarllot
skarllot / FormatExtensions.cs
Created February 25, 2024 16:22
Allocation free int to string (incomplete)
public static class FormatExtensions
{
public static string Int32ToString(int a)
{
const int radix = 10;
const int maxLength = 11;
Span<char> str = stackalloc char[maxLength];
int i = str.Length;
bool isNegative = a < 0;
@skarllot
skarllot / .gitconfig
Created January 29, 2024 22:56
Git config include (Windows)
# Global
[includeIf "gitdir/i:C:/Users/<user>/Source/repos/github/<user>/"]
path = C:/Users/<user>/Source/repos/github/<user>/.gitconfig
[includeIf "gitdir/i:~/Source/repos/github/<user>/"]
path = ~/Source/repos/github/<user>/.gitconfig
# Path
[user]
email = <email>
@skarllot
skarllot / get-azure-current-user.cs
Created January 25, 2024 17:29
Get current Azure logged user
Claim displayName = ClaimsPrincipal.Current.FindFirst(ClaimsPrincipal.Current.Identities.First().NameClaimType);
ViewBag.DisplayName = displayName != null ? displayName.Value : string.Empty;
@skarllot
skarllot / array-extension.ts
Created November 29, 2023 21:17
Find last index of an array (mirror of ES2015 findIndex function)
/**
* Returns the index of the last element in the array where predicate is true, and -1
* otherwise.
* @param array The source array to search in
* @param predicate find calls predicate once for each element of the array, in descending
* order, until it finds one where predicate returns true. If such an element is found,
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
*/
export function findLastIndex<T>(array: Array<T>, predicate: (value: T, index: number, obj: T[]) => boolean): number {
let l = array.length;
@skarllot
skarllot / README.md
Created September 14, 2023 20:13
Enable Long Paths in Windows 10, Version 1607, and Later
@skarllot
skarllot / ServiceCollectionExtensions.cs
Created July 30, 2023 16:43
Register self with interfaces dependency injection
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddSelfWithInterfacesSingleton<TService>(this IServiceCollection services)
where TService : class
{
services.AddSingleton<TService>();
@skarllot
skarllot / git-logs.sh
Last active December 12, 2023 18:53
Analyze Git commits between branches
# Format: - 2023-05-15 Name: Commit message
git log --cherry-pick --right-only --no-merges --reverse --pretty="- %ad %cn: %s" --date=short branch-a...branch-b
# Format: - 2023-05-15 Commit message
git log --cherry-pick --reverse --pretty="- %ad %<(35,trunc)%s" --date=short branch-a...branch-b
# Format: example@example.com 2023-04-25 initial commit
git log --cherry --reverse --pretty="%<(20,trunc)%ce%x09%>(10)%ad%x09%s" --date=short branch-a...branch-b
git log --cherry --reverse branch-a...branch-b
@skarllot
skarllot / run-windows.sh
Created May 3, 2023 02:01
Sign commits and tags with X.509 certificates
# 1. Get a free S/MIME e-mail certificate
# Actalis: https://extrassl.actalis.it/portal/uapub/freemail?lang=en
# 2. Install S/MIME Sign
# https://github.com/github/smimesign/releases
#
# Download latest stable release
# eg: https://github.com/github/smimesign/releases/download/v0.2.0/smimesign-windows-amd64-v0.2.0.zip
# Unpack to 'C:\Program Files\Github' folder