Skip to content

Instantly share code, notes, and snippets.

@kspearrin
kspearrin / SecureRandomString.sql
Last active March 2, 2019 04:42
T-SQL Cryptographically Secure Random String Function using CRYPT_GEN_RANDOM()
-- Helper view so that you can call CRYPT_GEN_RANDOM in your function
CREATE VIEW [dbo].[SecureRandomBytes]
AS
SELECT [RandBytes] = CRYPT_GEN_RANDOM(2)
GO
-- Function for generating secure random string
CREATE FUNCTION [dbo].[SecureRandomString](@sLength tinyint)
RETURNS varchar(200)
AS
@kspearrin
kspearrin / gist:9db6900ef9483fcf58c88b92410758ba
Created March 1, 2018 18:04
Clear Azure SQL Procedure Cache
-- ref: https://dba.stackexchange.com/a/159886
-- run this script against a user database, not master
-- count number of plans currently in cache
select count(*) from sys.dm_exec_cached_plans;
-- Executing this statement will clear the procedure cache in the current database, which means that all queries will have to recompile.
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
-- count number of plans in cache now, after they were cleared from cache
@kspearrin
kspearrin / C:\Program Files\Git\etc\profile.d
Created March 1, 2018 16:36
A Better GitBash Profile Config
if test -f /etc/profile.d/git-sdk.sh
then
TITLEPREFIX=SDK-${MSYSTEM#MINGW}
else
TITLEPREFIX=$MSYSTEM
fi
if test -f ~/.config/git/git-prompt.sh
then
. ~/.config/git/git-prompt.sh
@kspearrin
kspearrin / IEnumerableCanBeInefficient.cs
Last active July 26, 2016 20:58
CAREFUL! IEnumerable can be inefficient and slow.
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
public class Program
{
// CAREFUL! IEnumerable can be inefficient and slow.
public static void Main()
{