Skip to content

Instantly share code, notes, and snippets.

View refactorsaurusrex's full-sized avatar

refactorsaurusrex

View GitHub Profile

Keybase proof

I hereby claim:

  • I am refactorsaurusrex on github.
  • I am nickspreitzer (https://keybase.io/nickspreitzer) on keybase.
  • I have a public key ASAE7hZWzEh4jyEpkcRzsSpkH0ruZOi5nvuyQgKP9h_-Mgo

To claim this, I am signing this object:

@refactorsaurusrex
refactorsaurusrex / profile.ps1
Last active August 22, 2023 22:57
How to open the Windows environment variables dialog with PowerShell
function Get-EnvironmentVariablesDialog {
rundll32 sysdm.cpl,EditEnvironmentVariables
}
Set-Alias EnvGui Get-EnvironmentVariablesDialog
@refactorsaurusrex
refactorsaurusrex / .htaccess
Last active January 7, 2020 18:45
How to simultaneously 1) redirect http to https AND 2) remove 'www', if it exists, using an htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://example.com%{REQUEST_URI} [R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com%{REQUEST_URI} [R=301]
@refactorsaurusrex
refactorsaurusrex / nuget-update-fails.md
Last active March 13, 2018 20:41
Nuget 'update' command fails: 'Microsoft.CSharp.Core.targets' was not found

When running nuget update 'some.solution.sln' -id 'Some.Package.Id' yesterday, I got the following error:

Scanning for projects...
MSBuild auto-detection: using msbuild version '15.4.8.50001' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\
Enterprise\MSBuild\15.0\bin'.
The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\Roslyn\
Microsoft.CSharp.Core.targets" was not found. Confirm that the path in the <Import> declaration is correct, 
and that the file exists on disk.  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\
Microsoft.CSharp.CurrentVersion.targets
@refactorsaurusrex
refactorsaurusrex / process-vs-continue.ps1
Last active November 15, 2024 13:30
PowerShell: What's the difference between ShouldContinue and ShouldProcess?
# The default is High. Setting it here for clarity.
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-5.1
$ConfirmPreference = 'High'
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[switch]$Force
)
# Use this to prompt the user by default. Use the -Force parameter to disable prompting.
@refactorsaurusrex
refactorsaurusrex / prepare-commit-msg.sh
Last active December 23, 2019 14:58
git 'prepare commit msg' hook that rejects merge commits when the source branch is behind the target branch
#!/bin/sh
if [ "$2" = "merge" ]; then
githead=$(env | grep GITHEAD)
source="${githead##*=}"
target=$(git symbolic-ref HEAD)
behind=$(git rev-list --left-only --count $target...$source)
if [ $behind -gt 0 ]; then
echo "Aborting: The source branch is $behind commits behind the target branch."
exit 1
fi
@refactorsaurusrex
refactorsaurusrex / Open-Solution.psd1
Last active February 1, 2024 03:21
PowerShell function to open the first Visual Studio solution file found within the current directory.
@{
RootModule = 'Open-Solution.psm1'
ModuleVersion = '0.1.0'
GUID = '42f8cad0-c32a-4ccd-9401-de4bdbafdd65'
Author = 'Nick Spreitzer'
FunctionsToExport = @('Open-Solution')
AliasesToExport = @('sln')
}
@refactorsaurusrex
refactorsaurusrex / appendAllLines.ps1
Last active June 22, 2024 05:49
How to call 'File.AppendAllLines' with PowerShell
$path = 'C:\text.txt'
$output = 'This is an output string'
# This works...
[System.IO.File]::WriteAllLines($path, $output)
# But this doesn't. WTF!
[System.IO.File]::AppendAllLines($path, $output)
# Result: 'Cannot find an overload for "AppendAllLines" and the argument count: "2".'
@refactorsaurusrex
refactorsaurusrex / zero29.bat
Last active January 7, 2020 18:49
Install zero29 with Chocolatey!
choco install zero29 -source https://nuget.org/api/v2/
@refactorsaurusrex
refactorsaurusrex / jenkinsfile.groovy
Created May 22, 2017 23:07
Jenkins Pipeline: How to get the status of the previous build
node('whatever') {
stage('blah') {
echo currentBuild.getPreviousBuild().result
}
}
// ref: https://support.cloudbees.com/hc/en-us/articles/217591038-How-to-Iterate-Through-the-Last-Successful-Builds-in-Pipeline-Job