Skip to content

Instantly share code, notes, and snippets.

View NickCraver's full-sized avatar
:shipit:
Shipping

Nick Craver NickCraver

:shipit:
Shipping
View GitHub Profile
@NickCraver
NickCraver / DmpAnalysis.linq
Last active May 1, 2024 21:09
DMP Analysis in LinqPad
<Query Kind="Program">
<NuGetReference Prerelease="true">Microsoft.Diagnostics.Runtime</NuGetReference>
<Namespace>Microsoft.Diagnostics.Runtime</Namespace>
<Namespace>System</Namespace>
<Namespace>System.IO</Namespace>
<Namespace>System.Linq</Namespace>
<Namespace>System.Text</Namespace>
<Namespace>Microsoft.Diagnostics.Runtime.Utilities</Namespace>
</Query>
@NickCraver
NickCraver / GitHubTrendingWeekly.ps1
Last active January 4, 2021 09:59
A weekly task that pops up https://github.com/trending in Chrome to find interesting OSS projects.
Register-ScheduledTask `
-Action (New-ScheduledTaskAction `
-Execute ((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe")."(default)") `
-Argument 'https://github.com/trending') `
-Trigger (New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday -At 3am) `
-TaskName "GitHub Trending" `
-Description "Weekly check of GitHub trending repos."
@NickCraver
NickCraver / Examples.cs
Last active April 16, 2019 01:56
SQL Exception handy helpers
// Here are some example usages for unimportant jobs we have where crap happens occasionally:
/// <summary>
/// intended for database commands that might deadlock, but are just "nice to haves"; we don't care if they deadlock every now and then
/// and we DON'T want them to block execution of the rest of /daily or /hourly! this returns -1 if deadlocked, otherwise, returns
/// the # of rows that the SQL command affected
/// </summary>
private int ExecuteIgnoreDeadlocks(string sql, object param = null, bool logDeadlock = false)
{
try
@NickCraver
NickCraver / Benchmark.cs
Last active June 9, 2016 12:27
TimeSpan.FromSeconds() benchmark
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnostics.Windows;
using BenchmarkDotNet.Running;
namespace Benchmarks
{
class Program
{
@NickCraver
NickCraver / QueryPlan.xml
Created June 5, 2016 12:53
SQL 2016 RTM AG Regression Query Plan
<ShowPlanXML xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan" Version="1.5" Build="13.0.1601.5">
<BatchSequence>
<Batch>
<Statements>
<StmtSimple StatementText="CREATE function sys.fn_hadr_is_same_replica(&#xD;&#xA;&#x9;@lag_id uniqueidentifier,&#xD;&#xA; @lag_replica_id uniqueidentifier,&#xD;&#xA;&#x9;@ag_replica_id uniqueidentifier)&#xD;&#xA;returns bit&#xD;&#xA;as&#xD;&#xA;begin&#xD;&#xA; declare @ag_id uniqueidentifier&#xD;&#xA;&#x9; declare @local_replica_id uniqueidentifier&#xD;&#xA;&#x9; declare @ret bit&#xD;&#xA;&#x9; &#xD;&#xA; SELECT @ag_id = group_id &#xD;&#xA; FROM sys.fn_hadr_distributed_ag_replica(@lag_id, @lag_replica_id)" StatementId="1" StatementCompId="3" StatementType="SELECT" RetrievedFromCache="true" StatementSubTreeCost="1.157e-006" StatementEstRows="1" SecurityPolicyApplied="false" StatementOptmLevel="FULL" QueryHash="0x48E1F82013EEA15A" QueryPlanHash="0x3443401473380A77" StatementOptmEarlyAbortReason="GoodEnoughPlanF
@NickCraver
NickCraver / Int32ToBase64.cs
Created May 14, 2016 11:52
Base64 Header Example
void Main()
{
"99999999".Dump();
Int32ToBase64(99999999).Dump();
}
private static readonly char[] EqualsChar = { '=' };
private static string Int32ToBase64(int i)
{
try
@NickCraver
NickCraver / TeamCity-Dev-Build-Log.txt
Created April 30, 2016 20:02
Stack Overflow Build Log Examples
Build 'Stack Exchange Network :: New York :: SENetwork - Dev' #21007
Started 'Wed Apr 27 23:54:04 UTC 2016' on 'NY-WEB05' by 'Git'
Finished 'Wed Apr 27 23:56:21 UTC 2016' with status 'NORMAL Success'
TeamCity URL https://build/viewLog.html?buildId=477326&buildTypeId=StackExchangeNetwork_NewYork_SENetworkDev
TeamCity server version is 9.1.5 (build 37377)
[23:54:03]i: TeamCity server version is 9.1.5 (build 37377)
[23:54:03]W: bt4 (2m:17s)
[23:54:03] : projectId:project55 projectExternalId:StackExchangeNetwork_NewYork buildTypeId:bt4 buildTypeExternalId:StackExchangeNetwork_NewYork_SENetworkDev
[23:54:03] : Collecting changes in 2 VCS roots (1s)
@NickCraver
NickCraver / Build.xml
Last active July 7, 2023 16:40
Stack Overflow Build Reference Docs
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="PrepareStaticContent" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Passed in Parameters -->
<configuration></configuration>
<workingDir></workingDir>
<buildNumber></buildNumber>
<buildViews>false</buildViews>
<minifyJs>true</minifyJs>
<TargetsDirectory></TargetsDirectory>
@NickCraver
NickCraver / BotLovin.cs
Last active January 5, 2023 11:36
Some bot/crawler fun on Stack Overflow. 10 hours of fun, to be precise.
private static readonly string[] tenHoursOfFun =
{
"https://www.youtube.com/watch?v=wbby9coDRCk",
"https://www.youtube.com/watch?v=nb2evY0kmpQ",
"https://www.youtube.com/watch?v=eh7lp9umG2I",
"https://www.youtube.com/watch?v=z9Uz1icjwrM",
"https://www.youtube.com/watch?v=Sagg08DrO5U",
"https://www.youtube.com/watch?v=5XmjJvJTyx0",
"https://www.youtube.com/watch?v=IkdmOVejUlI",
"https://www.youtube.com/watch?v=jScuYd3_xdQ",
@NickCraver
NickCraver / Readme.md
Created April 10, 2016 19:40
A simple LINQPad script I wrote for load testing SQL Server.

This is a simple LINQPad script I wrote one day to load test some large SQL servers. Maybe it's useful to someone. The basic premise is defining your queries once, including which ID patterns to fetch (at the bottom), and load test a mixture. The script defines everything needed in one place, then fires up the command-line linqpad runner to run many queries at once.

Params up top:

const string LinqPadPath = @"C:\Linqpad\lprun.exe";
const bool runSequential = false;
const int defaultThreads = 1;
const int defaultIterations = 2000;