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 / TimingExample.ps1
Last active November 5, 2022 20:59
Quick example of how to use script blocks to track timing in an easy-to-wrap way in PowerShell for things like stages of a build
# Track build time components below
$steps = [System.Collections.Generic.List[PSObject]]@()
function TrackTime {
Param(
[string]$name,
[scriptblock]$script
)
Write-Host ""
Write-Host -ForegroundColor Blue "[$(([DateTime](Get-Date)).ToString("u"))] Step: $name"
@NickCraver
NickCraver / Program.cs
Created May 15, 2022 21:13
MSBuild Dupe WriteChecker
// Inspired by https://github.com/dotnet/roslyn/blob/main/src/Tools/BuildBoss/StructuredLoggerCheckerUtil.cs#L33
// Licensed to the .NET Foundation under one or more agreements.
using System;
using Microsoft.Build.Logging.StructuredLogger;
// Invokes the analyzer here:
// https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/master/src/StructuredLogger/Analyzers/DoubleWritesAnalyzer.cs
string _logFilePath = System.IO.Path.GetFullPath(args[0]);
Console.WriteLine($"Running MSBuild binlog checks for '{_logFilePath}'");
@NickCraver
NickCraver / Craver-Paradox.ps1
Last active April 20, 2022 03:05
My PowerShell PoshGit theme (used with Cmder)
#requires -Version 2 -Modules posh-git
# This is a tweaked version of https://github.com/JanJoris/oh-my-posh/blob/master/Themes/Paradox.psm1
function Write-Theme {
param(
[bool]
$lastCommandFailed,
[string]
$with
)
@NickCraver
NickCraver / TopCPUUsers.sql
Created April 24, 2019 14:52
SQL: Top CPU Users query
SELECT AvgCPU, AvgDuration, AvgReads, AvgCPUPerMinute,
TotalCPU, TotalDuration, TotalReads,
PercentCPU, PercentDuration, PercentReads, PercentExecutions,
ExecutionCount,
ExecutionsPerMinute,
PlanCreationTime, LastExecutionTime,
SUBSTRING(st.text,
(StatementStartOffset / 2) + 1,
((CASE StatementEndOffset
WHEN -1 THEN DATALENGTH(st.text)
@NickCraver
NickCraver / RedisExampleListBlocking.linq
Created February 3, 2022 19:49
Redis Blocking BRPOP example
<Query Kind="Program">
<NuGetReference>StackExchange.Redis</NuGetReference>
<Namespace>StackExchange.Redis</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>
private static RedisKey WorkToDoList = "work-to-do-list";
private static RedisChannel WorkToDoChannel = "work-to-do";
// List-backed, blocker example
@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))
{
@NickCraver
NickCraver / Legion7AspNetCoreTimings.md
Created September 2, 2021 03:08
Legion 7 dotnet/aspnetcore build timings

Machine info

Lenovo Legion 7 AMD 5900HX (8C/16T) 32 GB RAM 2TB NVMe

Repo info

git rev-parse HEAD 916e008178a1dc2c9f33475437e2ebf257cd7cd6

@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 / jQuery.logHandlers.js
Created April 25, 2015 15:42
A simple jQuery plugin to print bound event handlers, including on parent elements
$.fn.logHandlers = function() {
var result = {};
this.parents().andSelf().each(function(_, e) {
var events = $._data(e, 'events') || {};
if ($.isEmptyObject(events)) return;
var cur = result[this.outerHTML.split($(this).html())[0]] = {};
Object.keys(events).forEach(function(k) {
cur[k] = events[k].map(function(ev) {
return ev.handler.toString();
});
@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."