Skip to content

Instantly share code, notes, and snippets.

View thanhminhmr's full-sized avatar
😻
I may be slow to respond.

Mai Thanh Minh thanhminhmr

😻
I may be slow to respond.
View GitHub Profile
@thanhminhmr
thanhminhmr / README.md
Last active March 28, 2025 12:34
Go doesn't have ternary, so created one...

go-ternary

Yes, I know—yet another attempt at bringing a ternary-like experience to Go. But hey, Go doesn’t have one, and I wasn’t around when the last million were written.

Why?

Because Go doesn't have a ternary operator, and according to the official FAQ, it likely never will. The reasoning? To prevent developers from writing "impenetrably complex expressions." But let's be real—poor coding practices exist in all forms. Instead of outright banning a useful construct, wouldn’t compiler warnings for overly complicated ternary expressions have been a more reasonable approach?

Since that's not happening, here’s go-ternary—because sometimes, a one-liner is just nicer than an if-else.

@thanhminhmr
thanhminhmr / pie-camera.service
Created November 24, 2024 10:50
systemd service for streaming camera feed on Raspberry Pi Zero 2w using `ffmpeg` only
[Unit]
Description=Low-res Camera Stream
BindsTo=dev-video0.device
After=dev-video0.device
[Service]
ExecStart=ffmpeg -hide_banner -loglevel warning -i /dev/video0 -listen 1 -c:v h264_v4l2m2m -b:v 1000k -f mpegts http://0.0.0.0:8080
Restart=always
RestartSec=1s
@thanhminhmr
thanhminhmr / hyperv-usb-passthrough-guide.md
Created April 22, 2024 08:40
Hyper-V USB Passthrough using USBIP (afaik the *only* way)
  1. (Optional) Run this to disable "Microsoft Wi-Fi Direct Virtual Adapter" if you planned to passthrough a USB Wifi adapter.
netsh wlan stop hostednetwork
netsh wlan set hostednetwork mode=disallow
  1. Get VendorID and ProductID of the USB device, both are 4 hexadecimal digits. There are many ways to do this, the easy enough way for a noob is to plug it in, open Device Manager, right-click the device and open Properties, choose Details tab, on the Property drop-down, select Hardware Ids. The value should be something like USB\VID_ABCD&PID_1234, that should make the VendorID be ABCD and ProductID be 1234.

  2. Install usbipd-win: https://github.com/dorssel/usbipd-win/

@thanhminhmr
thanhminhmr / string-to-sha1.java
Created January 12, 2020 03:27 — forked from giraam/string-to-sha1.java
Hashing a String with SHA1 in Java
import java.io.*;
import java.util.logging.*;
import javax.xml.bind.DatatypeConverter;
/**
* Hashing with SHA1
*
* @param input String to hash
* @return String hashed
*/