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 / DataGridViewExtensions.cs
Created October 3, 2024 09:29
Export unbound DataGridView to CSV file
internal record RowRecord(DataGridViewRow Row, string RowItem);
public static class DataGridViewExtensions
{
public static void ExportRows(this DataGridView sender, string fileName, string defaultNullValue = "(empty)")
{
File.WriteAllLines(fileName, sender.Rows.Cast<DataGridViewRow>()
.Where(row => !row.IsNewRow)
.Select(row => new RowRecord(
@karenpayneoregon
karenpayneoregon / Program.cs
Last active September 28, 2024 02:03
Ask question in console project
using Spectre.Console;
using static YourNamespace.Classes.SpectreConsoleHelpers;
namespace YourNamespace;
internal partial class Program
{
static void Main(string[] args)
{
@karenpayneoregon
karenpayneoregon / Customer.cs
Last active September 22, 2024 15:25
C# IFormattable example
public record Customer(int Id, string FirstName, string LastName, DateOnly BirthDay) : IFormattable
{
public int Id { get; set; } = Id;
public string FirstName { get; set; } = FirstName;
public string LastName { get; set; } = LastName;
public DateOnly BirthDay { get; set; } = BirthDay;
public string ToString(string format, IFormatProvider _)
=> format switch
{
"F" => $"{Id,-5}{FirstName} {LastName}",
@karenpayneoregon
karenpayneoregon / Customer.cs
Created September 21, 2024 11:45
IFormattable
public record Customer(int Id, string FirstName, string LastName, DateOnly BirthDay) : IFormattable
{
public int Id { get; set; } = Id;
public string FirstName { get; set; } = FirstName;
public string LastName { get; set; } = LastName;
public DateOnly BirthDay { get; set; } = BirthDay;
public string ToString(string format, IFormatProvider _)
=> format switch
{
"F" => $"{Id,-5}{FirstName} {LastName}",
var $debugHelper = $debugHelper || {};
$debugHelper = function () {
var href = "lib/debugger.css";
var addCss = function () {
if (styleStyleIsLoaded(href) === true) {
return;
}
const head = document.head;
const link = document.createElement("link");
link.type = "text/css";
@karenpayneoregon
karenpayneoregon / Helpers.cs
Last active September 13, 2024 20:39
Random
using System.Security.Cryptography;
public static class Helpers
{
public static string RandomNumberString(int length) =>
RandomNumberGenerator.GetString(
choices: new string('a'.To('z').Concat('0'.To('9')).ToArray()),
length: length
);
public static T[] RandomElements<T>(this T[] source, int count) =>
@karenpayneoregon
karenpayneoregon / keyboard.md
Last active September 12, 2024 14:39
Resharper Keys
public class BirthDay
{
private const string Template =
"""
Hey,
{name}'s birthday is on {dob}, which is in {month}.
Let's plan a party!
@karenpayneoregon
karenpayneoregon / IBaseEntity.cs
Created September 11, 2024 15:08
Read json asynchronous
public interface IBaseEntity
{
int Id { get; set; }
}
@karenpayneoregon
karenpayneoregon / ProcedureProperty.cs
Last active August 23, 2024 16:11
Get user stored procedure extended properties
public class ProcedureProperty
{
public string Schema { get; set; }
public string Name { get; set; }
public string Information { get; set; }
public string PropertyValue { get; set; }
public override string ToString() => $"{Information} = {PropertyValue}";
}