Skip to content

Instantly share code, notes, and snippets.

View oddmario's full-sized avatar

Mario oddmario

View GitHub Profile
@oddmario
oddmario / Golang Resource Management Best Practices.md
Created December 19, 2025 15:36
Golang Resource Management Best Practices

In Go, resource management is critical because unlike memory (which is garbage collected), external resources like file descriptors and network sockets must be released explicitly. Failure to do so leads to leaks that can crash your application.

Here is a checklist of the most common things you need to close, typically using the defer keyword.

1. HTTP Response Bodies (resp.Body)

This is the most common source of leaks in Go. When you make an HTTP request using the net/http client, you must close the response body, even if you don't read it. If you don't, the underlying network connection cannot be reused (keep-alive) or released.

  • What to close: http.Response.Body
  • Pattern:
@oddmario
oddmario / get_public_ip.go
Created December 16, 2025 11:45
A Go function for returning the current public IP address (supports both IPv4 and IPv6)
package main
import (
"fmt"
"github.com/pion/stun"
)
func getPublicIP(ipType string) ([]string, error) {
var network string = "udp4"
@oddmario
oddmario / extract_original_audio.sh
Last active December 10, 2024 12:23
Extract the original audio track from a video using ffmpeg + ffprobe
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <input_file> <output_file>"
exit 1
fi
input="$1"
output="$2"
@oddmario
oddmario / WARP.md
Last active April 28, 2025 15:21
Stop routing all traffic through Cloudflare WARP and use it on-demand using the tunnel interface name instead

Stop routing all traffic through Cloudflare WARP and use it on-demand using the tunnel interface name instead

#!/bin/bash

# https://serverfault.com/questions/978701/setting-up-openvpn-as-an-interface-rather-than-routing-all-traffic-from-paid-vpn
# https://serverfault.com/questions/992624/vpn-client-doesnt-have-internet-connection

WARP_INTERFACE_NAME="CloudflareWARP"
@oddmario
oddmario / OPENVPN.md
Last active September 28, 2024 09:08
Stop routing all traffic through OpenVPN and use it on-demand using the tunnel interface name instead

Stop routing all traffic through OpenVPN and use it on-demand using the tunnel interface name instead

#!/bin/bash

# https://serverfault.com/questions/978701/setting-up-openvpn-as-an-interface-rather-than-routing-all-traffic-from-paid-vpn
# https://serverfault.com/questions/992624/vpn-client-doesnt-have-internet-connection

OVPN_TUN_INTERFACE_NAME="tun0"
@oddmario
oddmario / GRE_TUNNELS.md
Last active August 10, 2024 08:09
Setup a GRE tunnel between two Linux servers
@oddmario
oddmario / ANTI_MAGISK_ROOT_DETECTION.md
Last active February 9, 2025 13:01
Avoid Magisk root detection
@oddmario
oddmario / winefix.sh
Created July 13, 2024 11:09
Attempt to fix a corrupted Wineprefix
#!/bin/bash
killall -9 wine
mv ~/.wine ~/.winebak
wineboot
rm -rf ~/.wine/drive_*
mv -f ~/.winebak/drive_* ~/.wine
rm -rf ~/.wine/*.reg
mv -f ~/.winebak/*.reg ~/.wine
rm -rf ~/.winebak
@oddmario
oddmario / tune_go_http_server.md
Last active December 28, 2025 08:39
Tuning a Golang (Go) HTTP server

Tune a Go http.Server

by adjusting its default buffer sizes


In some situations, you may need to adjust the default buffer sizes of a Golang HTTP server.

Adjusting the default buffer sizes allows you to benefit from higher throughput and improve the performance of your HTTP servers overall.

For the cherry on the top,

Installing QEMU with the qemu-anti-detection patch

This procedure was done on an Ubuntu 24.04 system


Install the dependencies required for the building process:

sudo apt install git build-essential ninja-build python3-venv libglib2.0-0 libglib2.0-dev flex bison libpixman-1-dev libsdl2-dev libsdl2-image-dev mesa-common-dev libglfw3-dev libgles2-mesa-dev libgl-dev libepoxy-dev libpipewire-0.3-dev libspice-protocol-dev libspice-server-dev libvirglrenderer-dev libjson-c-dev libcmocka-dev libusbredirparser-dev libgtk-3-dev libusb-1.0-0-dev