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 / 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)
@karenpayneoregon
karenpayneoregon / readme.md
Created November 18, 2024 12:05
How to suppress System.Text.Json Severity high

Currently targeting NET Core project using System.Text.Json 7.0.0 as a Transitive Package will be flagged as high Severity using

dotnet list package --include-transitive --vulnerable

To circumvent, add the following to the project file.

@karenpayneoregon
karenpayneoregon / EntityHelpers.cs
Created November 3, 2024 13:46
EF Core does database exists method
using yournamespace.Data;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
namespace yournamespace.Classes;
internal class EntityHelpers
{
public static bool DatabaseExists()
{
using var context = new Context();
@karenpayneoregon
karenpayneoregon / Demo.cs
Created November 2, 2024 00:43
int to string JsonConverter
List<Item> items =
[
new() { Id = 1,Name = "100"},
new() { Id = 2,Name = "100"},
new() { Id = 3,Name = "100" }
];
string json = JsonSerializer.Serialize(items, Options);
@karenpayneoregon
karenpayneoregon / Extensions.cs
Created October 30, 2024 15:22
Simple paging
internal static partial class Extensions
{
/// <summary>
/// Paginates the elements of an <see cref="IQueryable{TSource}"/> based on the specified page number and page size.
/// </summary>
/// <typeparam name="TSource">The type of the elements of the source.</typeparam>
/// <param name="source">The source <see cref="IQueryable{TSource}"/> to paginate.</param>
/// <param name="page">The page number to retrieve. Must be greater than or equal to 1.</param>
/// <param name="pageSize">The number of elements per page. Must be greater than or equal to 1.</param>