Skip to content

Instantly share code, notes, and snippets.

@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
@hunandy14
hunandy14 / chrome.adm
Created January 10, 2022 11:53
Google Chrome 如何安裝第三方擴充插件。20220110備份檔案,詳細說明請看部落格文章https://bit.ly/31FSFiW
; chrome version: 97.0.4692.71
CLASS MACHINE
CATEGORY !!Google:Cat_Google
CATEGORY !!googlechrome
KEYNAME "Software\Policies\Google\Chrome"
CATEGORY !!GoogleCast_Category
POLICY !!EnableMediaRouter_Policy
#if version >= 4
SUPPORTED !!SUPPORTED_WIN7
@hunandy14
hunandy14 / split_sting.cpp
Created May 22, 2021 17:26
字串切割物件
/*
2021-05-23
部落格說明 https://charlottehong.blogspot.com/2021/05/cc.html
*/
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
@hunandy14
hunandy14 / ReadFile.hpp
Last active May 22, 2021 16:37
C/C++ 依照特定格式 讀取檔案並 切割字串
/*
2021-05-19
詳細的說明可以參考我的部落格
https://charlottehong.blogspot.com/2021/05/cc.html
*/
#pragma
#include <vector>
#include <fstream>
#include <string>
#include <string_view>