Skip to content

Instantly share code, notes, and snippets.

View joelverhagen's full-sized avatar

Joel Verhagen joelverhagen

View GitHub Profile
@joelverhagen
joelverhagen / GenerateVersionId.cs
Last active July 23, 2024 15:01
Generate version ID
private static string GenerateVersionId(Guid extensionId, string version, string? targetPlatform)
{
StringBuilder builder = new();
builder.Append(extensionId.ToString("D")); // use default string format
builder.Append('|'); // extension ID cannot contain '|'
builder.Append(version.ToLowerInvariant()); // SQL collation is case insensitive
if (targetPlatform is not null)
{
@joelverhagen
joelverhagen / Program.cs
Created April 5, 2024 16:22
Managed identities or user impersonation with WindowsAzure.Storage
using System;
using System.Linq;
using Azure.Core;
using Azure.Identity;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
internal class Program
{
private static void Main(string[] args)
----------------------------------------
at Knapcode.FactorioTools.OilField.LocationIntSet..ctor(Int32 width, Int32 height)
at Knapcode.FactorioTools.OilField.Context.GetLocationSet()
at Knapcode.FactorioTools.SetHandling.ToSet(IEnumerable`1 items, Context context)
at Knapcode.FactorioTools.OilField.AddElectricPoles.GetElectricPoleGroups(Context context, Dictionary`2 electricPoles)
at Knapcode.FactorioTools.OilField.AddElectricPoles.ConnectElectricPoles(Context context, Dictionary`2 electricPoles)
at Knapcode.FactorioTools.OilField.AddElectricPoles.Execute(Context context, LocationIntSet avoid, Boolean allowRetries)
at Knapcode.FactorioTools.OilField.Planner.Execute(OilFieldOptions options, Blueprint blueprint, LocationIntSet electricPolesAvoid, EletricPolesMode electricPolesMode)
at Knapcode.FactorioTools.OilField.Planner.Execute(OilFieldOptions options, Blueprint inputBlueprint)
Total: 6775
@joelverhagen
joelverhagen / Program.cs
Created December 1, 2023 15:56
Validate consistency of NuGet.org catalog page items and pages
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Serialization;
using Xunit;
Console.WriteLine("Starting...");
var indexUrl = "https://api.nuget.org/v3/catalog0/index.json";
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
@joelverhagen
joelverhagen / Program.cs
Last active October 26, 2023 16:11
Missing x-ms-client-request-id in Azurite
using System.Net.Http.Headers;
using Azure.Core.Pipeline;
using Azure.Data.Tables;
using Azure.Storage.Blobs;
using Azure.Storage.Queues;
var connectionString = "UseDevelopmentStorage=true";
// var connectionString = "DefaultEndpointsProtocol=https;AccountName=REDACTED;AccountKey=REDACTED;EndpointSuffix=core.windows.net";
var pipeline = new HttpClientTransport(new TestHandler { InnerHandler = new HttpClientHandler() });
@joelverhagen
joelverhagen / Program.cs
Last active October 17, 2023 17:18
Performance test for in-memory Azurite
using Azure.Data.Tables;
using Azure.Storage.Blobs;
using Azure.Storage.Queues;
using Azure.Storage.Queues.Models;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Extensions;
using System.Diagnostics;
using System.Net;
using System.Text;
@joelverhagen
joelverhagen / Program.cs
Last active October 26, 2023 19:53
Retry conflicts with Azure SDK
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Text.Json;
using Azure;
using Azure.Core;
using Azure.Core.Pipeline;
using Azure.Data.Tables;
var messageHandler = new TestHandler { InnerHandler = new SocketsHttpHandler() };
var serviceClient = new TableServiceClient(
@joelverhagen
joelverhagen / AppInsightsDataSize.kql
Created October 1, 2023 18:25
Determine what telemetry is taking up the most space in Application Insights
let since = ago(1d);
let bucket = 5m;
let dt = datatable(table: string)[];
dt
| union (availabilityResults | where timestamp > since | summarize sum(estimate_data_size(*)) by bin(timestamp, bucket), cloud_RoleName | extend table = "availabilityResults")
| union (browserTimings | where timestamp > since | summarize sum(estimate_data_size(*)) by bin(timestamp, bucket), cloud_RoleName | extend table = "browserTimings")
| union (customEvents | where timestamp > since | summarize sum(estimate_data_size(*)) by bin(timestamp, bucket), cloud_RoleName | extend table = "customEvents")
| union (customMetrics | where timestamp > since | summarize sum(estimate_data_size(*)) by bin(timestamp, bucket), cloud_RoleName | extend table = "customMetrics")
| union (dependencies | where timestamp > since | summarize sum(estimate_data_size(*)) by bin(timestamp, bucket), cloud_RoleName | extend table = "dependencies")
| union (exceptions | where timestamp > since | summarize sum(estimate_data_size(*)) by bin(timestamp, bucket), clou
@joelverhagen
joelverhagen / train-caged.lua
Created August 21, 2023 17:20
DFHack script train-caged: Marks all caged, trainable creatures for training
-- Marks all caged, trainable creatures for training.
-- Author: Joel Verhagen (@joelverhagen on GitHub)
local utils = require('utils')
function getTrainingAssignment(unit)
local training_assignment, _, _ = utils.binsearch(
df.global.plotinfo.equipment.training_assignments,
unit.id,
'animal_id')