Skip to content

Instantly share code, notes, and snippets.

@nickcox
nickcox / env.sh
Last active May 17, 2021 07:38
Source environment variables from a .env file
set -a && source .env && set +a
@nickcox
nickcox / CleanSolution.ps1
Created May 17, 2021 07:40
Remove obj & bin directories (to a depth of four levels)
ls -Directory -Recurse -Depth 4 |? Name -In obj,bin | rm -Force -Recurse
@nickcox
nickcox / debug-to-file.xml
Created May 17, 2021 07:42
Redirect `Debug.WriteLine` output to a text file
<system.diagnostics>
<sharedListeners>
<add name="file"
autoFlush="true"
append="false"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
customLocation="c:\temp"
location="Custom"
logFileCreationSchedule="Daily"
baseFileName="Log"/>
@nickcox
nickcox / timever.ps1
Created May 23, 2021 22:39
Timever compatible version string
# get a version string based on the current date & time
# https://gist.github.com/twolfson/de1b004dd22536b8e668
(Get-Date -AsUTC).ToString('yyyyMMdd.hhmmss.fffffff00')
@nickcox
nickcox / gitignore.ps1
Created May 25, 2021 21:41
Add a .gitignore file suitable for NodeJS
# https://github.com/github/gitignore
npx gitignore node
@nickcox
nickcox / aws-whoami.sh
Last active October 11, 2021 00:49
AWS whoami
aws sts get-caller-identity
# set environment variables from a file
cat ./vars.env | ConvertFrom-StringData |? Values -ne @{} |% {ni -Name $_.Keys -Value $_.Values -Path env: -Force}
fd --no-ignore System.Collections.Immutable.dll | gi |% {
[pscustomobject]@{name=$_; version=[Reflection.AssemblyName]::GetAssemblyName($_).Version }}
@nickcox
nickcox / Use-LSColors.ps1
Created May 5, 2022 23:22
Apply PowerShell styles to an LSColors format string
Function Use-LSColors {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$LSColors
)
$LSColors -Split ":" | % {
$param, $arg = $_ -Split "="
# lazy load posh-git
Register-ArgumentCompleter -Native -CommandName 'git' -ScriptBlock {
if (!(gmo posh-git)) { Expand-GitCommand ($args[1] -replace '^git\W*', '') }
}