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 / base64file.ps1
Created April 14, 2025 21:02
Convert binary file to base-64 using Powershell
$filePath = "C:\path\to\your\file.txt"
$outputPath = "C:\path\to\output\encodedFile.txt"
# Read the file content as bytes
$fileContent = [System.IO.File]::ReadAllBytes($filePath)
# Convert the byte array to a Base64 string
$base64String = [Convert]::ToBase64String($fileContent)
# Output the Base64 string to a new file
@skarllot
skarllot / GenerationDepthBehavior.cs
Created April 10, 2025 15:59
Control the depth when building fixture instances using AutoFixture
using System.Collections;
using AutoFixture.Kernel;
public class GenerationDepthBehavior : ISpecimenBuilderTransformation
{
private const int DefaultGenerationDepth = 1;
private readonly int _generationDepth;
public GenerationDepthBehavior(int generationDepth = DefaultGenerationDepth)
{
@skarllot
skarllot / MockLogger.Moq.cs
Created April 8, 2025 18:04
Mocking ILogger
using Microsoft.Extensions.Logging;
using Moq;
public static class MockLogger
{
public static Mock<ILogger<T>> Create<T>()
{
var mock = new Mock<ILogger<T>>();
mock.Setup(l => l.IsEnabled(It.IsAny<LogLevel>())).Returns(true);
return mock;
@skarllot
skarllot / CreateArchive.ps1
Created April 4, 2025 19:49
Create archive ignoring folders using 7-Zip
& 'C:\Program Files\7-Zip\7z.exe' a dest.zip . -r "-x!.git" "-x!.terraform"
& 'C:\Program Files\7-Zip\7z.exe' a dest.zip MyFolder\ -r -x!bin -x!obj
@skarllot
skarllot / AutoFixtureExtensions.cs
Created April 2, 2025 12:17
Set custom value for init-only properties on AutoFixture
using System.Linq.Expressions;
using AutoFixture;
public static class AutoFixtureExtensions
{
public static FixtureCustomization<T> For<T>(this Fixture fixture) => new(fixture);
public class FixtureCustomization<T>(Fixture fixture)
{
public FixtureCustomization<T> With<TProp>(Expression<Func<T, TProp>> expr, TProp value)
@skarllot
skarllot / config.toml
Created March 1, 2025 23:28
Gitlab runner configuration using Powershell on Windows
concurrent = 5
check_interval = 0
connection_max_age = "15m0s"
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "gitlab-runner01"
@skarllot
skarllot / ServiceCollectionExtensions.cs
Created February 25, 2025 22:20
The equivalent of AsImplementedInterfaces+InstancePerLifetimeScope from AutoFac on Microsoft DependencyInjection
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Example;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddImplementedInterfacesAsScoped(
this IServiceCollection services,
@skarllot
skarllot / ImmutableListSpecimenBuilder.cs
Created January 30, 2025 21:49
AutoFixture support to ImmutableList
using System.Collections.Immutable;
using AutoFixture.Kernel;
public class ImmutableListSpecimenBuilder : ISpecimenBuilder
{
public object Create(object request, ISpecimenContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
@skarllot
skarllot / .gitleaks.toml
Created December 27, 2024 12:42
Setup Gitleaks to ignore a non-secret value
[extend]
useDefault = true
[allowlist]
description = "Fake secrets"
regexTarget = "match"
regexes = [
"6a654835c594485b8980ba2c73af6f18"
]
@skarllot
skarllot / subnet.bicep
Created December 19, 2024 15:22
Example condition that does not work on Bicep
resource natGateway 'Microsoft.Network/natGateways@2023-11-01' = if (hasNatGateway) {
name: natGatewayName
location: location
sku: {
name: 'Standard'
}
}
resource subnets 'Microsoft.Network/virtualNetworks/subnets@2022-11-01' = {
name: name