Skip to content

Instantly share code, notes, and snippets.

View huanlin's full-sized avatar

Michael Tsai huanlin

View GitHub Profile
@huanlin
huanlin / VeeamBackupAllVMs.ps1
Last active September 11, 2025 10:03
Powershell Script for Automatic Backup with Veeam Backup Free Edition
<#
Utility functions for deleting old files.
Source: http://blog.danskingdom.com/powershell-functions-to-delete-old-files-and-empty-directories/
#>
# Function to remove all empty directories under the given path.
# If -DeletePathIfEmpty is provided the given Path directory will also be deleted if it is empty.
# If -OnlyDeleteDirectoriesCreatedBeforeDate is provided, empty folders will only be deleted if they were created before the given date.
# If -OnlyDeleteDirectoriesNotModifiedAfterDate is provided, empty folders will only be deleted if they have not been written to after the given date.
function Remove-EmptyDirectories([parameter(Mandatory)][ValidateScript({Test-Path $_})][string] $Path, [switch] $DeletePathIfEmpty, [DateTime] $OnlyDeleteDirectoriesCreatedBeforeDate = [DateTime]::MaxValue, [DateTime] $OnlyDeleteDirectoriesNotModifiedAfterDate = [DateTime]::MaxValue, [switch] $OutputDeletedPaths, [switch] $WhatIf)
@huanlin
huanlin / swaggerui.html
Created June 3, 2025 15:50
Enable SwaggerUI Deep Linking in Docsy
{{ $original := .Get "src" }}
<div id="docsy_swagger_ui"></div>
<script>
window.onload = function () {
const ui = SwaggerUIBundle({
url: {{ $original | relURL }},
dom_id: '#docsy_swagger_ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
@huanlin
huanlin / parse_hugo_md.go
Last active September 24, 2024 21:14
Parsing a Hugo markdown file
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"regexp"
"gopkg.in/yaml.v2"
@huanlin
huanlin / Example.cs
Last active January 3, 2024 15:42
Helper classes for change printer settings with P/Invoke.
void GetDefaultPaperSize()
{
var devMode = PInvoke.PrinterHelper.GetPrinterDevMode(null);
string s = String.Format("{0} : {1} x {2}", devMode.dmPaperSize, devMode.dmPaperWidth, devMode.dmPaperLength);
Console.WriteLine(s);
}
void SetDefaultPaperSize()
{
string formName = "User defined";
@huanlin
huanlin / azure-openai-example.cs
Created October 14, 2023 12:48
Azure OpenAI C# example
using Azure;
using Azure.AI.OpenAI;
var key = "0bc0xxxxxxxxxxxxxxxx7971";
var endpoint = "https://my-demo-ai-app.openai.azure.com/";
var deployment = "turbo-michael-35";
Console.Write("Ask me anything: ");
var prompt = Console.ReadLine();
@huanlin
huanlin / openai-request-example.txt
Last active October 14, 2023 12:36
OpenAI API request example
@API_KEY = 0bc0xxxxxxxxxxxx7971
@RESOURCE_NAME = my-demo-ai-app
@DEPLOYMENT_ID = turbo-michael-35
### OpenAI Test
POST https://{{RESOURCE_NAME}}.openai.azure.com/openai/deployments/{{DEPLOYMENT_ID}}/chat/completions?api-version=2023-05-15
api-key: {{API_KEY}}
{
"messages": [
@huanlin
huanlin / mudblazor-fonts-and-css.html
Created December 22, 2022 06:13
mudblazor-fonts-and-css.html
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
@huanlin
huanlin / MainLayout.razor
Created December 16, 2022 08:32
Blazor app MainLayout.razor
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<NavMenu />
</div>
<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
@huanlin
huanlin / Index.razor
Created December 16, 2022 08:28
Blazor app Index.razor
@page "/"
<PageTitle>Index</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />
@huanlin
huanlin / App.razor
Created December 16, 2022 08:24
Blazor App.razor
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>