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 / CSharp6GetOnlyOverride.cs
Created March 9, 2016 14:23
Example of get-only overrides in C# 6 and fun side-effects.
void Main()
{
var child = new Child();
child.Prop = false;
child.Prop.Dump();
var propertyInfo = typeof(Child).GetProperty(nameof(Child.Prop));
propertyInfo.GetGetMethod().Dump();
propertyInfo.GetSetMethod().Dump();
}
public class Base
@NickCraver
NickCraver / DapperExample.cs
Last active February 21, 2016 20:53
Query Optimization: Literal Example
// Here's a normal query as you'd expect
db.QuerySingleOrDefault<PostCacheEntry>(@"SELECT
(Select Count(*) From Posts Where PostTypeId = @Question And DeletionDate Is Null) TotalQuestions,
(Select Count(*) From Posts Where PostTypeId = @Question And IsNull(IsAnswered, 0) = 0 And AcceptedAnswerId Is Null And ClosedDate Is Null And DeletionDate Is Null) TotalUnanswered,
(Select Count(*) From Posts Where PostTypeId = @Question And AcceptedAnswerId Is Not NulL And DeletionDate Is Null) TotalAccepted,
(Select Count(*) From Posts Where PostTypeId = @Answer And DeletionDate Is Null) TotalAnswers",
new { PostTypeId.Question, PostTypeId.Answer });
// In this case though, PostTypeId.Question and PostTypeId.Answer are values that never change.
// In this case they're constants, but this same trick works for enums.
@NickCraver
NickCraver / ForSyntaxHighlights.cs
Last active February 20, 2016 01:09
How to be a jerk using SQL and Dapper
var tb = AppDomain.CurrentDomain
.DefineDynamicAssembly(new AssemblyName("Test"), AssemblyBuilderAccess.Run)
.DefineDynamicModule("DM")
.DefineType("Type with spaces in the name", TypeAttributes.Public);
tb.DefineField("Is💩Post", typeof(bool), FieldAttributes.Public);
var spt = tb.CreateType();
this.Connection.QueryFirstOrDefault(spt, "Select 1 as [Is💩Post]").Dump();
@NickCraver
NickCraver / DbColumnReflectionPerf.cs
Created February 8, 2016 23:00
Quick performance comparison of the DbColumn options performance-wise
void Main()
{
var c = new DbColumn() { ColumnName = "test" };
var sw = Stopwatch.StartNew();
for (var i = 0; i < 10000000; i++)
{
var test = c["ColumnName"];
}
sw.Stop();
sw.ElapsedMilliseconds.Dump();

Keybase proof

I hereby claim:

  • I am NickCraver on github.
  • I am nickcraver (https://keybase.io/nickcraver) on keybase.
  • I have a public key whose fingerprint is 9854 D2C3 4BEF 984F 7310 DC97 A163 F138 E6C1 87DF

To claim this, I am signing this object:

@NickCraver
NickCraver / SwitchTest.cs
Created January 22, 2016 13:58
LinqPad switch implementation test
void Main() { }
public class DbColumn
{
private readonly Dictionary<string, object> _customValues = new Dictionary<string, object>();
public virtual bool AllowDBNull { get; set; }
public virtual string BaseCatalogName { get; set; }
public virtual string BaseColumnName { get; set; }
public virtual string BaseSchemaName { get; set; }
public virtual string BaseServerName { get; set; }
@NickCraver
NickCraver / Win10NagRemover.ps1
Last active July 25, 2023 00:20
Windows 10 Upgrade Nag Remover. This script removes the Windows 7 & 8 updates that cause the Windows 10 upgrade nags to appear and hides them to prevent re-install. Must be run as administrator.
# Simple script to remove the Windows 10 "Nag" Updates and telemetry additions for Windows 7 & 8 users
# This will uninstall the updates and hide them, preventing installation in the future
# Note: MUST BE RUN AS ADMINISTRATOR, setting updates to hidden requires admin permissions
# Updates removed:
# KB3035583 - Update installs Get Windows 10 app in Windows 8.1 and Windows 7 SP1
# https://support.microsoft.com/en-us/kb/3035583
# KB2952664 - Compatibility update for upgrading Windows 7
# https://support.microsoft.com/en-us/kb/2952664
# KB2976978 - Compatibility update for Windows 8.1 and Windows 8
# https://support.microsoft.com/en-us/kb/2976978
@NickCraver
NickCraver / Orion-QueryPlan.sqlplan
Created November 20, 2015 04:12
Orion SQL Plan for SELECT Count(*) FROM InterfaceTraffic
This file has been truncated, but you can view the full file.
<?xml version="1.0" encoding="utf-16"?>
<ShowPlanXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.2" Build="11.0.5343.0" xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan">
<BatchSequence>
<Batch>
<Statements>
<StmtSimple StatementCompId="1" StatementEstRows="1" StatementId="1" StatementOptmLevel="FULL" StatementSubTreeCost="162.511" StatementText="Select Count(*)&#xD;&#xA; From InterfaceTraffic" StatementType="SELECT" QueryHash="0x9DA8413D2DA45AE8" QueryPlanHash="0xDCB2FBECB646294A" RetrievedFromCache="true">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="24" MemoryGrant="51280" CachedPlanSize="512" CompileTime="766" CompileCPU="765" CompileMemory="15912">
<ThreadStat Branches="2" UsedThreads="48">
<
@NickCraver
NickCraver / results.txt
Created November 3, 2015 20:11
string.Format() vs string.Concat() quick perf tests for Abstractions
string.Concat(): 3011 ms
string.Format(): 18337 ms
string.Concat(): 2885 ms
string.Format(): 18312 ms
@NickCraver
NickCraver / dnx.log
Created October 25, 2015 22:02
DNX "Failed to start CLR host" log
C:\DNXTest\Client\runtimes\dnx-coreclr-win-x86.1.0.0-beta8\bin>dnx
The default servicing root does not exist.
Loaded module: dnx.win32.coreclr.dll
Found export: CallApplicationMain
Failed to start CLR host