Skip to content

Instantly share code, notes, and snippets.

@brianpursley
brianpursley / Example.pubxml
Created March 9, 2017 15:08
An example Visual Studio pubxml file to zip the output when publishing an ASP.NET web application to file system
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>C:\Publish\SimpleExample</publishUrl>
@brianpursley
brianpursley / assembly_version.sh
Created April 16, 2024 17:34
Script that prints the version of a .NET assembly
#!/bin/sh
command -v dotnet >/dev/null 2>&1 || { echo >&2 "dotnet is not installed. Please install it and try again."; exit 1; }
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <path_to_dll>"
exit 1
fi
temp_dir=$(mktemp -d)
@brianpursley
brianpursley / cgroup-resources.sh
Created April 13, 2023 02:51
Get cgroup resources using crictl
sudo crictl inspect $(sudo crictl ps --name bar -q) | jq '.info.runtimeSpec.linux.resources'
sudo crictl inspect $(sudo crictl ps --name baz -q) | jq '.info.runtimeSpec.linux.resources'
@brianpursley
brianpursley / remove-extended-resources.sh
Last active April 13, 2023 01:11
Remove extended resources from kubernetes nodes
kubectl patch node k8s-worker-1 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/example.com~1fakecpu"}]'
kubectl patch node k8s-worker-1 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/example.com~1fakePTSRes"}]'
kubectl patch node k8s-worker-1 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/scheduling.k8s.io~1foo"}]'
kubectl patch node k8s-worker-2 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/example.com~1fakecpu"}]'
kubectl patch node k8s-worker-2 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/example.com~1fakePTSRes"}]'
kubectl patch node k8s-worker-2 --subresource=status --type=json -p='[{"op":"remove","path":"/status/capacity/scheduling.k8s.io~1foo"}]'
@brianpursley
brianpursley / Overview.md
Last active April 5, 2023 14:09
Incorrect limits displayed for multi-container pods

Incorrect limits displayed for multi-container pods

Summary

Pod resource limits are incorrectly calculated in kubectl describe node when all the following conditions are met:

  1. The pod has multiple containers (including init containers).
  2. At least one container specifies a resource limit.
  3. At least one container does not specify a resource limit for a resource type for which another container has specified a resource limit.
@brianpursley
brianpursley / openapi-bad.json
Last active January 19, 2023 01:39
OpenAPI for testing
{
"definitions": {
"org.apache.camel.v1.Integration": {
"description": "Integration is the Schema for the integrations API",
"properties": {
"spec": {
"description": "the desired Integration specification",
"properties": {
"template": {
"description": "Pod template customization",
@brianpursley
brianpursley / sorting-networks-chat-gpt.md
Created December 26, 2022 16:16
Trying to teach Chat GPT to generate sorting networks

Brian Pursley

A sorting network can be represented as a comma-separated list of comparators. A comparator, which compares and swaps two inputs to ensure they are in sorted order, can be represented using the string "a:b", where "a" is the index of the first input, and "b" is the index of the second input. Index numbering starts at 0. Using this notation, create a sorting network that is able to sort three inputs.


Chat GPT

Here is a sorting network that can sort three inputs:

"0:1, 1:2"

This sorting network consists of two comparators. The first comparator compares the first and second inputs, and swaps them if they are out of order. The second comparator compares the second and third inputs, and swaps them if they are out of order. This sorting network is able to sort the three inputs because it will ensure that the first input is the smallest, the second input is the second smallest, and the third input is the largest.

@brianpursley
brianpursley / quickperm.py
Last active December 18, 2022 07:38
This is a Python implementation of the QuickPerm algorithm described by Phillip Paul Fuchs at http://www.quickperm.org that generates all permutations of a list without using recursion
#!/usr/bin/env python
#
# This is a Python implementation of the QuickPerm algorithm described by Phillip Paul Fuchs at http://www.quickperm.org
# that generates all permutations of a list without using recursion.
#
a = ['a', 'b', 'c', 'd']
N = len(a)
@brianpursley
brianpursley / iBeacon-Windows10-C#-Program.cs
Created February 2, 2017 13:50
iBeacon Windows 10 Console Application using C#
using System;
using System.Linq;
using Windows.Devices.Bluetooth.Advertisement;
using Windows.Storage.Streams;
namespace BeaconExample
{
class Program
{
private class BeaconData
@brianpursley
brianpursley / ServiceCollectionExtensions.cs
Created October 11, 2022 19:04
Use different SignUpSignIn Azure AD B2C policies, depending on the hostname, allowing you to provide SSO for specific companies, without having to provide a button for each SSO integration on the main login page
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
namespace AuthTest.Extensions;
public static class ServiceCollectionExtensions
{
// USAGE:
//
// 1. Add the following line in Program.cs, after your call to AddMicrosoftIdentityWebApp:
// builder.Services.AddAlternateSignUpSignInPolicies(builder.Configuration.GetSection("AzureAdB2C"));