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 / .editorconfig
Created September 26, 2017 21:31
Stack Overflow's .editorconfig
# editorconfig.org
root = true
# Don't use tabs for indentation.
[*]
indent_style = space
[*.less]
charset = utf-8
end_of_line = lf
@NickCraver
NickCraver / Stylus.StackExchange.css
Created July 7, 2017 21:27
My Stylus theme for Stack Exchange MiniProfiler and Chat
@-moz-document domain("stackoverflow.com"), domain("stackexchange.com"), domain("serverfault.com"), domain("askubuntu.com"), domain("stackapps.com"), domain("superuser.com") {
.profiler-result tr[style*='display: block;'] {
display: table-row !important;
}
.profiler-result th[style*='display: block;'], .profiler-result td[style*='display: block;'] {
display: table-cell!important;
}
}
@-moz-document domain("chat.meta.stackexchange.com"), domain("chat.stackexchange.com"), domain("chat.stackoverflow.com") {
@NickCraver
NickCraver / Query.sql
Created June 1, 2017 21:50
SQL Divide By Zero Glitch with aggregates
SELECT [tag.iface], [tag.host], Sum([value]) [value], [timestamp]
FROM (SELECT [tag.iface], [tag.host], [tag.direction], [dateDiff], Max([value]) [value],
DateAdd(Second, DateDiff(Second, GETUTCDATE(), [timestamp]) / 15 * 15, GETUTCDATE()) [timestamp]
FROM (SELECT [tag.iface],
[tag.host],
[tag.direction],
[timestamp],
DateDiff(Second, [LastTime], [timestamp]) [dateDiff],
--(([value] - [LastValue]) / NullIf(DateDiff(Second, [LastTime], [timestamp]), 0)) [value]
(([value] - [LastValue]) / DateDiff(Second, [LastTime], [timestamp])) [value]
@NickCraver
NickCraver / SSMS17and17-HiDPI.ps1
Last active June 24, 2023 23:30
PowerShell: SSMS 16 & 17 HiDPI Enable
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"><asmv3:application><asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings"><dpiAware>True</dpiAware></asmv3:windowsSettings></asmv3:application><dependency><dependentAssembly><assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /></dependentAssembly></dependency><dependency><dependentAssembly><assemblyIdentity type="win32" name="debuggerproxy.dll" processorArchitecture="X86" version="1.0.0.0"></assemblyIdentity></dependentAssembly></dependency></assembly>';
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide" -Name PreferExternalManifest -Value 1 -Type DWord;
$ssms16 = "C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Ssms.exe";
if ((
@NickCraver
NickCraver / VPN-DNS-Test.ps1
Created April 27, 2017 12:19
Windows 10 VPN/DNS problem repro
# Must be run as admin for registry changes
# This illustrates the problem with the Stack Exchange VPN, results locally:
# Total time for default behavior (seconds): 12.0566448
# Total time with registry tweaks (seconds): 1.0808937
# Broken/Slow (default Windows 10 behavior)
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows NT\DNSClient" -Name DisableSmartNameResolution -Value 0 -Type DWord
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters" -Name DisableParallelAandAAAA -Value 0 -Type DWord
ipconfig /flushdns | Out-null
Write-Host "Total time for default behavior (seconds): " -NoNewLine
@NickCraver
NickCraver / 01. TrafficLogs.sql
Last active April 20, 2017 18:09
Setup scripts for TrafficLogs.sql - table partitioning and archive movement fun.
-- For production
--CREATE DATABASE [TrafficLogs] CONTAINMENT = NONE ON
--PRIMARY ( NAME = N'TrafficLogs', FILENAME = N'E:\Data\TrafficLogs.mdf' , SIZE = 102400000KB , FILEGROWTH = 5120000KB),
--FILEGROUP [TrafficLogs_D] ( NAME = N'TrafficLogs_D', FILENAME = N'D:\Data\TrafficLogs_D.ndf' , SIZE = 102400000KB, FILEGROWTH = 51200000KB),
--FILEGROUP [TrafficLogs_E] ( NAME = N'TrafficLogs_E', FILENAME = N'E:\Data\TrafficLogs_E.ndf' , SIZE = 1024000000KB, FILEGROWTH = 51200000KB)
--LOG ON ( NAME = N'TrafficLogs_log', FILENAME = N'D:\Data\TrafficLogs.ldf' , SIZE = 51200000KB , FILEGROWTH = 10240000KB)
--GO
-- For local development
Declare @dataPath nvarchar(500) = Cast(ServerProperty('instancedefaultdatapath') as nvarchar(500)),
@NickCraver
NickCraver / JSONBenchmarks.txt
Created April 12, 2017 10:07
BenchmarkDotNet 3hr run
// ***** BenchmarkRunner: Start *****
// Found benchmarks:
// JSONBenchmarks.'.ToJson(): Minimal MiniProfiler': DefaultJob
// JSONBenchmarks.'MiniProfiler.FromJson: Minimal MiniProfiler': DefaultJob
// Validating benchmarks:
// **************************
// Benchmark: JSONBenchmarks.'.ToJson(): Minimal MiniProfiler': DefaultJob
// *** Generate ***
// Result = Success
@NickCraver
NickCraver / Benchmarks.md
Last active April 9, 2017 22:30
MiniProfiler JSON Benchmarks
BenchmarkDotNet=v0.10.3.0, OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-4850HQ CPU 2.30GHz, ProcessorCount=3
Frequency=10000000 Hz, Resolution=100.0000 ns, Timer=UNKNOWN
  [Host] : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1590.0
  Clr    : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1590.0
  Core   : .NET Core 4.6.25009.03, 64bit RyuJIT
@NickCraver
NickCraver / Svg.cs
Created February 1, 2017 22:36
A simple SVG helper for Stack Overflow that inlines SVGs into Razor views efficiently
using System;
using System.IO;
using System.Web;
using System.Web.Hosting;
namespace StackOverflow.Helpers
{
public static class Svg
{
// NOTE: To add a new SVG icon, copy paste the line below. Paste it after the other ones.
@NickCraver
NickCraver / ExampleUsage.cs
Last active November 27, 2021 04:24
Code to mark a SQL string before it's passed to Dapper.
public static List<T> Query<T>(this DataContext db, string sql, object param = null, int? commandTimeout = null, IDbTransaction transaction = null, [CallerFilePath]string fromFile = null, [CallerLineNumber]int onLine = 0, string comment = null)
{
using (db.Connection.EnsureOpen())
{
try
{
return db.Connection.Query<T>(MarkSqlString(sql, fromFile, onLine, comment), param, transaction ?? db.Transaction, true, commandTimeout).AsDapperList();
}
catch (SqlException ex) when (ex.Is(SqlErrorCode.DatabaseReadOnly_3906))
{