Skip to content

Instantly share code, notes, and snippets.

View doggy8088's full-sized avatar
🙂
Giving is a reward in itself

Will 保哥 doggy8088

🙂
Giving is a reward in itself
View GitHub Profile
@doggy8088
doggy8088 / README.md
Last active April 9, 2023 12:40 — forked from Trenly/README.md
Install Winget to the Windows Sandbox Base Image
View README.md

This powershell script modifies the Base Image, or the Virtual Hard Disk, which the Windows Sandbox launches upon startup. It will copy the required files to the sandbox and add a registry key which will install them upon startup. By default the script will install the latest stable release of Winget. You can specify to use the latest pre-release with the -PreRelease switch.

When a new version of Winget is released, run this script again to update the installation in the sandbox to the latest version

View IE_README.md
  1. 開啟 Windows PowerShell

  2. IE 函式加入到 $PROFILE 之中

    [System.IO.Directory]::CreateDirectory([System.IO.Path]::GetDirectoryName($PROFILE))
    notepad $PROFILE
View TimeOnlyConverter.cs
public class TimeOnlyConverter : JsonConverter<TimeOnly>
{
private readonly string serializationFormat;
public TimeOnlyConverter() : this(null) { }
public TimeOnlyConverter(string? serializationFormat)
{
this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
}
View DynamicJsonConverter.cs
public class DynamicJsonConverter : JsonConverter<dynamic>
{
public override dynamic Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.True)
{
return true;
}
View DateOnlyConverter.cs
public class DateOnlyConverter : JsonConverter<DateOnly>
{
private readonly string serializationFormat;
public DateOnlyConverter() : this(null) { }
public DateOnlyConverter(string? serializationFormat)
{
this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
}
@doggy8088
doggy8088 / Program.cs
Created November 29, 2021 16:48
Serilog 與 ASP.NET Core 6.0 範例
View Program.cs
using Serilog;
using Serilog.Events;
var builder = WebApplication.CreateBuilder(args);
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.CreateLogger();
try
View $PROFILE.ps1
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadLine
}
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
View $PROFILE_Cmdlets_Functions.ps1
# 移除兩個不實用的 Cmdlet Aliases
If (Test-Path Alias:curl) {Remove-Item Alias:curl}
If (Test-Path Alias:wget) {Remove-Item Alias:wget}
# 快速開啟 c:\windows\system32\drivers\etc\hosts 檔案
function hosts { notepad c:\windows\system32\drivers\etc\hosts }
# 快速產生一組亂數密碼 (預設會產生 10 個字元的密碼)
function New-Password {
<#
View $PROFILE_ArgumentCompleter.ps1
# winget parameter completion
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
$Local:word = $wordToComplete.Replace('"', '""')
$Local:ast = $commandAst.ToString().Replace('"', '""')
winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
View ohmyposhv3-will.omp.json
{
"final_space": true,
"console_title": true,
"console_title_style": "folder",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"horizontal_offset": 0,
"vertical_offset": 0,