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 / SqlBulkInsert.cs
Created January 25, 2023 19:35
Inserting as fast as I can.
using System.Data;
using System.Data.SqlClient;
internal class Program
{
static int threads = 0;
static int records = 0;
static int batch = 10_000;
static DateTime started = DateTime.Now;
@JerryNixon
JerryNixon / json.sql
Last active December 14, 2022 01:09
SQL JSON WORK
SET NOCOUNT ON
DECLARE @json NVARCHAR(MAX) =
'{
"reading": {
"source": "A01",
"values": [
{ "date": "2022-12-12", "value": 123.456 }
, { "date": "2022-12-13", "value": 234.567 }
]
@JerryNixon
JerryNixon / FileReadShowdown.cs
Last active December 7, 2022 17:02
Evaluate the performance of DynamicObject versus normal programming.
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Xml.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
@JerryNixon
JerryNixon / part-view.ipynb
Created November 10, 2022 21:58
Creating a partitioned view in SQL Server that auto-partitions INSERT & UPDATE statements
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JerryNixon
JerryNixon / ssn_sex_generator.sql
Last active September 26, 2022 19:56
Generate Social Security Numbers in TSQL
DROP TABLE IF EXISTS #SSN
CREATE TABLE #SSN (
ID INT IDENTITY(1, 1) PRIMARY KEY
, SSN VARCHAR(11) MASKED WITH (FUNCTION = 'partial(0, "XXX-XX-", 4)')
, SEX BIT
, BIRTH INT
)
GO
@JerryNixon
JerryNixon / EntityFramework.cs
Created September 20, 2022 18:52
Generic Repository using Entity Framework
using Library.Models;
using Library.EF;
namespace Abstractions
{
public interface IKeyedModel
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
}
@JerryNixon
JerryNixon / generate.sql
Last active September 10, 2022 01:41
Generate an arbitrary range in T-SQL UDF.
DBCC DROPCLEANBUFFERS;
CHECKPOINT;
DBCC FREEPROCCACHE WITH no_infomsgs;
GO
CREATE OR ALTER FUNCTION Range (@start BIGINT, @end BIGINT)
RETURNS @table TABLE (Id BIGINT) AS
BEGIN
-- Jerry Nixon
@JerryNixon
JerryNixon / paging.sql
Created August 16, 2022 16:04
Paging SQL Results
BEGIN TRANSACTION
CREATE TABLE x
(
Id INT NOT NULL PRIMARY KEY
, Name VARCHAR(150) NOT NULL
);
WITH generator (Id, Name) AS
@JerryNixon
JerryNixon / cat.cs
Created August 4, 2022 17:32
A simple console sample
Console.Clear();
Console.CursorVisible = false;
var cat = new Cat();
while (true)
{
cat.Erase();
if (Console.KeyAvailable)
@JerryNixon
JerryNixon / format_int.cs
Created July 19, 2022 04:29
Padding zeros with custom numeric format strings in C#
var x = 4;
var y = x.ToString(); // y equals "4"
var x = 4;
var y = x.ToString("##"); // y equals "4"
var x = 4;
var y = x.ToString("###"); // y equals "4"
var x = 4;