[{"content":"In Golang\u0026rsquo;s standard library sync, sync.Mutex is a basic mutual exclusion lock used to protect shared resources and prevent multiple goroutines from simultaneously accessing or modifying data. The sync package provides several types of locks and synchronization mechanisms. Here\u0026rsquo;s a comprehensive overview of the main lock types and their differences:\n1. sync.Mutex (Mutual Exclusion Lock) sync.Mutex is the most basic lock type used to protect critical sections, ensuring only one goroutine can enter the locked area.\nCharacteristics Exclusive lock: When a goroutine acquires the lock, other goroutines must wait until it\u0026rsquo;s released (using Unlock()). Suitable for write operations (modifying shared resources) or scenarios requiring non-concurrent execution. Usage var mu sync.Mutex mu.Lock() // Lock critical section // Critical section code mu.Unlock() // Unlock Important Notes Forgetting to release the lock (due to goroutine crash or logic errors) can lead to deadlocks. Does not support reentrant locking: If the same goroutine attempts to acquire the lock again, it will cause a deadlock.\n2. sync.RWMutex (Read-Write Lock) sync.RWMutex supports multiple readers and single writer, ideal for read-heavy scenarios.\nCharacteristics Read Lock (RLock): Multiple goroutines can acquire read locks simultaneously. Write locks are blocked when read locks are held. Write Lock (Lock): Exclusive lock; all read and write operations are blocked when a write lock is held. Best for scenarios with significantly more read operations than write operations.\nUsage var rw sync.RWMutex // Read operation rw.RLock() // Acquire read lock // Critical section code (reading shared resource) rw.RUnlock() // Release read lock // Write operation rw.Lock() // Acquire write lock // Critical section code (modifying shared resource) rw.Unlock() // Release write lock Important Notes Like sync.Mutex, failing to release locks leads to deadlocks. Write locks have higher priority than read locks; subsequent read operations are blocked when write operations request the lock.\n3. sync.Cond (Condition Variable) sync.Cond is a synchronization mechanism based on conditions, allowing goroutines to wait until specific conditions are met.\nCharacteristics Used for implementing advanced synchronization logic (e.g., producer-consumer pattern). Typically used in conjunction with sync.Mutex.\nUsage var mu sync.Mutex cond := sync.NewCond(\u0026amp;mu) go func() { mu.Lock() cond.Wait() // Wait for condition fmt.Println(\u0026#34;Condition met\u0026#34;) mu.Unlock() }() mu.Lock() cond.Signal() // Wake up one waiting goroutine mu.Unlock() Important Notes Wait() must be called after Lock() to avoid runtime errors. Signal() wakes one waiting goroutine, while Broadcast() wakes all waiting goroutines.\n4. sync.Once (One-time Execution) sync.Once ensures a piece of code is executed only once, regardless of how many goroutines attempt to execute it.\nCharacteristics Ideal for initialization operations (e.g., singleton pattern). Thread-safe and efficient.\nUsage var once sync.Once func initFunction() { fmt.Println(\u0026#34;Initialized\u0026#34;) } func main() { for i := 0; i \u0026lt; 10; i++ { go func() { once.Do(initFunction) // Ensures single execution }() } } 5. sync.Map (Concurrent-safe Map) sync.Map is Go\u0026rsquo;s built-in concurrent-safe map implementation using an efficient read-write separation strategy.\nCharacteristics No manual locking required; synchronization handled internally. Suitable for read-heavy scenarios.\nUsage var m sync.Map // Store data m.Store(\u0026#34;key\u0026#34;, \u0026#34;value\u0026#34;) // Load data value, ok := m.Load(\u0026#34;key\u0026#34;) if ok { fmt.Println(value) } // Delete data m.Delete(\u0026#34;key\u0026#34;) Important Notes Not suitable for frequent write operations as they can decrease efficiency. Consider using regular map with sync.Mutex for high-frequency operations.\n6. Custom Locks (Channel-based) Developers can implement custom locks using channels:\nSimple Channel Lock Implementation type ChanLock struct { ch chan struct{} } func NewChanLock() *ChanLock { return \u0026amp;ChanLock{ch: make(chan struct{}, 1)} } func (l *ChanLock) Lock() { l.ch \u0026lt;- struct{}{} } func (l *ChanLock) Unlock() { \u0026lt;-l.ch } func main() { lock := NewChanLock() lock.Lock() // Critical section code lock.Unlock() } Differences and Selection Guidelines sync.Mutex vs sync.RWMutex: Use sync.RWMutex when most operations are reads for better performance.\nUse sync.Mutex when read/write ratios are similar or write operations are frequent.\nsync.Cond vs Other Locks: Use sync.Cond when waiting for specific conditions.\nPrefer sync.Mutex or sync.RWMutex for basic critical section protection.\nsync.Once vs Manual Control: sync.Once is optimal for initialization code that should run exactly once.\nsync.Map vs Regular Map with Lock: Consider sync.Map for frequent operations with read-heavy patterns.\nRegular map with sync.Mutex might be more flexible and efficient otherwise.\n","permalink":"https://ka1hung.github.io/blog/posts/go-concurrency-locks/","summary":"\u003cp\u003eIn Golang\u0026rsquo;s standard library \u003ccode\u003esync\u003c/code\u003e, \u003ccode\u003esync.Mutex\u003c/code\u003e is a basic mutual exclusion lock used to protect shared resources and prevent multiple goroutines from simultaneously accessing or modifying data. The \u003ccode\u003esync\u003c/code\u003e package provides several types of locks and synchronization mechanisms. Here\u0026rsquo;s a comprehensive overview of the main lock types and their differences:\u003c/p\u003e\n\u003ch2 id=\"1-syncmutex-mutual-exclusion-lock\"\u003e1. sync.Mutex (Mutual Exclusion Lock)\u003c/h2\u003e\n\u003cp\u003e\u003ccode\u003esync.Mutex\u003c/code\u003e is the most basic lock type used to protect critical sections, ensuring only one goroutine can enter the locked area.\u003c/p\u003e","title":"Understanding Locks and Synchronization Mechanisms in Golang's sync Package"},{"content":"Beyond the Basic Search: Why Kagi is Your New Best Friend Hey there, internet explorers! Tired of drowning in ads and sponsored content every time you search for something? Let me introduce you to Kagi - the search engine that treats you like a human, not a walking wallet.\n🎯 What Makes Kagi Special? No More Ad Maze Remember the last time you searched for a recipe and had to scroll past three screens of ads? Yeah, Kagi doesn\u0026rsquo;t do that. Zero ads. Nada. Just pure, delicious search results.\nPrivacy is Not Just a Buzzword While other search engines are basically digital stalkers, Kagi is like that trustworthy friend who keeps your secrets. No tracking, no data selling, no creepy \u0026ldquo;we know what you\u0026rsquo;ll search next\u0026rdquo; moments.\n🚀 Cool Features That\u0026rsquo;ll Blow Your Mind Lenses: Your Search Superpowers Think of Lenses as your personal search DJ. They help you filter and focus your results exactly how you want them. Looking for academic papers? There\u0026rsquo;s a lens for that. Want developer documentation? Got you covered!\nUniversal Summarizer Too lazy to read that long article? (We\u0026rsquo;ve all been there!) Kagi\u0026rsquo;s Universal Summarizer will give you the TL;DR version faster than you can say \u0026ldquo;information overload.\u0026rdquo;\nDeep Search Ever felt like you\u0026rsquo;re only scratching the surface? Deep Search dives into the web\u0026rsquo;s hidden gems, accessing premium content and specialized databases. It\u0026rsquo;s like having a research assistant with superpowers!\n🎉 Why You\u0026rsquo;ll Love Kagi Speed: Results faster than your coffee machine Relevance: Actually finds what you\u0026rsquo;re looking for (shocking, right?) Customization: Make it yours, because one size doesn\u0026rsquo;t fit all No Dark Patterns: Just honest, straightforward searching The Bottom Line Kagi isn\u0026rsquo;t just another search engine - it\u0026rsquo;s what search should have been all along. It\u0026rsquo;s like upgrading from a bicycle to a Tesla, but for your web searching needs.\nReady to join the search revolution? Your brain (and your privacy) will thank you!\nP.S. The name \u0026ldquo;Kagi\u0026rdquo; means \u0026ldquo;key\u0026rdquo; in Japanese. How fitting for a tool that unlocks the true potential of web search!\n","permalink":"https://ka1hung.github.io/blog/posts/kagi/","summary":"\u003ch2 id=\"beyond-the-basic-search-why-kagi-is-your-new-best-friend\"\u003eBeyond the Basic Search: Why Kagi is Your New Best Friend\u003c/h2\u003e\n\u003cp\u003eHey there, internet explorers! Tired of drowning in ads and sponsored content every time you search for something? Let me introduce you to Kagi - the search engine that treats you like a human, not a walking wallet.\u003c/p\u003e\n\u003ch3 id=\"-what-makes-kagi-special\"\u003e🎯 What Makes Kagi Special?\u003c/h3\u003e\n\u003ch4 id=\"no-more-ad-maze\"\u003eNo More Ad Maze\u003c/h4\u003e\n\u003cp\u003eRemember the last time you searched for a recipe and had to scroll past three screens of ads? Yeah, Kagi doesn\u0026rsquo;t do that. Zero ads. Nada. Just pure, delicious search results.\u003c/p\u003e","title":"Kagi: The Search Engine That Actually Respects Your Brain (and Privacy!)"},{"content":"The Ultimate Guide to Installing Chocolatey Package Manager for Windows What is Chocolatey? Chocolatey (choco) is a powerful package manager for Windows that automates software installation, upgrading, and uninstallation. Think of it as the Windows equivalent of apt-get for Linux or brew for macOS.\nPrerequisites Windows operating system Administrator privileges Internet connection Installation Steps Step 1: Open PowerShell as Administrator Right-click on the Start menu Select \u0026ldquo;Windows PowerShell (Admin)\u0026rdquo; or \u0026ldquo;Windows Terminal (Admin)\u0026rdquo; Confirm the UAC prompt if it appears Step 2: Check Execution Policy Get-ExecutionPolicy If the policy isn\u0026rsquo;t set to RemoteSigned or Unrestricted, run:\nSet-ExecutionPolicy Bypass -Scope Process -Force Step 3: Install Chocolatey Copy and paste this command:\nSet-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(\u0026#39;https://community.chocolatey.org/install.ps1\u0026#39;)) Step 4: Verify Installation choco --version Essential Chocolatey Commands 📦 Package Management Command Description Example Install choco install \u0026lt;package\u0026gt; choco install firefox -y Upgrade choco upgrade \u0026lt;package\u0026gt; choco upgrade all Uninstall choco uninstall \u0026lt;package\u0026gt; choco uninstall notepad++ List choco list --local-only Shows installed packages Search choco search \u0026lt;keyword\u0026gt; choco search vlc 🔧 Useful Parameters -y: Auto-confirm all prompts --version: Specify package version --force: Force package installation --verbose: Show detailed output Pro Tips 💡 Install multiple packages at once: choco install firefox vlc 7zip -y Keep all packages updated: choco upgrade all -y Schedule automatic updates: choco install chocolatey-core.extension choco install choco-upgrade-all-at --params \u0026#34;\u0026#39;/DAILY:yes /TIME:03:00\u0026#39;\u0026#34; Popular Software to Install Development: vscode, git, nodejs Utilities: 7zip, notepadplusplus, everything Browsers: googlechrome, firefox Media: vlc, spotify Troubleshooting If you encounter any issues:\nRun PowerShell as Administrator Check your internet connection Verify Windows Defender isn\u0026rsquo;t blocking the installation Clear the Chocolatey cache: choco cache remove all Need Help? Official Documentation: chocolatey.org/docs Community Forum: chocolatey.org/community Package Repository: community.chocolatey.org Happy installing! With Chocolatey, managing Windows software has never been easier. 🚀\n","permalink":"https://ka1hung.github.io/blog/posts/ultimate-guide-to-chocolatey/","summary":"\u003ch1 id=\"the-ultimate-guide-to-installing-chocolatey-package-manager-for-windows\"\u003eThe Ultimate Guide to Installing Chocolatey Package Manager for Windows\u003c/h1\u003e\n\u003ch2 id=\"what-is-chocolatey\"\u003eWhat is Chocolatey?\u003c/h2\u003e\n\u003cp\u003eChocolatey (choco) is a powerful package manager for Windows that automates software installation, upgrading, and uninstallation. Think of it as the Windows equivalent of \u003ccode\u003eapt-get\u003c/code\u003e for Linux or \u003ccode\u003ebrew\u003c/code\u003e for macOS.\u003c/p\u003e\n\u003ch2 id=\"prerequisites\"\u003ePrerequisites\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003eWindows operating system\u003c/li\u003e\n\u003cli\u003eAdministrator privileges\u003c/li\u003e\n\u003cli\u003eInternet connection\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"installation-steps\"\u003eInstallation Steps\u003c/h2\u003e\n\u003ch3 id=\"step-1-open-powershell-as-administrator\"\u003eStep 1: Open PowerShell as Administrator\u003c/h3\u003e\n\u003col\u003e\n\u003cli\u003eRight-click on the Start menu\u003c/li\u003e\n\u003cli\u003eSelect \u0026ldquo;Windows PowerShell (Admin)\u0026rdquo; or \u0026ldquo;Windows Terminal (Admin)\u0026rdquo;\u003c/li\u003e\n\u003cli\u003eConfirm the UAC prompt if it appears\u003c/li\u003e\n\u003c/ol\u003e\n\u003ch3 id=\"step-2-check-execution-policy\"\u003eStep 2: Check Execution Policy\u003c/h3\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;\"\u003e\u003ccode class=\"language-powershell\" data-lang=\"powershell\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eGet-ExecutionPolicy\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eIf the policy isn\u0026rsquo;t set to \u003ccode\u003eRemoteSigned\u003c/code\u003e or \u003ccode\u003eUnrestricted\u003c/code\u003e, run:\u003c/p\u003e","title":"Ultimate Guide to Chocolatey"},{"content":"Looking for efficient ways to sort data in Go? This guide covers everything from basic sorting to advanced techniques!\n🚀 Basic Sorting The sort package provides fundamental sorting capabilities.\npackage main import ( \u0026#34;fmt\u0026#34; \u0026#34;sort\u0026#34; ) func main() { //sort int s1 := []int{8, 2, 6, 3, 1, 4} sort.Ints(s1) fmt.Println(s1) //sort int reverse sort.Sort(sort.Reverse(sort.IntSlice(s1))) fmt.Println(s1) //sort string s2 := []string{\u0026#34;aaa\u0026#34;, \u0026#34;bbb\u0026#34;, \u0026#34;6\u0026#34;, \u0026#34;3\u0026#34;, \u0026#34;1\u0026#34;, \u0026#34;4\u0026#34;} sort.Strings(s2) fmt.Println(s2) //sort string reverse sort.Sort(sort.Reverse(sort.StringSlice(s2))) fmt.Println(s2) //sort float64 s3 := []float64{1, 1.2, 0, -1.9, -82.333, 99.11} sort.Float64s(s3) fmt.Println(s3) //sort float64 reverse sort.Sort(sort.Reverse(sort.Float64Slice(s3))) fmt.Println(s3) } 🎯 Object Sorting How to sort a list of objects by specific fields:\npackage main import ( \u0026#34;fmt\u0026#34; \u0026#34;sort\u0026#34; ) type Data struct { ID int Name string } func main() { //sort struct ds := []Data{} ds = append(ds, Data{ID: 49, Name: \u0026#34;kevin\u0026#34;}) ds = append(ds, Data{ID: 11, Name: \u0026#34;peter\u0026#34;}) ds = append(ds, Data{ID: 11, Name: \u0026#34;mary\u0026#34;}) ds = append(ds, Data{ID: 11, Name: \u0026#34;adon\u0026#34;}) ds = append(ds, Data{ID: 15, Name: \u0026#34;lily\u0026#34;}) //sort by id sort.Slice(ds, func(i, j int) bool { return ds[i].ID \u0026lt; ds[j].ID }) fmt.Println(ds) //sort by Name sort.Slice(ds, func(i, j int) bool { return ds[i].Name \u0026lt; ds[j].Name }) fmt.Println(ds) //sort by id reverse sort.Slice(ds, func(i, j int) bool { return ds[i].ID \u0026gt; ds[j].ID }) fmt.Println(ds) } 🎨 Multi-Level Sorting Need secondary sorting when primary fields are equal? Here\u0026rsquo;s how:\npackage main import ( \u0026#34;fmt\u0026#34; \u0026#34;sort\u0026#34; ) type Data struct { ID int Name string } func main() { ds := []Data{} ds = append(ds, Data{ID: 49, Name: \u0026#34;kevin\u0026#34;}) ds = append(ds, Data{ID: 13, Name: \u0026#34;kevin\u0026#34;}) ds = append(ds, Data{ID: 12, Name: \u0026#34;kevin\u0026#34;}) ds = append(ds, Data{ID: 11, Name: \u0026#34;peter\u0026#34;}) ds = append(ds, Data{ID: 15, Name: \u0026#34;lily\u0026#34;}) //sort by Name, then by ID sort.Slice(ds, func(i, j int) bool { if ds[i].Name == ds[j].Name { return ds[i].ID \u0026lt; ds[j].ID } return ds[i].Name \u0026lt; ds[j].Name }) fmt.Println(ds) } ⭐ Natural Sorting Ever faced issues sorting strings with numbers? For example:\nInput: [\u0026ldquo;A11\u0026rdquo;, \u0026ldquo;A3\u0026rdquo;, \u0026ldquo;A2\u0026rdquo;, \u0026ldquo;A1\u0026rdquo;] Standard sort result: [\u0026ldquo;A1\u0026rdquo;, \u0026ldquo;A11\u0026rdquo;, \u0026ldquo;A2\u0026rdquo;, \u0026ldquo;A3\u0026rdquo;] Desired result: [\u0026ldquo;A1\u0026rdquo;, \u0026ldquo;A2\u0026rdquo;, \u0026ldquo;A3\u0026rdquo;, \u0026ldquo;A11\u0026rdquo;] Natural sorting solves this problem perfectly! It\u0026rsquo;s especially useful for:\nVersion numbers\nIP addresses\nFile names with numbers\nInstallation First, install the required package:\ngo get github.com/facette/natsort Here\u0026rsquo;s how to use natural sorting:\npackage main import ( \u0026#34;fmt\u0026#34; \u0026#34;sort\u0026#34; \u0026#34;github.com/facette/natsort\u0026#34; ) type Data struct { ID string Name string } func main() { // Standard string sort comparison s2 := []string{\u0026#34;Device2\u0026#34;, \u0026#34;Device11\u0026#34;, \u0026#34;Device1\u0026#34;, \u0026#34;Device22\u0026#34;, \u0026#34;Device13\u0026#34;, \u0026#34;Device3\u0026#34;} sort.Strings(s2) fmt.Println(\u0026#34;Standard sort:\u0026#34;, s2) // Natural sort s2 = []string{\u0026#34;Device2\u0026#34;, \u0026#34;Device11\u0026#34;, \u0026#34;Device1\u0026#34;, \u0026#34;Device22\u0026#34;, \u0026#34;Device13\u0026#34;, \u0026#34;Device3\u0026#34;} natsort.Sort(s2) fmt.Println(\u0026#34;Natural sort:\u0026#34;, s2) // Natural sort with structs ds := []Data{} ds = append(ds, Data{ID: \u0026#34;2\u0026#34;, Name: \u0026#34;kevin\u0026#34;}) ds = append(ds, Data{ID: \u0026#34;11\u0026#34;, Name: \u0026#34;peter\u0026#34;}) ds = append(ds, Data{ID: \u0026#34;1\u0026#34;, Name: \u0026#34;mary\u0026#34;}) ds = append(ds, Data{ID: \u0026#34;3\u0026#34;, Name: \u0026#34;adon\u0026#34;}) ds = append(ds, Data{ID: \u0026#34;12\u0026#34;, Name: \u0026#34;lily\u0026#34;}) //sort by id sort.Slice(ds, func(i, j int) bool { return natsort.Compare(ds[i].ID, ds[j].ID) }) fmt.Println(ds) } ","permalink":"https://ka1hung.github.io/blog/posts/golang-sort/","summary":"\u003cp\u003eLooking for efficient ways to sort data in Go? This guide covers everything from basic sorting to advanced techniques!\u003c/p\u003e\n\u003ch2 id=\"-basic-sorting\"\u003e🚀 Basic Sorting\u003c/h2\u003e\n\u003cp\u003eThe \u003ccode\u003esort\u003c/code\u003e package provides fundamental sorting capabilities.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;\"\u003e\u003ccode class=\"language-golang\" data-lang=\"golang\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#f92672\"\u003epackage\u003c/span\u003e \u003cspan style=\"color:#a6e22e\"\u003emain\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#f92672\"\u003eimport\u003c/span\u003e (\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#e6db74\"\u003e\u0026#34;fmt\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#e6db74\"\u003e\u0026#34;sort\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#66d9ef\"\u003efunc\u003c/span\u003e \u003cspan style=\"color:#a6e22e\"\u003emain\u003c/span\u003e() {\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#75715e\"\u003e//sort int\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e\u003c/span\u003e    \u003cspan style=\"color:#a6e22e\"\u003es1\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e:=\u003c/span\u003e []\u003cspan style=\"color:#66d9ef\"\u003eint\u003c/span\u003e{\u003cspan style=\"color:#ae81ff\"\u003e8\u003c/span\u003e, \u003cspan style=\"color:#ae81ff\"\u003e2\u003c/span\u003e, \u003cspan style=\"color:#ae81ff\"\u003e6\u003c/span\u003e, \u003cspan style=\"color:#ae81ff\"\u003e3\u003c/span\u003e, \u003cspan style=\"color:#ae81ff\"\u003e1\u003c/span\u003e, \u003cspan style=\"color:#ae81ff\"\u003e4\u003c/span\u003e}\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eInts\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es1\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#a6e22e\"\u003efmt\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003ePrintln\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es1\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#75715e\"\u003e//sort int reverse\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e\u003c/span\u003e    \u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eSort\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eReverse\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eIntSlice\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es1\u003c/span\u003e)))\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#a6e22e\"\u003efmt\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003ePrintln\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es1\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#75715e\"\u003e//sort string\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e\u003c/span\u003e    \u003cspan style=\"color:#a6e22e\"\u003es2\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e:=\u003c/span\u003e []\u003cspan style=\"color:#66d9ef\"\u003estring\u003c/span\u003e{\u003cspan style=\"color:#e6db74\"\u003e\u0026#34;aaa\u0026#34;\u003c/span\u003e, \u003cspan style=\"color:#e6db74\"\u003e\u0026#34;bbb\u0026#34;\u003c/span\u003e, \u003cspan style=\"color:#e6db74\"\u003e\u0026#34;6\u0026#34;\u003c/span\u003e, \u003cspan style=\"color:#e6db74\"\u003e\u0026#34;3\u0026#34;\u003c/span\u003e, \u003cspan style=\"color:#e6db74\"\u003e\u0026#34;1\u0026#34;\u003c/span\u003e, \u003cspan style=\"color:#e6db74\"\u003e\u0026#34;4\u0026#34;\u003c/span\u003e}\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eStrings\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es2\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#a6e22e\"\u003efmt\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003ePrintln\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es2\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#75715e\"\u003e//sort string reverse\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e\u003c/span\u003e    \u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eSort\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eReverse\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eStringSlice\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es2\u003c/span\u003e)))\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#a6e22e\"\u003efmt\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003ePrintln\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es2\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#75715e\"\u003e//sort float64\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e\u003c/span\u003e    \u003cspan style=\"color:#a6e22e\"\u003es3\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e:=\u003c/span\u003e []\u003cspan style=\"color:#66d9ef\"\u003efloat64\u003c/span\u003e{\u003cspan style=\"color:#ae81ff\"\u003e1\u003c/span\u003e, \u003cspan style=\"color:#ae81ff\"\u003e1.2\u003c/span\u003e, \u003cspan style=\"color:#ae81ff\"\u003e0\u003c/span\u003e, \u003cspan style=\"color:#f92672\"\u003e-\u003c/span\u003e\u003cspan style=\"color:#ae81ff\"\u003e1.9\u003c/span\u003e, \u003cspan style=\"color:#f92672\"\u003e-\u003c/span\u003e\u003cspan style=\"color:#ae81ff\"\u003e82.333\u003c/span\u003e, \u003cspan style=\"color:#ae81ff\"\u003e99.11\u003c/span\u003e}\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eFloat64s\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es3\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#a6e22e\"\u003efmt\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003ePrintln\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es3\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#75715e\"\u003e//sort float64 reverse\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#75715e\"\u003e\u003c/span\u003e    \u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eSort\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eReverse\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003esort\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003eFloat64Slice\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es3\u003c/span\u003e)))\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#a6e22e\"\u003efmt\u003c/span\u003e.\u003cspan style=\"color:#a6e22e\"\u003ePrintln\u003c/span\u003e(\u003cspan style=\"color:#a6e22e\"\u003es3\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e}\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"-object-sorting\"\u003e🎯 Object Sorting\u003c/h2\u003e\n\u003cp\u003eHow to sort a list of objects by specific fields:\u003c/p\u003e","title":"Golang-sort"},{"content":"Looking for an easy-to-use TCP/UDP testing tool? Sokit is a lightweight but powerful solution that helps you test network communications with ease.\n✨ Key Features TCP/UDP Server simulation (supports both string and hex formats) TCP/UDP Client simulation (supports both string and hex formats) Data forwarding/proxy capabilities Cross-platform support (Windows \u0026amp; Linux) Clean and intuitive UI 🔗 Quick Links GitHub Repository Download Link 📖 Quick Start Guide Basic Server-Client Communication Launch two instances of Sokit - one as TCP Server (left) and one as TCP Client (right) Configure IP addresses and ports for both instances Establish the connection between them Testing Basic Communication: Send \u0026ldquo;123\u0026rdquo; from Client to Server Server receives the string Server can select specific client from the Connection list Send \u0026ldquo;999\u0026rdquo; back to Client from Server 🔢 Hex Communication Mode Client can send hex data like [33 32 31] to Server\nNote: Hex data must be enclosed in square brackets [ ]\nServer can expand received data to show hex representation\n🔄 Data Forwarding Setup Launch a third Sokit instance as forwarding server with:\nSource: 127.0.0.1:54321 Destination: 127.0.0.1:12345 When client connects to the forwarding server\u0026rsquo;s source address, traffic will be automatically forwarded to the destination server\n💡 Pro Tips Use hex mode for binary protocol testing Forwarding feature is great for debugging proxy scenarios Save common configurations for quick reuse Monitor traffic in real-time with the built-in logger 🛠 Perfect For Network protocol testing IoT device communication debugging API endpoint verification Network proxy testing Educational purposes Give Sokit a try - it might become your go-to networking tool! Feel free to star the project on GitHub if you find it useful.\n","permalink":"https://ka1hung.github.io/blog/posts/sokit/","summary":"\u003cp\u003eLooking for an easy-to-use TCP/UDP testing tool? Sokit is a lightweight but powerful solution that helps you test network communications with ease.\u003c/p\u003e\n\u003ch2 id=\"-key-features\"\u003e✨ Key Features\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003eTCP/UDP Server simulation (supports both string and hex formats)\u003c/li\u003e\n\u003cli\u003eTCP/UDP Client simulation (supports both string and hex formats)\u003c/li\u003e\n\u003cli\u003eData forwarding/proxy capabilities\u003c/li\u003e\n\u003cli\u003eCross-platform support (Windows \u0026amp; Linux)\u003c/li\u003e\n\u003cli\u003eClean and intuitive UI\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"-quick-links\"\u003e🔗 Quick Links\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/sinpolib/sokit\"\u003eGitHub Repository\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://mega.nz/file/1l9AzS4Q#Q-D9Slf4O52bOtmkjYawedvQR4GxyfRi0hj7svkUHR4\"\u003eDownload Link\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"-quick-start-guide\"\u003e📖 Quick Start Guide\u003c/h2\u003e\n\u003ch3 id=\"basic-server-client-communication\"\u003eBasic Server-Client Communication\u003c/h3\u003e\n\u003col\u003e\n\u003cli\u003eLaunch two instances of Sokit - one as TCP Server (left) and one as TCP Client (right)\u003c/li\u003e\n\u003cli\u003eConfigure IP addresses and ports for both instances\u003c/li\u003e\n\u003cli\u003eEstablish the connection between them\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003e\u003cimg alt=\"Server-Client Setup\" loading=\"lazy\" src=\"/blog/posts/sokit/1.png\"\u003e\u003c/p\u003e","title":"Sokit - A Powerful TCP/UDP Testing Tool You Should Know"},{"content":"🎯 Ninja Ways to Hide Console Window in Go Ever wanted to make your Go applications look more professional by hiding that pesky console window? You\u0026rsquo;re in the right place! Let\u0026rsquo;s explore some ninja techniques to achieve this. 🥷\n🚀 Method 1: The Quick Strike (-ldflags) The simplest way to hide the console window is using build flags. Think of it as a stealth mode for your app!\ngo build -ldflags -H=windowsgui main.go Pros:\nSuper simple to implement No code changes needed Works for most basic applications Cons:\nLimited flexibility Can\u0026rsquo;t toggle console visibility at runtime\n🎭 Method 2: The Shape-Shifter (syscall) Want more control? Let\u0026rsquo;s use Windows API calls to dynamically hide/show the console!\npackage main import ( \u0026#34;fmt\u0026#34; \u0026#34;syscall\u0026#34; ) func main() { hideConsole() // Your awesome code here! } func hideConsole() { console := syscall.MustLoadDLL(\u0026#34;kernel32\u0026#34;).MustFindProc(\u0026#34;GetConsoleWindow\u0026#34;) if console != nil { showWindow := syscall.MustLoadDLL(\u0026#34;user32.dll\u0026#34;).MustFindProc(\u0026#34;ShowWindow\u0026#34;) hwnd, _, _ := console.Call() if hwnd != 0 { showWindow.Call(hwnd, 0) // 0 = SW_HIDE } } } // Want to show it again? Just use this! func showConsole() { console := syscall.MustLoadDLL(\u0026#34;kernel32\u0026#34;).MustFindProc(\u0026#34;GetConsoleWindow\u0026#34;) if console != nil { showWindow := syscall.MustLoadDLL(\u0026#34;user32.dll\u0026#34;).MustFindProc(\u0026#34;ShowWindow\u0026#34;) hwnd, _, _ := console.Call() if hwnd != 0 { showWindow.Call(hwnd, 5) // 5 = SW_SHOW } } } 🎨 Method 3: The Artist\u0026rsquo;s Way (manifest.xml + syso) This is the professional approach! Create a manifest file for your application:\n\u0026lt;?xml version=\u0026#34;1.0\u0026#34; encoding=\u0026#34;UTF-8\u0026#34; standalone=\u0026#34;yes\u0026#34;?\u0026gt; \u0026lt;assembly xmlns=\u0026#34;urn:schemas-microsoft-com:asm.v1\u0026#34; manifestVersion=\u0026#34;1.0\u0026#34;\u0026gt; \u0026lt;assemblyIdentity version=\u0026#34;1.0.0.0\u0026#34; processorArchitecture=\u0026#34;*\u0026#34; name=\u0026#34;YourCoolApp\u0026#34; type=\u0026#34;win32\u0026#34;/\u0026gt; \u0026lt;dependency\u0026gt; \u0026lt;dependentAssembly\u0026gt; \u0026lt;assemblyIdentity type=\u0026#34;win32\u0026#34; name=\u0026#34;Microsoft.Windows.Common-Controls\u0026#34; version=\u0026#34;6.0.0.0\u0026#34; processorArchitecture=\u0026#34;*\u0026#34; publicKeyToken=\u0026#34;6595b64144ccf1df\u0026#34; language=\u0026#34;*\u0026#34;/\u0026gt; \u0026lt;/dependentAssembly\u0026gt; \u0026lt;/dependency\u0026gt; \u0026lt;/assembly\u0026gt; Then follow these magical steps:\n# Install the wizard\u0026#39;s tool go install github.com/akavel/rsrc@latest # Create the magic potion (syso file) rsrc -manifest manifest.xml -o app.syso # Build your masterpiece go build 🧙‍♂️ Pro Tips and Tricks Logging Magic When your console is hidden, don\u0026rsquo;t forget to implement proper logging:\npackage main import ( \u0026#34;log\u0026#34; \u0026#34;os\u0026#34; ) func main() { // Create your spell book (log file) logFile, _ := os.OpenFile(\u0026#34;app.log\u0026#34;, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) defer logFile.Close() // Direct your magical energies (logs) to the spell book log.SetOutput(logFile) // Cast your spells (write logs) log.Println(\u0026#34;✨ Application started!\u0026#34;) } Debug Mode Toggle Add this cool feature to show/hide console based on command line flags:\npackage main import \u0026#34;flag\u0026#34; func main() { debug := flag.Bool(\u0026#34;debug\u0026#34;, false, \u0026#34;show console window\u0026#34;) flag.Parse() if !*debug { hideConsole() } // Rest of your awesome code } 🎮 Best Practices Always provide error logging mechanisms Consider adding a debug mode Test thoroughly on different Windows versions Keep a development build with console visible Handle panics gracefully\n🌟 When to Use What? Quick Project: Go with Method 1 (-ldflags) Need Runtime Control: Choose Method 2 (syscall) Professional App: Use Method 3 (manifest)\n🎉 Conclusion Now you\u0026rsquo;re equipped with all the ninja techniques to hide that console window like a pro! Remember, with great power comes great responsibility - make sure to implement proper logging and error handling in your invisible applications!\n📚 Further Reading Windows API Documentation\nGo Windows Examples\nrsrc Tool Documentation\n","permalink":"https://ka1hung.github.io/blog/posts/how-to-hide-the-console-window-when-running-a-golang-compiled-file./","summary":"\u003ch2 id=\"-ninja-ways-to-hide-console-window-in-go\"\u003e🎯 Ninja Ways to Hide Console Window in Go\u003c/h2\u003e\n\u003cp\u003eEver wanted to make your Go applications look more professional by hiding that pesky console window? You\u0026rsquo;re in the right place! Let\u0026rsquo;s explore some ninja techniques to achieve this. 🥷\u003c/p\u003e\n\u003ch2 id=\"-method-1-the-quick-strike--ldflags\"\u003e🚀 Method 1: The Quick Strike (-ldflags)\u003c/h2\u003e\n\u003cp\u003eThe simplest way to hide the console window is using build flags. Think of it as a stealth mode for your app!\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ego build -ldflags -H\u003cspan style=\"color:#f92672\"\u003e=\u003c/span\u003ewindowsgui main.go\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003ePros:\u003c/p\u003e","title":"How to hide the Console window when running a Golang compiled file"}]