Skip to content

Instantly share code, notes, and snippets.

from functools import partial
def return_arg(func, /, arg):
func(arg)
return arg
def return_args(func, /, *args):
func(*args)
@travisclagrone
travisclagrone / pokemon_unite_master_match_expected_ranking_change.py
Last active November 7, 2021 00:21
Pokemon Unite master ranking converges to zero
from statistics import mean
# average win/loss rate of player against other humans/bots (i.e. it is/isn't a bot game)
VS_HUMANS_WIN_RATE = 1 / 2 # expected long-run average in a true ELO system
VS_HUMANS_LOSE_RATE = 1 - HUMAN_WIN_RATE
VS_BOTS_WIN_RATE = 1 # ideal assumption (i.e. unrealistic)
VS_BOTS_LOSE_RATE = 1 - BOT_LOSE_RATE
# expected change in Master ranking of player against humans/bots after a win/loss
@travisclagrone
travisclagrone / WindowsPowerShellEncodingProfile.ps1
Last active February 4, 2021 04:33
Windows PowerShell profile snippet that fixes the antiquated/inconsistent encoding conventions in PowerShell <=5.1 by defaulting (almost) everything to true UTF8.
# Preference Variable
Set-Variable -Name 'OutputEncoding' -Value ([System.Text.Encoding]::UTF8) `
-Scope Global -Option AllScope, ReadOnly -Force -ErrorAction Continue
# These commands' Encoding parameter are enumly typed.
$global:PSDefaultParameterValues['Add-Content:Encoding'] = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::UTF8
$global:PSDefaultParameterValues['Get-Content:Encoding'] = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::UTF8
$global:PSDefaultParameterValues['Set-Content:Encoding'] = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::UTF8
# These commands' Encoding parameter are stringly typed.
@travisclagrone
travisclagrone / ConnectMicrosoftGraph.csx
Last active January 5, 2021 00:03
.NET Core (C#) example of Microsoft Graph connection, authentication, and querying.
#! "netcoreapp3.1"
#r "nuget: Microsoft.Graph"
#r "nuget: Microsoft.Graph.Core"
#r "nuget: Microsoft.Graph.Auth"
#r "nuget: Microsoft.Identity.Client"
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@travisclagrone
travisclagrone / Mount-DBFS.ps1
Created September 21, 2020 18:14
Mount-DBFS.ps1 mounts a storage account to a Databricks' workspace DBFS using a remotely-executable self-contained PowerShell Core script
#Requires -Version 6.2
<#PSScriptInfo
.VERSION 1.0.0-20200222T0102366618Z
.GUID ce06a265-573d-4557-a66b-dfe9fff8d7a1
.AUTHOR Travis.LaGrone@microsoft.com
@travisclagrone
travisclagrone / geo2ofs.py
Last active November 27, 2021 11:55
Python function to convert a geographic location to a timezone offset
from datetime import datetime, timedelta, tzinfo
from dateutil.tz import gettz
from uuid import uuid4
from geopy.geocoders import Nominatim
from timezonefinder import TimezoneFinder
nomi = Nominatim(user_agent=str(uuid4()))
tzf = TimezoneFinder()
@travisclagrone
travisclagrone / Hashtable.Types.ps1xml
Last active January 5, 2021 00:03
PowerShell type extensions
<Types>
<Type>
<Name>System.Collections.Hashtable</Name>
<Members>
<ScriptMethod>
<Name>AddRange</Name>
<Script>
[OutputType()]
param([hashtable] $other)
@travisclagrone
travisclagrone / requirements.psd1
Last active September 7, 2021 07:44
PowerShell dependencies (PSDepend)
@{
PSDependOptions = @{}
#region Interactive
# Color
'PSColor' = @{
Tags = @(
'interactive'
'color'
@travisclagrone
travisclagrone / GetHelpParameterArgumentCompleter.ps1
Last active November 27, 2021 11:57
PowerShell script to register an intelligent argument completer for the -Parameter parameter of the Get-Help command, based upon the value of the -Name parameter. (i.e. it now suggests names of parameters of the corresponding command instead of random filesystem items)
Register-ArgumentCompleter -CommandName 'Get-Help' -ParameterName 'Parameter' -ScriptBlock {
[OutputType([System.Management.Automation.CompletionResult])] # zero to many
param(
[string] $commandName,
[string] $parameterName,
[string] $wordToComplete,
[System.Management.Automation.Language.CommandAst] $commandAst,
[System.Collections.IDictionary] $fakeBoundParameters
)
@travisclagrone
travisclagrone / Get-Noun.ps1
Created January 9, 2020 22:15
PowerShell noun-centric command information
class NounInfo {
[string] $Noun
[string[]] $Verbs
[System.Management.Automation.PSModuleInfo[]] $Modules
[System.Management.Automation.CommandInfo[]] $Commands
}
Update-TypeData -Force `
-TypeName 'NounInfo' `
-DefaultKeyPropertySet 'Noun' `