Skip to content

Instantly share code, notes, and snippets.

View refactorsaurusrex's full-sized avatar

refactorsaurusrex

View GitHub Profile
@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 / JsonDeserializer.cs
Last active October 15, 2018 17:09
Debugging RestSharp Deserialization Errors http://wp.me/p4mdOw-1f9
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using RestSharp;
using RestSharp.Deserializers;
namespace MyAwesomeProject
{
public class JsonDeserializer : IDeserializer
{
@refactorsaurusrex
refactorsaurusrex / maybe.cs
Created May 22, 2016 20:46
Maybe<T>, inspired by Mark Seemann
public class Maybe<T> : IEnumerable<T>
{
readonly IEnumerable<T> values;
public Maybe()
{
values = new T[0];
}
public Maybe(T value)
@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 / .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 / 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.txt
Last active January 7, 2020 18:55
Jenkinsfile: How to get the author name for the HEAD commit
AUTHOR_NAME = bat (
script: "git show -s --format='%%an' HEAD",
returnStdout: true
).split('\r\n')[2].trim()
echo "The last commit was written by ${AUTHOR_NAME}."
echo "PS - Jenkins sucks giant monkey balls."

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 / process-vs-continue.ps1
Last active July 28, 2021 05:27
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 -Force to disable prompting.
@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