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 / 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>
@karenpayneoregon
karenpayneoregon / Params.cs
Last active January 1, 2025 04:59
C# 13 parms
using System.Diagnostics;
using NewStuffApp.Models;
namespace NewStuffApp.Classes;
/// <summary>
/// Provides a set of static methods for iterating over collections of various types
/// (e.g., strings, integers, and Person) and performing operations on them.
/// </summary>
internal class Params
@karenpayneoregon
karenpayneoregon / Helpers.cs
Created December 28, 2024 23:46
Interface helpers
public static class Helpers
{
/// <summary>
/// Retrieves the names of all entities that implement a specified interface type.
/// </summary>
/// <typeparam name="T">
/// The interface type to search for. Must be a class type and an interface.
/// </typeparam>
@karenpayneoregon
karenpayneoregon / Example.cs
Last active December 17, 2024 11:01
GroupBy multiple columns with tuples
var members = MemberOperations.MembersList();
List<GroupedMember> groups = MemberOperations.GroupedMembers(members);
foreach (GroupedMember groupMember in groups)
{
Console.WriteLine(groupMember);
foreach (Member member in groupMember.Lists)
{
Console.WriteLine($"\t{member.Id,-3}{member.Active}");
}
@karenpayneoregon
karenpayneoregon / christmas.sql
Created December 12, 2024 02:45
T-Server Christmas
USE tempdb
GO
-- Prepare the scene
CREATE TABLE #ChristmasScene
(
@karenpayneoregon
karenpayneoregon / New.sql
Created December 10, 2024 18:50
Get row count for each table in a database for SQL-Server
SELECT t.name AS TableName,
p.rows AS [RowCount]
FROM sys.tables t
INNER JOIN sys.partitions p
ON t.object_id = p.object_id
WHERE p.index_id IN ( 0, 1 )
ORDER BY p.rows DESC,
t.name;
@karenpayneoregon
karenpayneoregon / from-now.js
Created December 6, 2024 19:55
JavaScript now-now
/*
* var pastDate = new Date('2014-10-01T02:30');
* var message = fromNow(pastDate);
* //=> '2 days ago'
*
* @param {Date} Native JavaScript Date object
* @return {string}
*/
function fromNow(date) {
var seconds = Math.floor((new Date() - date) / 1000);
@karenpayneoregon
karenpayneoregon / Program.cs
Created November 28, 2024 11:46
NET 9 [GeneratedRegex] on properties
using System.Text.RegularExpressions;
namespace Net9Features;
internal class Program
{
static void Main(string[] args)
{
const string sentence = "a test to see if";
@karenpayneoregon
karenpayneoregon / Demo.cs
Last active November 19, 2024 21:04
C# OverloadResolutionPriority Attribute
public partial class Demo
{
[OverloadResolutionPriority(2)]
public static void DisplayInvoice(string invoice )
{
Console.WriteLine($"invoice: {NextValue(invoice)}");
}
[OverloadResolutionPriority(-1)]
public static void DisplayInvoice(string invoice, int count = 3)