Skip to content

Instantly share code, notes, and snippets.

View sheldonhull's full-sized avatar
👋
Hi! Who keeps their github status up to date? You get a 🌮 just for reading this

sheldonhull sheldonhull

👋
Hi! Who keeps their github status up to date? You get a 🌮 just for reading this
View GitHub Profile
@sheldonhull
sheldonhull / README.md
Last active December 14, 2021 03:37
Clean Go Mod Cache

Clean Go Mod Cache

  • run go clean -modcache
  • run sudo --preserve-env find $HOME/go/pkg/mod -exec rm -rf {} +
@sheldonhull
sheldonhull / README.md
Last active November 17, 2021 21:24
[help] enumeration with go

Enumeration With Go

Usage of named aliases for types in an effort to emulate enumeration behavior from other languages can cause issues.

Using a named type for an alias gives the illusion of control, but since a literal value can be placed as it matches the type, it doesn't really do anything but provide an additional layer of abstraction.

Example:

@sheldonhull
sheldonhull / update-package-json.ps1
Last active November 1, 2021 23:10
Using pwsh to edit package.json temporalio version update
# this uses aliases to simulate what a linux user would normally expect to write
# idiomatic powershell leans on clarity over being terse, so "%" would be ForEach-Object for example.
$Files = gci -Recurse -Filter package.json | Where Name -notmatch "node_modules" | % { [pscustomobject]@{FullName = $_.FullName; Content = (gc $_.FullName -raw | ConvertFrom-Json) }}
$UpdateFiles = $files | ? {$_.Content.Dependencies -match 'temporalio'}
$UpdateFiles | % {
$f = $_ # $_ = pipelined object with all properties available
$f.Content.Dependencies.temporalio = '^0.13.0' # this is object property reference because ConvertFrom-Json gave us an object, not raw text
$f.Content | ConvertTo-Json -depth 100 | Out-File -Path $f.FullName -Force # convert back to json as it was actually an object
}
@sheldonhull
sheldonhull / README.md
Last active July 17, 2022 00:36
[using nix for tooling inside docker] Test case of using nix for replacing custom steps in a dockerfile for dev tooling #nix #codespaces #help

Using Nix CLI

FROM mcr.microsoft.com/vscode/devcontainers/universal:1-${VARIANT} as BASE

RUN sh <(curl -L https://nixos.org/nix/install) --no-daemon
RUN mkdir -p /home/codespace/.config/nixpkgs && echo '{ allowUnfree = true; }' >> /home/codespace/.config/nixpkgs/config.nix
RUN echo '. /home/codespace/.nix-profile/etc/profile.d/nix.sh' >> /home/codespace/.bashrc

# Install git
@sheldonhull
sheldonhull / run.ps1
Created August 5, 2021 17:36
[Use GM to render a markdown] #go #markdown
# choco install go -y
# brew install go
# should use latest to simplify go install commands.
go install github.com/kpym/gm@latest
# help
&"$ENV:HOME/go/bin/gm" -h
@sheldonhull
sheldonhull / envBoo.go
Created July 27, 2021 22:27
[GitHub Copilot Goland envBool function] #golang
// envBool returns a boolean from an environment variable existing or not.
Synthesizing 10/10 solutions
=======
# mean prob: 0.8506432006730708
func envBool(key string) bool {
if val, ok := os.LookupEnv(key); ok {
if val == "true" || val == "1" {
@sheldonhull
sheldonhull / parse-enabled-and-installed-extensions.ps1
Last active July 21, 2021 21:31
[Enabled & Installed VSCode Extensions] #vsocde #powershell
# Get Extension Data from Settings Sync, and put the list of extensions in this here block
$extensions = Get-Clipboard | convertfrom-json -depth 10
# $extensions = @'
# '@ | convertfrom-json -depth 10
$parsed = $extensions | Where {$_.disabled -ne $true -and $_.Installed -eq $true}
$parsed.Identifier
# Print output to copy
@sheldonhull
sheldonhull / README.md
Last active July 7, 2021 01:05
git-compose

Using Git-Compose

  • Install Git-Compose
  • Set preference of ssh or https. Default behavior is https. To change to ssh use: gico config set --prefer-remote ssh

Use in current directory to initialize quickly with: gico init, or use a remote yaml url to quickly setup a new dev.

@sheldonhull
sheldonhull / patch-work-item.ps1
Last active June 11, 2021 00:52
[Update Azure DevOps description using patch request with api] #powershell #azuredevops
<#
.LINK
Operation Types: https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/update?view=azure-devops-rest-6.0#operation
How to Use This API: https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/update?view=azure-devops-rest-6.0
Gotcha:
However, this isn't always the case. For instance, running a script on my machine, using my own base64 encoded PAT, ../_apis/../projects needs `Basic` but ../_apis/../pullrequests needs `Bearer`. When running through AzDO, they all need `Bearer`.
https://developercommunity.visualstudio.com/t/using-powershell-script-to-call-azure-devops-api-w/816540
... but it appears that if you use your account's PAT, you need to use `Basic` and encode it with a : (colon) at the beginning of the PAT:
@sheldonhull
sheldonhull / README.md
Created June 9, 2021 17:20
[Python 3 Virtual Env Basics] quick example of using python3 venv to install tools and stuff in a self-contained virtual env in the current project directory #python #windows

Getting Started Tips for Windows & Terminal

  • don't use cmd prompt for anything, use PowerShell
  • install latest windows terminal from store, don't use default terminals, they are terrible and less featured.
  • Suggest installing PowerShell 7 as your normal windows base terminal to use.
  • Install Scoop to make this super easy to install. scoop install pwsh
  • Open pwsh (PowerShell 7) as your default in Terminal

Use Py