Skip to content

Instantly share code, notes, and snippets.

View pedroinfo's full-sized avatar

Pedro Xavier pedroinfo

  • São Paulo - BR - Solar System | Milky Way
View GitHub Profile
@pedroinfo
pedroinfo / PdfDownloadInterceptor.cs
Last active January 26, 2026 20:07
PdfDownloadInterceptor
public static class PdfDownloadInterceptor
{
public static async Task HandleAsync(ResponseTransformContext context)
{
var proxyResponse = context.ProxyResponse;
var httpContext = context.HttpContext;
if (proxyResponse == null)
return;
var builder = WebApplication.CreateBuilder(args);
// Configuração do YARP que preserva cookies e headers
builder.Services.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
.AddTransforms(builderContext =>
{
// Preserva todos os headers importantes
builderContext.AddRequestTransform(async context =>
{
@pedroinfo
pedroinfo / gist:a1d76c98eab40c08bde809676509e125
Last active January 12, 2026 15:24
DatabaseConnection.cs
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Dapper;
namespace Infrastructure.Database
{
// ================================
// 1. Enum
@pedroinfo
pedroinfo / SystemInfoHelper.cs
Last active January 2, 2026 20:44
SystemInfoHelper
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Management;
public static class SystemInfoHelper
{
// Stores last CPU samples per PID (important if pool recycles)
/// <summary>
/// Provides helper methods to retrieve runtime and assembly-related information
/// about the currently executing application.
/// </summary>
/// <remarks>
/// This class is designed to be framework-agnostic and can be safely used in
/// desktop, service, and web applications.
///
/// When running under IIS, the application entry assembly may not represent
/// the web application itself (it may resolve to the IIS worker process instead).
@pedroinfo
pedroinfo / HeartbeatService.cs
Created December 23, 2025 20:32
Simple Heartbeat
public class HeartbeatService : IDisposable
{
private readonly HeartbeatSettings _cfg;
private Timer _timer;
private bool _running;
public HeartbeatService(HeartbeatSettings cfg)
{
_cfg = cfg;
}
@pedroinfo
pedroinfo / .svc
Created December 17, 2025 13:23
Svc Enable
<system.webServer>
<security>
<requestFiltering>
<fileExtensions>
<add fileExtension=".svc" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Thread-safe logger for web APIs with buffered writing and daily rotation.
/// The file is only opened during flush, allowing safe moves at the end of the day.
ui "default" {
// Access only locally (recommended)
listen_address = "127.0.0.1:12345"
// For remote access: "0.0.0.0:12345"
}
@pedroinfo
pedroinfo / TimeSpanFormatter.cs
Created December 9, 2025 19:35
TimeSpanFormatter
public static class TimeSpanFormatter
{
public static string ToReadableString(TimeSpan ts)
{
var parts = new List<string>();
if (ts.Days > 0)
parts.Add($"{ts.Days} day{(ts.Days > 1 ? "s" : "")}");
if (ts.Hours > 0)