Skip to content

Instantly share code, notes, and snippets.

View refactorsaurusrex's full-sized avatar

refactorsaurusrex

View GitHub Profile
@refactorsaurusrex
refactorsaurusrex / git.md
Last active April 13, 2024 16:31
How to retroactively apply gitignore to a repo
  1. Add or update a .gitignore file
  2. Rebase your repo such that the .gitignore from step one is positioned in history prior to the naughty file(s) being commited.
  3. Run this command, where <commit> is the hash for the commit respresented by step 1: git rebase -ix 'git rm -r --cache . && git add . && git commit --amend --no-edit' <commit>
  4. Resolve conflicts as necessary.

Note that if there are only a few file types or directories or individual files, filter-branch is a simpler route to take. These steps are only necessary for large numbers of files / file types. Also note that there may be better ways still of doing this. :-)

@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 / 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 / appendAllLines.ps1
Last active August 1, 2023 12:53
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 / 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
@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.

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 / 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."
@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 / .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]