Skip to content

Instantly share code, notes, and snippets.

View wsmelton's full-sized avatar
🦆
Little bit of this, little bit of that

Shawn Melton wsmelton

🦆
Little bit of this, little bit of that
View GitHub Profile
@wsmelton
wsmelton / jl.ps1
Last active February 25, 2020 20:17
Quick function to start up JupyterLab using dotnet interactive
function jl {
[cmdletbinding()]
param ([string]$folder)
if ([String]::IsNullOrEmpty($folder)) {
& jupyter lab --notebook-dir=$pwd
} else {
& jupyter lab --notebook-dir=$folder
}
}
@wsmelton
wsmelton / snippet.md
Last active January 10, 2020 04:48
Create a snippet for PSCredential in VS Code

Sometimes you just need to create a PSCredential object in your PowerShell script. In VS Code I was not able to find any snippet that did this so created one.

You can add this to the powershell.json snippet file for your VS Code instance. Use Command Palette > Configure User Snippets > PowerShell to open that file.

Then paste the code in the json file of this Gist.

You can use either cred or pscred to bring up the snippet in any editor set to the PowerShell language:

@wsmelton
wsmelton / profiles.json
Last active November 21, 2019 16:33
My personal Windows Terminal profile settings
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"profiles": [
{
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell Core",
$Global:baseUri = 'https://management.azure.com'
$Global:subScription = "subscriptions/<add subscription guid>"
$Global:resourceGroup = "resourceGroups/genera-rg"
$Global:AzureSqlProvider = "providers/Microsoft.Sql"
$Global:AzureApiVersion = "?api-version=2017-10-01-preview"
function New-AuthToken {
$token = az account get-access-token --resource="$baseUri" --output json | ConvertFrom-Json
$global:header = @{
'Content-Type' ='application\json'
@wsmelton
wsmelton / Reset-BranchToUpstream.ps1
Last active November 8, 2019 14:31
Function you can add to your profile for resetting a given branch in your fork to the upstream branch.
function Reset-BranchToUpstream {
<#
.SYNOPSIS
Command to reset the branch to your upstream remote
.DESCRIPTION
Assumes you remote is setup as origin is your fork, and "upstream" is the remote source. You can pass in a branch, and it assumes you have this branch checked out on your origin or local repository.
.PARAMETER Branch
The desired branch you want to sync
.EXAMPLE
Reset-BranchToUpstream -Branch development
@wsmelton
wsmelton / AzDependencies.json
Created October 8, 2019 19:11
Json file of the Az modules and their dependencies.
[
{
"Name": "Az.Accounts",
"Dependencies": null
},
{
"Name": "Az.Automation",
"Dependencies": "Az.Accounts"
},
{
@wsmelton
wsmelton / f.sh
Created August 4, 2019 04:15
String search using WSL
ag --ignore-case --nogroup $1
# requires install of silversearcher-ag
# apt-get install silversearcher-ag
@wsmelton
wsmelton / Get-NetFramework.ps1
Last active June 26, 2019 18:49
SO script for pulling versions of NET Framework installed
<# Source: https://stackoverflow.com/a/3495491/847990 #>
# Get the text from github
$url = "https://raw.githubusercontent.com/dotnet/docs/master/docs/framework/migration-guide/how-to-determine-which-versions-are-installed.md"
$md = Invoke-WebRequest $url -UseBasicParsing
$OFS = "`n"
# Replace the weird text in the tables, and the padding
# Then trim the | off the front and end of lines
$map = $md -split "`n" -replace " installed [^|]+" -replace "\s+\|" -replace "\|$" |
# Then we can build the table by looking for unique lines that start with ".NET Framework"
Select-String "^.NET" | Select-Object -Unique |
@wsmelton
wsmelton / details.md
Last active February 8, 2019 21:38
General script used in projects that allows you to validate an environment.

Purpose

On average I'm working with Docker for Windows on my machine when I need to analyze some data or say build reports from collected metric data of a given client. The environment.ps1 script provided simply does some validates for me and ensures everything is in order.

No Pester

I'm not using Pester for the testing of the environment because on average I don't have machines in client environments with that installed. Just making it more universal for right now but if you want to take it and go with using Pester...by all means.

Check for Docker

@wsmelton
wsmelton / DownloadDbatools-GitHub.ps1
Created January 15, 2019 19:51
Download dbatools from GitHub - uses shortlink for dbatools.io
$zipFile = 'C:\temp\dbatools.zip'
$url = 'https://dbatools.io/zip'
$extractPath = 'C:\temp\modules\'
(New-Object System.Net.WebClient).DownloadFile($url, $zipfile)
[io.compression.zipfile]::ExtractToDirectory($zipPath, $extractPath)
# You can stop right there and will just use following to import
Import-Module C:\temp\modules\dbatools-master\dbatools.psd1
# Other option is to rename the folder