Skip to content

Instantly share code, notes, and snippets.

View GrahamTheCoder's full-sized avatar

Graham GrahamTheCoder

View GitHub Profile
@GrahamTheCoder
GrahamTheCoder / snowflake_uppercase_all.sql
Last active July 31, 2025 15:01
Set all objects to upper case names to help convert to case insensitive Snowflake DB
-- Generates a script to rename all objects to upper case in snowflake
EXECUTE IMMEDIATE $$
DECLARE
object_types ARRAY;
object_type STRING;
alter_type STRING;
singular_map OBJECT;
max_count INTEGER;
alter_statements ARRAY := ['ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = FALSE;'];
// Quick sketch of how the zustand api could be used with the full power of redux behind for when things get more complex
import { createSlice } from '@reduxjs/toolkit';
export function createZustandishSlice(name, creator) {
const initialState = {};
const creatorActions = {};
// Discover the store's shape by separating initial state from action functions.
const storeShape = creator(() => { }, () => { });
@GrahamTheCoder
GrahamTheCoder / TemporalTableAttribute.cs
Created May 6, 2025 11:48
Temporal table attribute for SQL Server EF Core
using System;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed record TemporalTableAttribute(string HistoryTableName, string PeriodStartColumnName, string PeriodEndColumnName) : Attribute;
public class YourDbContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
@GrahamTheCoder
GrahamTheCoder / DictionaryExtensions.cs
Created September 26, 2019 09:48
DictionaryExtensions
public static class DictionaryExtensions
{
public static TValue Get<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue))
=> dict.TryGetValue(key, out var actualValue) ? actualValue : defaultValue;
public static TValue Get<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue))
=> dict.TryGetValue(key, out var actualValue) ? actualValue : defaultValue;
public static TValue Get<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue))
@GrahamTheCoder
GrahamTheCoder / GetNewAndEditedLineRangesFromMaster.ps1
Created July 1, 2016 17:48
Gets a list of line ranges (index and length if more than 1) for files changed since diverging from origin master
function Get-LinesChanged() {
$diffFromCommonBase = git diff origin/master...HEAD --unified=0 --dst-prefix=""
$linesByFile = @{}
$currentLines = New-Object System.Collections.ArrayList
foreach ($diffLine in $diffFromCommonBase ) {
if ($diffLine.StartsWith("+++")) {
#e.g. "+++ Path/to/file.cs" -> "Path/to/file.cs"
$currentFile = $diffLine.Substring(4)
$currentLines = $linesByFile[$currentFile] = New-Object System.Collections.ArrayList