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
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
@pedroinfo
pedroinfo / gist:788683a57959199abac2e7275bb4bfd4
Last active December 5, 2025 18:07
PreencherJsonNaSheet2
Sub ParseJsonToSheet(jsonText As String, sheetName As String)
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets(sheetName)
ws.Cells.Clear
Dim json As String
json = Trim(jsonText)
' Remove [ ]
If Left(json, 1) = "[" Then json = Mid(json, 2)
public class ApiKeyMiddleware
{
private readonly RequestDelegate _next;
private readonly string _apiKey;
private const string HeaderName = "x-api-key";
public ApiKeyMiddleware(RequestDelegate next, IConfiguration config)
{
_next = next;
_apiKey = config["Security:ApiKey"];
for /r %i in (*) do powershell -NoProfile -Command "Unblock-File -Path '%~fi'"
@pedroinfo
pedroinfo / Macros
Last active September 12, 2025 17:49
# Lista versões comuns do Office (16.0 = 2016/2019/365, 15.0 = 2013, 14.0 = 2010)
$officeVersions = @("16.0", "15.0", "14.0")
foreach ($version in $officeVersions) {
$path = "HKCU:\Software\Microsoft\Office\$version\Excel\Security"
if (Test-Path $path) {
Write-Output "Aplicando configuração para Excel versão $version..."
# Cria a chave se não existir
"1073741824" <!-- 1 GB -->
<system.web>
<httpRuntime maxRequestLength="2097151" executionTimeout="600" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
@pedroinfo
pedroinfo / Form1.cs
Last active September 10, 2025 17:31
WCF Upload Tests
using System;
using System.IO;
using System.ServiceModel;
using System.Windows.Forms;
namespace WcfFileUploadClient
{
public partial class Form1 : Form
{
public Form1()