Skip to content

Instantly share code, notes, and snippets.

View seesharprun's full-sized avatar

Sidney Andrews seesharprun

View GitHub Profile
@seesharprun
seesharprun / AzureIdentityTokenHandler.cs
Last active April 25, 2025 03:59
C# console how-to guide for Entra auth in Azure Cosmos DB for MongoDB vCore
using Azure.Core;
using MongoDB.Driver.Authentication.Oidc;
internal sealed class AzureIdentityTokenHandler(
TokenCredential credential,
string tenantId,
string[] scopes
) : IOidcCallback
{
public OidcAccessToken GetOidcAccessToken(OidcCallbackParameters parameters, CancellationToken cancellationToken)
@seesharprun
seesharprun / Program.cs
Created April 23, 2025 15:47
Convert SVG to a PNG for a favicon
using System.Drawing;
using Svg;
FileInfo source = new(@"source.svg");
FileInfo target = new(@"target.png");
int width = 32;
int height = 32;
float dpi = 96f;
@seesharprun
seesharprun / readme.md
Last active April 15, 2025 15:09
Spark & Managed Identities
@seesharprun
seesharprun / Program.cs
Created December 5, 2024 22:05
Bulk & Stream support
using Azure.Core;
using Azure.Identity;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Cosmos.Fluent;
string endpoint = "<nosql-account-endpoint>";
TokenCredential credential = new DefaultAzureCredential();
CosmosClient client = new CosmosClientBuilder(endpoint, credential)
.WithBulkExecution(true)
using Microsoft.Azure.Cosmos;
string endpoint = "<nosql-account-endpoint>";
string key = "<nosql-account-read-write-key>";
CosmosClient client = new(endpoint, key, options);
string databaseName = "<database-name>";
string containerName = "<container-name>";
@seesharprun
seesharprun / Program.cs
Last active November 8, 2024 14:47
Spectre.Console integrated console application (Generic Host)
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting.Internal;
using Spectre.Console;
using Spectre.Console.Cli;
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSingleton<IAnsiConsole>((_) =>
AnsiConsole.Create(
@seesharprun
seesharprun / Program.cs
Last active November 8, 2024 03:46
Azure Cosmos DB console application (Generic Host)
using Azure.Identity;
using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
@seesharprun
seesharprun / Program.cs
Last active November 8, 2024 03:40
Simple console application (Generic Host)
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSingleton<IHostLifetime, ConsoleLifetime>();
builder.Services.AddScoped<IMessageService, MessageService>();
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<PingWorker>();
var host = builder.Build();
await host.RunAsync();
@seesharprun
seesharprun / .gitignore
Created September 8, 2022 15:55
Azure Cosmos DB SQL API + Node.js
node_modules/
package-lock.json