Skip to content

Instantly share code, notes, and snippets.

View ZacharyPatten's full-sized avatar
👊
It's Morphin' Time

ZacharyPatten

👊
It's Morphin' Time
  • Kansas, United States
  • 09:24 (UTC -05:00)
View GitHub Profile
using System;
class Program
{
static void Main()
{
int[] array = ConsoleHelper.GetInputArray<int>(length: 5, tryParse: int.TryParse);
//DateTime[] array = ConsoleHelper.GetInputArray<DateTime>(length: 5, tryParse: DateTime.TryParse);
foreach (var i in array)
@ZacharyPatten
ZacharyPatten / readme.md
Last active November 2, 2021 18:29
C# Analyzer Notes

These are a list of analyzers i want to make in C#

  • error on using Convert.ToXxx
    • code fix will change to a casting operator or Xxx.TryParse
  • warning on hard coding path seperators
    • code fix will change to Path.DirectorySeparatorChar or Path.Combine(...)
  • warning on identifier conflicts
    • locals conflicting with fields/properties
    • lambda parameters conflicting with locals/fields/properties
  • code fix will add numbers onto end of identifiers to make sure they are unique
@ZacharyPatten
ZacharyPatten / console-hex-example.cs
Created September 24, 2021 19:10
an example of a console hex for discord user
using System;
string[,] grid = new string[4, 4];
grid[3, 3] = "dog";
grid[0, 2] = "cat";
grid[2, 0] = "mom";
grid[0, 0] = "dad";
RenderGrid();
@ZacharyPatten
ZacharyPatten / readme.md
Last active February 3, 2023 15:58
GitHub Repository Checklist (C#)

GitHub Repository Checklist (C#)

Have a repository on GitHub? Planning on making a repository on GitHub? This checklist is intended to introduce you to various features that may help you make the most of your GitHub repository with specific recommendations for C# repositories.

Checklist

These are only suggestions.
They may not be appropriate for all repositories.
They are in no particular order.
Click each item to expand for more information.

@ZacharyPatten
ZacharyPatten / range.md
Last active July 3, 2021 14:40
"range" syntax in C#

Usage Example

using System;
using static Statics;

static class Program
{
	static void Main()
	{
System.Console.WriteLine("Hello World!");
#pragma warning disable IDE0060 // Remove unused parameter
#pragma warning disable CA1822 // Mark members as static
#region Analyzer #01: not all parameters accounted for
namespace Analyzer1_Example1
{
// There is no warning that "B" is missing XML docs for "T2".
using System;
using System.Collections.Generic;
using System.Linq;
using Towel;
class Program
{
public enum Location
{
Rivendell,
@ZacharyPatten
ZacharyPatten / CustomRangeSyntax.cs
Last active June 10, 2021 13:37
Custome Range Syntax in C# for fun...
using System;
using System.Collections.Generic;
using static Statics;
class Program
{
static void Main()
{
foreach (int i in -6 -to- -4)
{
@ZacharyPatten
ZacharyPatten / CombineRanges.cs
Last active May 24, 2021 20:12
Helper method for combining ranges.
using System;
using System.Collections.Generic;
using Towel.DataStructures;
using static Towel.Statics;
namespace ConsoleApp9001
{
class Program
{
static void Main(string[] args)
@ZacharyPatten
ZacharyPatten / RandomWithExclusions.md
Created January 31, 2021 05:54
Random Generation (with efficient exclusions)

Note: code examples are in C#, but the theory should be applicable to most programing languages

"How do I generate random numbers except for certain values?" - This is a relatively common question that I aim to answer with this post. I wrote some extension methods for the topic that look like this:

Random random = new();

int[] randomNumbers = random.Next(
    count: 5,
 minValue: 0,