Skip to content

Instantly share code, notes, and snippets.

View JerryNixon's full-sized avatar
🤔
Trying to make a living.

Jerry Nixon JerryNixon

🤔
Trying to make a living.
View GitHub Profile
@JerryNixon
JerryNixon / UnitTest1.cs
Last active August 1, 2024 21:15
Database Unit Test
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using System.Data;
namespace Database.TestRunner;
public class SqlDatabase : IDisposable, IAsyncDisposable
{
private static string ReadConnectionString()
@JerryNixon
JerryNixon / ApiApp_Program.cs
Last active January 18, 2024 22:13
Call an ASP.NET Minimal API from a Blazor WebAssembly App
// Change this to your project namespace
using Sample.Shared;
var CorsPolicyName = "MyCorsApiPolicy";
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(options =>
{
options.AddPolicy(name: CorsPolicyName, policy =>
{
@JerryNixon
JerryNixon / ConnectionString.sql
Created July 20, 2023 15:33
Build a connection string
DROP FUNCTION IF EXISTS ConnectionString;
GO
CREATE FUNCTION ConnectionString(@includeProperties bit = 1)
RETURNS nvarchar(1000)
AS
BEGIN
-- Retrieve server name
DECLARE @hostName nvarchar(128);
SET @hostName = CAST(host_name() AS nvarchar(128));
@JerryNixon
JerryNixon / Benchmark.cs
Created July 10, 2023 21:35
Testing parameter types: IEnumerable<string> versus List<string>
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
_ = BenchmarkRunner.Run<TestParamType>();
[MemoryDiagnoser]
public class TestParamType
{
private List<string> list = new();
@JerryNixon
JerryNixon / ProcedureInfo.sql
Last active May 19, 2023 18:12
Get Parameters and Columns of Stored Procedure in SQL Server
;WITH types AS
(
SELECT system_type_id,
CASE
WHEN system_type_id IN (34, 35, 99, 173, 165, 167, 175, 231, 239) THEN 'string'
WHEN system_type_id IN (36, 189) THEN 'Guid'
WHEN system_type_id IN (48) THEN 'byte'
WHEN system_type_id IN (52) THEN 'short'
WHEN system_type_id IN (56) THEN 'int'
WHEN system_type_id IN (58, 61) THEN 'DateTime'
@JerryNixon
JerryNixon / SqlUtilities.GetDotnetType.cs
Last active April 24, 2023 17:22
Convert SQL Type to .NET Type
using Microsoft.SqlServer.TransactSql.ScriptDom;
public static class SqlUtilities
{
public static string GetDotnetType(this SqlDataTypeOption sqlDataType, bool isNullable = false)
{
if (IsUnsupportedType())
{
return string.Empty;
}
@JerryNixon
JerryNixon / ClassSample.cs
Created February 28, 2023 19:01
Interface, Base, Chained Constructor, Properties, Init, Events, Methods, et al.
public interface IAccount
{
int Balance { get; }
void Deposit(int amount);
void Withdraw(int amount);
event EventHandler<int> BalanceChanged;
event EventHandler<int> Overdraft;
}
@JerryNixon
JerryNixon / InMemTable.sql
Created February 22, 2023 20:31
Create Azure SQL DB In-Memory Table
-- configure recommended DB option
ALTER DATABASE CURRENT SET MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT=ON;
GO
-- validate tier
IF (DatabasePropertyEx(DB_Name(), 'IsXTPSupported') = 0)
BEGIN
PRINT 'This database does not support in-mem database.'
@JerryNixon
JerryNixon / Menu.cs
Created February 9, 2023 17:31
Week 04 Coding in Class Snapshot
public static class Menu
{
/// <summary>
/// Displays a menu of options on the console and waits for the user to make a selection.
/// </summary>
/// <param name="x">The x-coordinate of the top-left corner of the menu box.</param>
/// <param name="y">The y-coordinate of the top-left corner of the menu box.</param>
/// <param name="items">The options to display in the menu.</param>
/// <returns>The selected option as a string.</returns>
public static void Draw(int x, int y, string current, string[] items)
@JerryNixon
JerryNixon / ColumnstoreParitioning.sql
Created February 3, 2023 01:21
Columnstore & Horizontal Partitioning SQL Server Tables
CREATE PARTITION FUNCTION year_partition_function (varchar(4)) AS
RANGE FOR VALUES ('2019', '2020', '2021')
GO
CREATE PARTITION SCHEME year_partition_scheme AS
PARTITION year_partition_function ALL TO ([PRIMARY])
GO
CREATE TABLE users
(