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 / styles.css
Created May 9, 2025 22:11
Provides styles for HTML placeholder
input[type="text"],
input[type="email"],
input[type="password"] {
all: unset;
box-sizing: border-box;
display: block;
width: 100%;
max-width: 400px;
padding: 10px 12px;
font-size: 1rem;
@karenpayneoregon
karenpayneoregon / Program.cs
Last active April 18, 2025 15:48
C# Get date time with hour and minutes in 24h format
namespace InputsDemo;
internal partial class Program
{
static void Main(string[] args)
{
var value = Prompts.GetDate();
Console.WriteLine(value.Year == 1 ? "Cancelled" : $"Selected date: {value:MM/dd/yyyy HH:mm}");
Console.ReadLine();
}
public class CatalogInfo
{
public string ProductDisplayVersion { get; set; }
}
@karenpayneoregon
karenpayneoregon / ProjectUpdater.cs
Created April 7, 2025 10:20
Update Framework in project file
using System.Xml.Linq;
namespace UpdateFrameworkApp.Classes;
public class ProjectUpdater
{
public static string UpdateTargetFramework(string csprojPath, string oldFramework = "net7.0", string newFramework = "net9.0")
{
if (!File.Exists(csprojPath))
{
@karenpayneoregon
karenpayneoregon / Sample.sql
Last active March 29, 2025 08:24
Example to get column details from a SQL-Server database table
DECLARE @TableName AS NVARCHAR(MAX) = 'Birthdays'
SELECT
X.COLUMN_NAME AS ColumnName,
X.ORDINAL_POSITION AS Position,
X.TABLE_CATALOG AS Catalog,
X.TABLE_SCHEMA AS TableSchema,
X.COLUMN_DEFAULT AS ColumnDefault,
X.DATA_TYPE AS DataType,
CASE
WHEN KCU.COLUMN_NAME IS NOT NULL THEN CAST(1 AS BIT)
@karenpayneoregon
karenpayneoregon / DapperOperations.cs
Last active March 27, 2025 23:09
GitHub Copilot statements to stored procedures
// create a method in DapperOperations.cs named GetImageById using Dapper
public class DapperOperations
{
private readonly string _connectionString;
public DapperOperations(string connectionString)
{
_connectionString = connectionString;
}
@karenpayneoregon
karenpayneoregon / Conventional.cs
Last active March 18, 2025 18:50
NodaTime difference between two dates raw
public static string CalculateTimeDifference(DateTime futureDate)
{
if (futureDate <= DateTime.Now)
{
return "The provided date must be in the future.";
}
DateTime now = DateTime.Now;
// Calculate total months difference
@karenpayneoregon
karenpayneoregon / Person.cs
Created March 16, 2025 16:26
Record PrintMembers custom
public record Person(string FirstName, string LastName, DateOnly BirthDate, string[] PhoneNumbers)
{
protected virtual bool PrintMembers(StringBuilder sb)
{
sb.Append($"FirstName = {FirstName}, LastName = {LastName}, Birth = {BirthDate:MM/dd/yyyy}");
if (!(PhoneNumbers?.Length > 0)) return true;
sb.Append(", PhoneNumbers: ");
sb.Append(string.Join(", ", PhoneNumbers));
@karenpayneoregon
karenpayneoregon / DateTimeHelpers.cs
Last active March 16, 2025 19:12
How AI can assist a developer
public static class DateTimeHelpers
{
/// <summary>
/// Generates a list of dates representing the next week's dates starting from the upcoming Sunday.
/// </summary>
/// <returns>A list of <see cref="DateOnly"/> objects representing the dates of the next week.</returns>
public static List<DateOnly> NextWeeksDates()
{
var start = DateTime.Now;
var nextSunday = DateOnly.FromDateTime(start).Next(DayOfWeek.Sunday);
@karenpayneoregon
karenpayneoregon / FixedDecimalJsonConverter.cs
Created March 13, 2025 21:34
Serialize decimals to 2 places
/// <summary>
/// Provides a custom JSON converter for <see cref="decimal"/> values, ensuring consistent formatting and parsing.
/// </summary>
/// <remarks>
/// This converter reads <see cref="decimal"/> values from JSON as strings and parses them using
/// <see cref="CultureInfo.InvariantCulture"/>. When writing, it formats <see cref="decimal"/> values
/// as strings with two decimal places using the same culture.
/// </remarks>
public class FixedDecimalJsonConverter : JsonConverter<decimal>
{