Skip to content

Instantly share code, notes, and snippets.

View BenMakesGames's full-sized avatar

Ben Hendel-Doying BenMakesGames

View GitHub Profile
public sealed class PaginatedResults<T>
{
public required IReadOnlyList<T> Results { get; init; }
public required int Page { get; init; }
public required int PageSize { get; init; }
public required int TotalCount { get; init; }
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
}
@BenMakesGames
BenMakesGames / BenchmarkDotNetProgram.cs
Created November 25, 2023 00:31
A simple Program.cs for selecting and running any of your BenchmarkDotNet benchmarks.
using System.Reflection;
using BenchmarkDotNet.Running;
// put all the benchmark classes into their own namespace, for easier discoverability. if you don't like this,
// change the next few lines to find your benchmarks using whatever logic you prefer.
const string BenchmarksNamespace = "YourBenchmarkNamespaceHere.Benchmarks";
var allBenchmarks = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(t => t is { Namespace: BenchmarksNamespace, IsClass: true })
@BenMakesGames
BenMakesGames / creating-an-app-service-with-key-vault-and-application-insights.md
Created November 15, 2023 16:30
A walkthrough for how to create a basic .NET Core 8 app for App Service w/ Key Vault & Application Insights

Creating an App Service w/ Key Vault & Application Insights

  1. Create your App Service, Key Vault, and Application Insights

    1. Copy the Key Vault's "Vault URI" for later
    2. Copy the Application Insights' "Connection String" for later
  2. In the App Service's "Identity", turn the "System assigned" "Status" to "On"

  3. In the App Service's "Configuration", create a "New application setting" with value "KeyVaultURI", and value of the "Vault URI" you copied in step 1

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
@BenMakesGames
BenMakesGames / .editorconfig
Created July 6, 2023 14:10
I like turning these .NET suggestions into ERRORS
[*.cs]
dotnet_diagnostic.IDE0005.severity = error # unnecessary using directives
dotnet_diagnostic.IDE0035.severity = error # unreachable code
dotnet_diagnostic.IDE0059.severity = error # unnecessary value assignment
dotnet_diagnostic.IDE0060.severity = error # unused parameter
@BenMakesGames
BenMakesGames / MoonPhase.cs
Created June 14, 2023 11:36
DateTimeOffset extension methods for computing the current phase of the moon
public static class DateTimeOffsetExtensions
{
private const double MoonCycleLength = 29.53058868;
public static MoonPhase ComputeMoonPhase(this DateTimeOffset dt)
{
return dt.GetMoonAge() switch
{
< 1.84566 => MoonPhase.NewMoon,
using System.DirectoryServices.AccountManagement;
using System.Runtime.InteropServices;
using System.Security.Principal;
using Microsoft.Win32.SafeHandles;
namespace YourNamespaceHere;
// Notes:
// * This class is a service. Hopefully you've got a DI/IoC container you can register it with. (For a desktop application,
// it'd probably make the most sense as a singleton.)
# by Ben Hendel-Doying
# Buy Me a Coffee? :D https://ko-fi.com/A0A12KQ16
#
# the following scripts are for RPG Maker VX Ace
#
# they allow for the automatic movement of the party between maps simply by walking
# to the edge, without the need to create ANY events on any map.
#
# BUT: it's required that all maps be only one screen in size. (it should be easy
# to remove this limitation, though I have not tried it.)
=begin
with this script, pressing ESC takes you directly to the "Quit" dialog,
AND adds two new options to this dialog: Save, and Load.
useful for games without inventory or party-management, where having the
normal menu is inappropriate.
Buy Me a Coffee? :D https://ko-fi.com/A0A12KQ16
=end
class Scene_Map
=begin
Can be used to change where faces are displayed in message boxes: the left, or
the right!
To use, place a "Script" in your event BEFORE the "Message". The script should
contain either:
Window_Message.FaceOnLeft
or: