Skip to content

Instantly share code, notes, and snippets.

@gsscoder
gsscoder / ChaosHealthCheck.cs
Created March 18, 2021 16:56
Basic IHealthCheck implementation that injects chaos
using System;
using System.Threading;
using System.Threading.Tasks;
using Polly.Contrib.Simmy;
using Polly.Contrib.Simmy.Outcomes;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using CSharpx;
sealed class ChaosHealthCheck : IHealthCheck
{
@gsscoder
gsscoder / AvailabilityCanaryFunction.cs
Last active March 19, 2021 06:56
Simple C# availability canary Function App
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
namespace HealthTest2
{
@gsscoder
gsscoder / JsonUtil_Prettify.cs
Last active March 25, 2021 07:36
C# helper method to pretty print JSON (ILogger friendly)
// based on: https://gist.github.com/FrankHu-MSFT/b6750185b19fd4ada4ba36b099985813
// can removes \r to fit in a single log line when using ILogger
using System.IO;
using Newtonsoft.Json;
static class JsonUtil
{
public static string Prettify(string json, bool stripLineFeed = false)
{
using var stringReader = new StringReader(json);
@gsscoder
gsscoder / ExportJsonARMTemplate.cs
Last active December 9, 2021 07:59
C# sample that demonstrates programmatic JSON AzureRM template export
// requires Microsoft.IdentityModel.Clients.ActiveDirectory 5.29
// Microsoft.Azure.Management.ResourceManager 3.15.1-preview
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.ResourceManager.Models;
@gsscoder
gsscoder / EnumerableExtensions_Partition.cs
Created December 10, 2021 11:16
C# extension method to partition sequences by a value
using System;
using System.Collections.Generic;
using System.Linq;
using SharpX.Extensions;
static class EnumerableExtensions
{
public static IEnumerable<IEnumerable<T>> Partition<T, TKey>(this IEnumerable<T> source, Func<T, TKey> selector)
{
var result = new List<IEnumerable<T>>();
@gsscoder
gsscoder / ImageUtil.cs
Last active April 19, 2024 11:59
C# image utilities
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
public static class ImageUtil
{
public static Image Resize(this Image image, int width, int height)
{
var destRect = new Rectangle(0, 0, width, height);
@gsscoder
gsscoder / BubbleSort.sol
Created February 3, 2023 13:49
Bubble sort implementation in Solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract BubbleSort {
function sort(uint[] memory array) public pure returns (uint[] memory) {
bool swapped;
for (uint i = 1; i < array.length; i++) {
swapped = false;
@gsscoder
gsscoder / PageExtensions,cs
Created January 29, 2025 18:15
C# extension method to set stealth mode in PuppeteerSharp
using PuppeteerSharp;
using SharpX.Extensions;
static class PageExtensions
{
static string[] _desktopUserAgents = new[]
{
// Chrome User Agents
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.138 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.138 Safari/537.36",
@gsscoder
gsscoder / AI_Behavioral_Guardrails.md
Created April 22, 2026 17:18
AI Instructions File - Behavioral Guardrails

Behavioral Guardrails

  • Verify Assumptions Before Acting: always confirm ambiguous requirements with the user instead of assuming intent and proceeding silently
  • Surface Confusion and Inconsistencies: when encountering unclear, contradictory, or incomplete specs, explicitly flag them and ask for clarification rather than guessing
  • Prioritize Honesty Over Agreement: push back on questionable requests and defend sound technical choices instead of immediately complying with every suggestion
  • Favor Simplicity Over Abstraction: write the simplest solution that meets the requirements; avoid unnecessary layers, patterns, and bloated APIs unless explicitly justified
  • Clean Up After Yourself: remove dead code, unused imports, and stale comments introduced or made obsolete during your changes.
  • Do Not Touch Unrelated Code: never modify, reformat, or delete comments and code that are orthogonal to the current task, even if they seem improvable
  • Respect User Instructions Strictly: tre