Skip to content

Instantly share code, notes, and snippets.

View bsdayo's full-sized avatar
💭
Reimagining my life

bsdayo bsdayo

💭
Reimagining my life
View GitHub Profile
@bsdayo
bsdayo / pwsh-bash-completion.ps1
Created November 12, 2024 23:47
Make Bash's autocompletion available to PowerShell on Linux.
# Add this snippet to your $PROFILE to make Bash's autocompletion available to PowerShell on Linux.
# Warning: adds ~500ms initialization time.
# References: https://brbsix.github.io/2015/11/29/accessing-tab-completion-programmatically-in-bash/
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/register-argumentcompleter
# Find all commands
$commands = bash -c 'source /usr/share/bash-completion/bash_completion && complete' | awk '{ print $NF }'
$commands += ls /usr/share/bash-completion/completions
$commands | ForEach-Object {
@bsdayo
bsdayo / make-shortcut.ps1
Last active May 21, 2024 01:23
Super "Windows shortcut" maker with embedded icon
param(
[Parameter(Mandatory)] [string] $Command,
[Parameter(Mandatory)] [string] $IconFile,
[string] $Output,
[switch] $Keep
)
(Get-Content -Encoding UTF8 template.c) -replace "COMMAND_PLACEHOLDER", ($Command -replace '\\', '\\') | Out-File -Encoding UTF8 temp.c
"icon ICON `"$($IconFile -replace '\\', '\\')`"" | Out-File -Encoding UTF8 temp.rc
public class DynamicJsonConverter : JsonConverter<dynamic>
{
public override dynamic Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.True)
{
return true;
}
@TheSnowfield
TheSnowfield / SandBox.cs
Last active April 22, 2025 13:18
Dynamically run C# code in the same context
public class SandBox
{
private ScriptState<object> _globalState;
public SandBox()
{
// Create initial script
var script = CSharpScript.Create(string.Empty, ScriptOptions.Default);
{
// Create an empty state