Skip to content

Instantly share code, notes, and snippets.

@ril3y
Last active May 9, 2025 14:48

Revisions

  1. ril3y revised this gist May 9, 2025. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -265,3 +265,27 @@ function which {
    # If no match was found
    Write-Host "${CommandName}: command not found" -ForegroundColor Red
    }


    function sha256 {
    param (
    [Parameter(Mandatory = $true, Position = 0)]
    [string]$Path
    )

    if (-not (Test-Path $Path)) {
    Write-Error "File not found: $Path"
    return
    }

    try {
    $stream = [System.IO.File]::OpenRead($Path)
    $sha256 = [System.Security.Cryptography.SHA256]::Create()
    $hashBytes = $sha256.ComputeHash($stream)
    $stream.Close()
    $hash = -join ($hashBytes | ForEach-Object { $_.ToString("x2") })
    Write-Output $hash
    } catch {
    Write-Error "Error hashing file: $_"
    }
    }
  2. ril3y revised this gist Dec 14, 2024. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    $env:VIRTUAL_ENV_DISABLE_PROMPT = "1"

    Set-Alias gcc "arm-none-eabi-gcc-13.3.1.exe"
    Set-Alias downloads "cd C:\Users\ril3y\Downloads"

    & "C:\Users\riley\myvenv\Scripts\Activate.ps1"
    try {
    @@ -11,6 +10,23 @@ try {
    }


    # Function to change directory to the Downloads folder
    function Downloads {
    try {
    $downloadsPath = [Environment]::GetFolderPath('MyDocuments') -replace '\\Documents$', '\\Downloads'
    if (Test-Path $downloadsPath) {
    Set-Location $downloadsPath
    Write-Host "Changed directory to Downloads: $downloadsPath" -ForegroundColor Green
    } else {
    Write-Host "Downloads directory not found!" -ForegroundColor Red
    }
    } catch {
    Write-Host "Error navigating to Downloads directory: $_" -ForegroundColor Red
    }
    }



    function Disable-NewsAndInterests {
    # Disable Windows Widgets by setting the registry value
    $registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
  3. ril3y revised this gist Dec 14, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    $env:VIRTUAL_ENV_DISABLE_PROMPT = "1"

    Set-Alias gcc "arm-none-eabi-gcc-13.3.1.exe"
    Set-Alias downloads "cd C:\Users\ril3y\Downloads"

    & "C:\Users\riley\myvenv\Scripts\Activate.ps1"
    try {
  4. ril3y revised this gist Dec 14, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    $env:VIRTUAL_ENV_DISABLE_PROMPT = "1"

    Set-Alias gcc "arm-none-eabi-gcc-13.3.1.exe"

    & "C:\Users\riley\myvenv\Scripts\Activate.ps1"
  5. ril3y revised this gist Dec 14, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    $env:VIRTUAL_ENV_DISABLE_PROMPT = "1"
    Set-Alias gcc "C:\Path\To\arm-none-eabi-gcc-13.3.1.exe"
    Set-Alias gcc "arm-none-eabi-gcc-13.3.1.exe"

    & "C:\Users\riley\myvenv\Scripts\Activate.ps1"
    try {
  6. ril3y revised this gist Dec 14, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    $env:VIRTUAL_ENV_DISABLE_PROMPT = "1"
    Set-Alias gcc "C:\Path\To\arm-none-eabi-gcc-13.3.1.exe"

    & "C:\Users\riley\myvenv\Scripts\Activate.ps1"
    try {
    oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" | Invoke-Expression
  7. ril3y revised this gist Oct 31, 2024. No changes.
  8. ril3y revised this gist Oct 31, 2024. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,10 @@
    $env:VIRTUAL_ENV_DISABLE_PROMPT = "1"
    & "C:\Users\riley\myvenv\Scripts\Activate.ps1"
    oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" | Invoke-Expression
    try {
    oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" | Invoke-Expression
    } catch {
    Write-Host "Failed to initialize Oh-My-Posh: $_" -ForegroundColor Red
    }


    function Disable-NewsAndInterests {
  9. ril3y revised this gist Oct 31, 2024. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -209,8 +209,14 @@ function which {
    [string]$CommandName
    )

    # Split the PATH environment variable into an array of directories
    $pathDirs = $env:PATH -split ';'
    # Check if the command is a path (relative or absolute)
    if (Test-Path $CommandName) {
    Write-Output (Get-Item $CommandName).FullName
    return
    }

    # Split the PATH environment variable into an array of directories, ignoring empty ones
    $pathDirs = $env:PATH -split ';' | Where-Object { $_ -ne "" }

    # Check each directory for the command
    foreach ($dir in $pathDirs) {
    @@ -233,6 +239,5 @@ function which {
    }

    # If no match was found
    Write-Host "$CommandName: command not found" -ForegroundColor Red
    Write-Host "${CommandName}: command not found" -ForegroundColor Red
    }

  10. ril3y revised this gist Oct 30, 2024. 1 changed file with 33 additions and 0 deletions.
    33 changes: 33 additions & 0 deletions personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -203,3 +203,36 @@ function tail {
    # Output the last $Lines lines from the file
    Get-Content -Path $FilePath | Select-Object -Skip $startLine
    }

    function which {
    param (
    [string]$CommandName
    )

    # Split the PATH environment variable into an array of directories
    $pathDirs = $env:PATH -split ';'

    # Check each directory for the command
    foreach ($dir in $pathDirs) {
    $filePath = Join-Path -Path $dir -ChildPath $CommandName

    # Check for an exact match, or with common executable extensions
    if (Test-Path $filePath) {
    Write-Output $filePath
    return
    }

    # On Windows, check for common executable extensions
    foreach ($ext in ".exe", ".bat", ".cmd", ".ps1") {
    $extendedPath = "$filePath$ext"
    if (Test-Path $extendedPath) {
    Write-Output $extendedPath
    return
    }
    }
    }

    # If no match was found
    Write-Host "$CommandName: command not found" -ForegroundColor Red
    }

  11. ril3y revised this gist Oct 30, 2024. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -180,3 +180,26 @@ if (Test-Path($ChocolateyProfile)) {
    Import-Module "$ChocolateyProfile"
    }


    function tail {
    param (
    [string]$FilePath,
    [int]$Lines = 10 # Default to the last 10 lines
    )

    # Check if the file exists
    if (-not (Test-Path $FilePath)) {
    Write-Host "File not found: $FilePath" -ForegroundColor Red
    return
    }

    # Get the total number of lines in the file
    $totalLines = (Get-Content -Path $FilePath).Count

    # Calculate the starting line (total lines - lines to display)
    $startLine = $totalLines - $Lines
    if ($startLine -lt 0) { $startLine = 0 } # Ensure we don't have negative start

    # Output the last $Lines lines from the file
    Get-Content -Path $FilePath | Select-Object -Skip $startLine
    }
  12. ril3y revised this gist Oct 30, 2024. 1 changed file with 3 additions and 75 deletions.
    78 changes: 3 additions & 75 deletions personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,76 +1,3 @@
    # Path for storing the last checksum
    $hashFile = "$env:USERPROFILE\.profile_hash"
    # Path for storing the Gist URL
    $urlFile = "$env:USERPROFILE\.profile_gist_url"

    # Function to compute the checksum of a string
    function Get-StringHash {
    param([string]$input)
    $hashAlgorithm = [System.Security.Cryptography.HashAlgorithm]::Create("SHA256")
    $bytes = [System.Text.Encoding]::UTF8.GetBytes($input)
    $hashBytes = $hashAlgorithm.ComputeHash($bytes)
    -join ($hashBytes | ForEach-Object { "{0:x2}" -f $_ })
    }

    # Function to get or ask for the Gist URL
    function Get-GistUrl {
    if (Test-Path $urlFile) {
    # Read the Gist URL from file if it exists
    return Get-Content $urlFile
    } else {
    # Ask the user for the Gist URL and save it
    $url = Read-Host "Enter the GitHub Gist URL (raw)"
    Set-Content -Path $urlFile -Value $url -Force
    return $url
    }
    }

    # Function to download the remote profile and compare hashes
    function Check-ProfileUpdate {
    try {
    # Get the Gist URL from the user or file
    $gistUrl = Get-GistUrl

    # Download the raw Gist content
    $remoteProfile = Invoke-WebRequest -Uri $gistUrl -UseBasicParsing
    $remoteContent = $remoteProfile.Content

    # Compute the hash of the remote content
    $remoteHash = Get-StringHash -input $remoteContent

    # If the local hash file exists, read the stored hash
    if (Test-Path $hashFile) {
    $localHash = Get-Content $hashFile
    } else {
    $localHash = ""
    }

    # Compare hashes
    if ($remoteHash -ne $localHash) {
    # Hashes are different, ask the user if they want to update the profile
    $userInput = Read-Host "New profile detected. Do you want to update? (Y/N)"
    if ($userInput -eq "Y" -or $userInput -eq "y") {
    # Update the local profile
    Set-Content -Path $PROFILE -Value $remoteContent -Force
    # Update the stored hash
    Set-Content -Path $hashFile -Value $remoteHash -Force
    Write-Host "Profile updated."
    } else {
    Write-Host "Profile update skipped."
    }
    } else {
    Write-Host "Profile is already up to date."
    }
    } catch {
    Write-Host "Failed to check for profile update: $_"
    }
    }

    # Run the update check on profile load
    Check-ProfileUpdate



    $env:VIRTUAL_ENV_DISABLE_PROMPT = "1"
    & "C:\Users\riley\myvenv\Scripts\Activate.ps1"
    oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" | Invoke-Expression
    @@ -91,7 +18,7 @@ function Disable-NewsAndInterests {



    function Test-InternetSpeed {
    function speedtest {
    $speedTestResult = speedtest --format=json
    $speedTestResultObj = $speedTestResult | ConvertFrom-Json

    @@ -138,7 +65,7 @@ function Disable-EdgeSearch {


    function gh {
    cd C:\\Users\\riley\\Documents\\GitHub\\
    cd $EVN:USERPROFILE\\Documents\\GitHub\\
    }

    function btop {
    @@ -252,3 +179,4 @@ $ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
    if (Test-Path($ChocolateyProfile)) {
    Import-Module "$ChocolateyProfile"
    }

  13. ril3y revised this gist Oct 29, 2024. No changes.
  14. ril3y revised this gist Oct 29, 2024. 1 changed file with 72 additions and 0 deletions.
    72 changes: 72 additions & 0 deletions personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,75 @@
    # Path for storing the last checksum
    $hashFile = "$env:USERPROFILE\.profile_hash"
    # Path for storing the Gist URL
    $urlFile = "$env:USERPROFILE\.profile_gist_url"

    # Function to compute the checksum of a string
    function Get-StringHash {
    param([string]$input)
    $hashAlgorithm = [System.Security.Cryptography.HashAlgorithm]::Create("SHA256")
    $bytes = [System.Text.Encoding]::UTF8.GetBytes($input)
    $hashBytes = $hashAlgorithm.ComputeHash($bytes)
    -join ($hashBytes | ForEach-Object { "{0:x2}" -f $_ })
    }

    # Function to get or ask for the Gist URL
    function Get-GistUrl {
    if (Test-Path $urlFile) {
    # Read the Gist URL from file if it exists
    return Get-Content $urlFile
    } else {
    # Ask the user for the Gist URL and save it
    $url = Read-Host "Enter the GitHub Gist URL (raw)"
    Set-Content -Path $urlFile -Value $url -Force
    return $url
    }
    }

    # Function to download the remote profile and compare hashes
    function Check-ProfileUpdate {
    try {
    # Get the Gist URL from the user or file
    $gistUrl = Get-GistUrl

    # Download the raw Gist content
    $remoteProfile = Invoke-WebRequest -Uri $gistUrl -UseBasicParsing
    $remoteContent = $remoteProfile.Content

    # Compute the hash of the remote content
    $remoteHash = Get-StringHash -input $remoteContent

    # If the local hash file exists, read the stored hash
    if (Test-Path $hashFile) {
    $localHash = Get-Content $hashFile
    } else {
    $localHash = ""
    }

    # Compare hashes
    if ($remoteHash -ne $localHash) {
    # Hashes are different, ask the user if they want to update the profile
    $userInput = Read-Host "New profile detected. Do you want to update? (Y/N)"
    if ($userInput -eq "Y" -or $userInput -eq "y") {
    # Update the local profile
    Set-Content -Path $PROFILE -Value $remoteContent -Force
    # Update the stored hash
    Set-Content -Path $hashFile -Value $remoteHash -Force
    Write-Host "Profile updated."
    } else {
    Write-Host "Profile update skipped."
    }
    } else {
    Write-Host "Profile is already up to date."
    }
    } catch {
    Write-Host "Failed to check for profile update: $_"
    }
    }

    # Run the update check on profile load
    Check-ProfileUpdate



    $env:VIRTUAL_ENV_DISABLE_PROMPT = "1"
    & "C:\Users\riley\myvenv\Scripts\Activate.ps1"
  15. ril3y created this gist Oct 29, 2024.
    182 changes: 182 additions & 0 deletions personal_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,182 @@

    $env:VIRTUAL_ENV_DISABLE_PROMPT = "1"
    & "C:\Users\riley\myvenv\Scripts\Activate.ps1"
    oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" | Invoke-Expression


    function Disable-NewsAndInterests {
    # Disable Windows Widgets by setting the registry value
    $registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
    $valueName = "TaskbarDa"
    $value = 0

    # Set the registry value to disable Widgets
    Set-ItemProperty -Path $registryPath -Name $valueName -Value $value

    # Restart Explorer to apply changes
    Stop-Process -Name explorer -Force
    }



    function Test-InternetSpeed {
    $speedTestResult = speedtest --format=json
    $speedTestResultObj = $speedTestResult | ConvertFrom-Json

    $downloadSpeedMbps = [math]::round($speedTestResultObj.download.bandwidth / 125000, 2) # Convert to Mbps
    $uploadSpeedMbps = [math]::round($speedTestResultObj.upload.bandwidth / 125000, 2) # Convert to Mbps
    $pingMs = $speedTestResultObj.ping.latency

    Write-Host "Download Speed: $downloadSpeedMbps Mbps"
    Write-Host "Upload Speed: $uploadSpeedMbps Mbps"
    Write-Host "Ping: $pingMs ms"
    }



    # Call the function
    #Disable-NewsAndInterests

    function Disable-EdgeSearch {
    # Set registry paths for disabling Bing search and Cortana web integration
    $registryPath = "HKCU:\Software\Policies\Microsoft\Windows\Explorer"
    $registryPath2 = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search"

    # Check if the key exists, if not, create it
    if (-not (Test-Path $registryPath)) {
    New-Item -Path $registryPath -Force
    }

    if (-not (Test-Path $registryPath2)) {
    New-Item -Path $registryPath2 -Force
    }

    # Disable web search and Cortana
    Set-ItemProperty -Path $registryPath -Name "DisableSearchBoxSuggestions" -Value 1 -Type DWord
    Set-ItemProperty -Path $registryPath2 -Name "BingSearchEnabled" -Value 0 -Type DWord
    Set-ItemProperty -Path $registryPath2 -Name "CortanaConsent" -Value 0 -Type DWord

    # Restart Explorer to apply changes
    Stop-Process -Name explorer -Force
    }

    # Call the function
    #Disable-EdgeSearch



    function gh {
    cd C:\\Users\\riley\\Documents\\GitHub\\
    }

    function btop {
    btop4win
    }

    function reboot {
    Restart-Computer
    }


    # Function to disable the Caps Lock key
    function Disable-CapsLock {
    $registryPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout"
    $scancodeMapName = "Scancode Map"

    # Check if the key exists
    if (-not (Test-Path $registryPath)) {
    Write-Host "Registry path does not exist."
    return
    }

    # Create the scancode map binary value to disable Caps Lock
    $scancodeMap = [byte[]](
    0x00, 0x00, 0x00, 0x00, # Header
    0x00, 0x00, 0x00, 0x00, # Header
    0x02, 0x00, 0x00, 0x00, # Entries (one remap)
    0x00, 0x00, 0x3A, 0x00, # Disable Caps Lock (Scancode for CapsLock = 0x3A)
    0x00, 0x00, 0x00, 0x00 # End of the map
    )

    # Set the registry key to disable Caps Lock
    Set-ItemProperty -Path $registryPath -Name $scancodeMapName -Value $scancodeMap
    Write-Host "Caps Lock key has been disabled. Please restart your system for the change to take effect."
    }

    function Remap-CapsLock-To-Tab {
    $registryPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout"
    $scancodeMapName = "Scancode Map"

    # Check if the key exists
    if (-not (Test-Path $registryPath)) {
    Write-Host "Registry path does not exist."
    return
    }

    # Create the scancode map binary value to remap Caps Lock to Tab
    $scancodeMap = [byte[]](
    0x00, 0x00, 0x00, 0x00, # Header
    0x00, 0x00, 0x00, 0x00, # Header
    0x02, 0x00, 0x00, 0x00, # Number of entries (one remap)
    0x0F, 0x00, 0x3A, 0x00, # Remap Caps Lock (0x3A) to Tab (0x0F)
    0x00, 0x00, 0x00, 0x00 # End of the map
    )

    # Set the registry key to remap Caps Lock to Tab
    Set-ItemProperty -Path $registryPath -Name $scancodeMapName -Value $scancodeMap
    Write-Host "Caps Lock key has been remapped to Tab. Please restart your system for the change to take effect."
    }

    # Run the function
    #Remap-CapsLock-To-Tab


    # Call the function to disable Caps Lock
    # Disable-CapsLock


    function easyeda {
    param (
    [string]$OutputPath = 'X:\Dropbox\Kicad\test'
    )

    # Function to get the clipboard text
    function Get-ClipboardText {
    Add-Type -AssemblyName PresentationCore
    return [Windows.Clipboard]::GetText()
    }

    # Get clipboard text
    $clipboardText = Get-ClipboardText

    # Define regex pattern for part number: C followed by up to 8 digits
    $pattern = "^C\d{1,8}$"

    # Check if clipboard contains a valid part number
    if ($clipboardText -match $pattern) {
    $partNumber = $clipboardText
    Write-Host "Found valid part number in clipboard: $partNumber"
    } else {
    # Prompt user for part number if clipboard doesn't have a valid value
    $partNumber = Read-Host "Clipboard does not contain a valid part number. Please enter the LCSC part number (e.g., C1848578)"
    }

    # Construct the command using the part number
    $command = "easyeda2kicad.exe --lcsc_id $partNumber --full --output '$OutputPath'"

    # Run the command
    Invoke-Expression $command

    # Inform the user that the conversion is complete
    Write-Host "Conversion complete. Output saved to $OutputPath"
    }

    # Import the Chocolatey Profile that contains the necessary code to enable
    # tab-completions to function for `choco`.
    # Be aware that if you are missing these lines from your profile, tab completion
    # for `choco` will not function.
    # See https://ch0.co/tab-completion for details.
    $ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
    if (Test-Path($ChocolateyProfile)) {
    Import-Module "$ChocolateyProfile"
    }