Skip to content

Instantly share code, notes, and snippets.

View karenpayneoregon's full-sized avatar
🎯
Focusing

Karen Payne karenpayneoregon

🎯
Focusing
View GitHub Profile
@karenpayneoregon
karenpayneoregon / Demo.cs
Last active February 26, 2025 22:39
C# 11 list pattern
using System.Text.Json;
namespace TODO;
class Samples
{
public static void IntegerListMatch()
{
List<List<int>> list =
@karenpayneoregon
karenpayneoregon / accordionUtilities1.js
Created February 24, 2025 22:08
Toggle accordion item by id
function expandToolSectionAccordionItem() {
let collapseElement = document.getElementById('collapseTools');
if (collapseElement) {
let bsCollapse = new bootstrap.Collapse(collapseElement, {
toggle: true
});
}
}
@karenpayneoregon
karenpayneoregon / accordionUtilities.js
Created February 24, 2025 17:47
Provides JavaScript helper methods to expand and collapse all items in a Bootstrap 5.3 accordion
function expandAll() {
document.querySelectorAll('.accordion-collapse').forEach(item => {
let bsCollapse = new bootstrap.Collapse(item, { toggle: false });
bsCollapse.show();
});
}
function collapseAll() {
document.querySelectorAll('.accordion-collapse').forEach(item => {
let bsCollapse = new bootstrap.Collapse(item, { toggle: false });
@karenpayneoregon
karenpayneoregon / Helpers.cs
Created February 14, 2025 14:13
For Twitter
string DefaultInterpolatedStringHandler()
{
var title = "Mr.";
var firstName = "John";
var middleName = "Q.";
var lastName = "Doe";
DefaultInterpolatedStringHandler stringHandler = new(50, 4);
stringHandler.AppendLiteral("Hello ");
stringHandler.AppendFormatted(title);
stringHandler.AppendLiteral(" ");
@karenpayneoregon
karenpayneoregon / demo.html
Last active February 12, 2025 22:53
Scrollable modal
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Bootstrap scrollable modal</title>
<link href="Lib/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />
<!-- REQUIRED -->
<script src="Lib/bootstrap/js/bootstrap.bundle.min.js"></script>
@karenpayneoregon
karenpayneoregon / ExceptionHelpers.cs
Last active February 10, 2025 22:38
Spectre.Console custom colored runtime exceptions
using Spectre.Console;
namespace SpectreExceptionsLibrary;
/// <summary>
/// Custom setting for presenting runtime exceptions using AnsiConsole.WriteException.
///
/// The idea here is to present different types of exceptions with different colors while
/// one would be for all exceptions and the other(s) for specific exception types.
/// </summary>
@karenpayneoregon
karenpayneoregon / JsonHelpers.js
Created February 1, 2025 12:09
Example for checking if sections exists in appsettings.json
using System.Text.Json;
namespace SomeLibrary.Classes;
/// <summary>
/// Provides utility methods for validating the presence of specific sections
/// in the "appsettings.json" configuration file.
/// </summary>
/// <remarks>
/// This class is designed to assist in ensuring that critical configuration
/// sections, such as "EntityConfiguration" and "ConnectionStrings", are
@karenpayneoregon
karenpayneoregon / Extensions.cs
Last active January 24, 2025 14:18
JoinWithLastSeparator
public static class Extensions
{
/// <summary>
/// Joins the elements of the specified <see cref="IEnumerable{T}"/> into a single string,
/// separating them with the specified separator, and appending a specified token before the last element.
/// </summary>
/// <typeparam name="T">The type of the elements in the collection.</typeparam>
/// <param name="sender">The collection of elements to join.</param>
/// <param name="separator">
/// The string to use as a separator between elements. Defaults to ", " if not specified.
@karenpayneoregon
karenpayneoregon / DataOperations.cs
Created January 15, 2025 00:43
ChatGPT generated method
internal class DataOperations
{
public static IEnumerable<Customer> GetCustomerDetails()
{
using IDbConnection connection = new SqlConnection(DataConnections.Instance.MainConnection);
var customerDictionary = new Dictionary<int, Customer>();
var customers = connection.Query<Customer, Contact, Country, ContactType, Customer>(
SqlStatements.CustomerWithContacts(),
@karenpayneoregon
karenpayneoregon / GenericINumberExtensions.cs
Last active January 3, 2025 15:15
Array/List merge - ChatGPT
using System.Numerics;
namespace Extensions;
public static class GenericINumberExtensions
{
public static T[] Merge<T>(this T[] container, T[] T1) where T : INumber<T>
=> [.. container, .. T1];
public static T[] Merge<T>(this T[] container, T[] T1, T[] T2) where T : INumber<T>