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 / HealthCheck_RestApi.cs
Created February 25, 2025 20:53
Create a health check for REST web api
using System.Text.Json;
using Health;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using System.Diagnostics;
internal class Program
{
private static void Main(string[] args)
{
@JerryNixon
JerryNixon / create.sql
Last active January 9, 2025 21:19
TSQL to read & write SQL extended property: MS_Description
CREATE TABLE dbo.STATE (
ID INT PRIMARY KEY,
Name NVARCHAR(50),
Description NVARCHAR(255)
);
EXEC sp_addextendedproperty
@name = N'MS_Description',
@value = N'Table holding state information',
@level0type = N'user', @level0name = dbo,
@JerryNixon
JerryNixon / program.cs
Last active January 5, 2025 06:29
Console Keyboard
using System.Drawing;
public class Program
{
static Program()
{
Console.Clear();
Console.CursorVisible = false;
}
@JerryNixon
JerryNixon / demo.ipynb
Created December 12, 2024 21:13
.NET Notebook connection to local SQL container rinning DAB Star Trek
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JerryNixon
JerryNixon / GetTicTacToeWinner.sql
Created October 3, 2024 02:59
Calculate Tic Tac Toe winner in SQL
CREATE FUNCTION dbo.GetTicTacToeWinner(
@Cell1 CHAR(1),
@Cell2 CHAR(1),
@Cell3 CHAR(1),
@Cell4 CHAR(1),
@Cell5 CHAR(1),
@Cell6 CHAR(1),
@Cell7 CHAR(1),
@Cell8 CHAR(1),
@Cell9 CHAR(1)
@JerryNixon
JerryNixon / Metric-Duration.cs
Last active September 25, 2024 20:12
Open Telemetry 001
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using System.Diagnostics;
using System.Diagnostics.Metrics;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<EndpointMeters>();
builder.Services.AddOpenTelemetry()
.WithMetrics(options =>
@JerryNixon
JerryNixon / SqlConnectionStringValidator.cs
Created June 7, 2024 16:56
Validate a SQL Connection String
public static class SqlConnectionStringValidator
{
public enum ErrorReason { None, ServerNetwork, Database, UserPassword, Other }
public static bool TryValidateConnectionString(string server, string database, string user, string password, out string connectionString, out ErrorReason reason, out string message)
{
connectionString = default;
if (!TryValidateValues(server, database, user, password, out reason, out message))
{
DECLARE @JsonOutput NVARCHAR(MAX);
WITH TablesToExclude AS
(
SELECT fk.parent_object_id AS object_id
FROM sys.foreign_keys AS fk
GROUP BY fk.parent_object_id
HAVING COUNT(fk.object_id) = 2
UNION
@JerryNixon
JerryNixon / ReturningJson.sql
Last active April 10, 2024 19:57
Sending and returning JSON to accommodate complex types.
BEGIN TRANSACTION
GO
CREATE PROCEDURE FetchObjectsWithMetadata
@SortBy NVARCHAR(50),
@PageSize INT = 10,
@PageNumber INT,
@NameFilter NVARCHAR(256)
AS
BEGIN
@JerryNixon
JerryNixon / foreign_key.sql
Created February 29, 2024 17:01
Demonstrating a FK does not require a PK in SQL
begin transaction;
create table Location
(
Id int primary key,
City varchar(255),
[State] char(2),
Zip char(5) unique,
);