Skip to content

Instantly share code, notes, and snippets.

@hunandy14
hunandy14 / run_nginx_site
Last active August 14, 2025 13:54
快速部署 nginx 容器網站
#!/usr/bin/env bash
# =======================================
# 🐳 run_nginx_site 函式
# =======================================
# 用途:快速部署 nginx 容器網站
#
# 🔧 支援參數(具名與位置皆可):
# --domain <名稱> ✅ 必填(位置參數1),預設為 mysite.com
# --port <數字> ➕ 可選(位置參數2),預設為 8080
@hunandy14
hunandy14 / X509Certificate2.psm1
Created July 15, 2025 15:36 — forked from heaths/X509Certificate2.psm1
X509Certificate2 PowerShell module
#Requires -Version 6.0
using namespace System.Security.Cryptography
using namespace System.Security.Cryptography.X509Certificates
using namespace System.Text
<#
.Synopsis
Generate an X509 v3 certificate.
@hunandy14
hunandy14 / sarchdb.sql
Created January 23, 2025 15:24
SQLServer反向搜索字串在哪個表中或視圖中
-- 宣告搜尋的字串和結果表格
DECLARE @TargetString nvarchar(255) = '<要檢索的字串>';
DECLARE @SearchResults TABLE (
TableType nvarchar(10),
FullTableName nvarchar(500),
ColumnName nvarchar(370),
ColumnValue nvarchar(3630)
);
-- 設定交易隔離等級為 READ UNCOMMITTED
@hunandy14
hunandy14 / tree.sh
Created May 29, 2024 10:11
This script shows the directory tree, color-codes files and folders, and optionally displays file sizes and hidden files.
#!/bin/bash
# This script displays the directory tree structure, color-codes files and folders,
# and optionally shows file sizes and hidden files.
# Usage:
# tree.sh [-a] [-s] <directory>
# -a Show all files including hidden files
# -s Show file sizes
@hunandy14
hunandy14 / Install-OpenSSH.ps1
Last active October 16, 2024 04:52
自動爬蟲抓取最新版本OpenSSH並安裝
# 獲取最新版本OpenSSHUrl
function Get-OpenSSHAsset {
param (
[Parameter(Position = 0, ParameterSetName = "")]
[ValidateSet(
'OpenSSH-Win32.zip',
'OpenSSH-Win64.zip',
'OpenSSH-Win32.msi',
'OpenSSH-Win64.msi'
)]
@hunandy14
hunandy14 / Hybrid.cmd
Last active September 29, 2023 05:41
PowerShell 與 Bat 的混合代碼
@(set "0=%~f0"^)#) & set "1=%*" & setlocal enabledelayedexpansion & powershell -nop -c "iex([io.file]::ReadAllText($env:0));$Host.SetShouldExit($LastExitCode);Exit $LastExitCode" & exit /b !errorlevel!
Write-Host "by PSVersion::" $PSVersionTable.PSVersion
Write-Host "Command is '$env:0 $env:1'"
Exit 0
@hunandy14
hunandy14 / Install_Maven.ps1
Last active September 10, 2023 09:22
基於官網最新版自動爬蟲安裝最新版本
# 檢查鏈接是否有效
function Test-URI {
param (
[Parameter(Position=0, Mandatory)]
[string] $Uri
)
try {
# 嘗試發送 HEAD 請求
$response = Invoke-WebRequest -Uri $Uri -Method Head -TimeoutSec 10
# 檢查 HTTP 狀態碼是否為 200
@hunandy14
hunandy14 / TestCopyTime.ps1
Last active June 20, 2022 15:09
測試壓縮複製與直接複製的時間差異
# 格式化時間單位
function FormatTimes {
param (
[Parameter(Position = 0, ParameterSetName = "", Mandatory=$false)]
[double] $Time=0,
[Parameter(Position = 1, ParameterSetName = "", Mandatory=$false)]
[double] $Digit=3
)
# 設定單位
$Unit_Type = 'ms'
@hunandy14
hunandy14 / Edge_GlobalMediaControls.ps1
Last active January 13, 2022 04:58
Edge 開啟 Global Media Control 模式
# https://www.reddit.com/r/edge/comments/s0dmqz/global_media_controls_missing_in_970107255
# 新版本的被禁用功能了 只能從啟動參數處理了...
$shortcutName = "Edge_MediaControls"
$edgePath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
$edgeArgs = "--enable-features=GlobalMediaControls"
$shell = New-Object -ComObject WScript.Shell
$userDsk = [Environment]::GetFolderPath("Desktop")
@hunandy14
hunandy14 / Install_Gpedit.ps1
Created January 10, 2022 13:18
讓 Windows10/11 Home 家用版 新增 支援 gpedit.msc 本機群組原則編輯器。部落格說明文章 https://bit.ly/3zJJCdF
((Get-ChildItem $env:SystemRoot\servicing\Packages)-match("(Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3)(.*?)(\.mum)|(Microsoft-Windows-GroupPolicy-ClientTools-Package~3)(.*?)(\.mum)")).FullName|ForEach-Object{dism /online /norestart /add-package:$_};gpedit.msc