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
/// <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)
using System;
using System.Collections.Generic;
using System.Diagnostics;
public static class SystemInfoHelper
{
// Stores last CPU and time samples to compute deltas
private static TimeSpan _lastCpu = TimeSpan.Zero;
private static DateTime _lastSampleTime = DateTime.UtcNow;
@pedroinfo
pedroinfo / Global.asax.cs
Last active December 9, 2025 13:32
WebFormsOTELLogger
using System;
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
HeartbeatService.Start();
}
protected void Application_Error(object sender, EventArgs e)
Sub DiagnosticoSheets()
Dim wbThis As Workbook, wbActive As Workbook
Dim msg As String
Set wbThis = ThisWorkbook
Set wbActive = ActiveWorkbook
msg = "ThisWorkbook: " & wbThis.Name & vbCrLf
msg = msg & "ActiveWorkbook: " & IIf(wbActive Is Nothing, "(nenhum)", wbActive.Name) & vbCrLf
msg = msg & "ThisWorkbook.Sheets.Count = " & wbThis.Sheets.Count & vbCrLf
@pedroinfo
pedroinfo / JsonExcel
Created December 5, 2025 18:33
JsonExcel
Sub PreencherSheet2(json As Object)
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet2")
' Limpa a sheet toda
ws.Cells.Clear
' JSON deve ser um array de objetos
If json.Count = 0 Then Exit Sub