Skip to content

Instantly share code, notes, and snippets.

View VojtechVitek's full-sized avatar
🏄
https://golang.cz

Vojtech Vitek (golang.cz) VojtechVitek

🏄
https://golang.cz
View GitHub Profile
@VojtechVitek
VojtechVitek / otel-logger-zerolog.go
Last active February 10, 2023 13:18
Open-Telemetry (otel) errors to zerolog logger
package main
import (
"github.com/rs/zerolog/log"
"go.opentelemetry.io/otel"
)
func main() {
otel.SetErrorHandler(&otelErrorHandler{})
}
@VojtechVitek
VojtechVitek / tailscale-advertise-vpn-routes.sh
Last active August 23, 2021 14:20
Advertise and route your VPN routes (ppp0) through a Tailscale node
#!/bin/bash
mask2cdr ()
{
# Based on https://stackoverflow.com/questions/20762575/explanation-of-convertor-of-cidr-to-netmask-in-linux-shell-netmask2cdir-and-cdir
local mask=$1
# In RFC 4632 netmasks there's no "255." after a non-255 byte in the mask
local left_stripped_mask=${mask##*255.}
local len_mask=${#mask}
@VojtechVitek
VojtechVitek / mask2cdr
Created December 7, 2020 21:03 — forked from RichardBronosky/mask2cdr
Convert netmask to CIDR
#!/bin/bash
# Based on https://stackoverflow.com/questions/20762575/explanation-of-convertor-of-cidr-to-netmask-in-linux-shell-netmask2cdir-and-cdir
mask2cdr ()
{
local mask=$1
# In RFC 4632 netmasks there's no "255." after a non-255 byte in the mask
local left_stripped_mask=${mask##*255.}
local len_mask=${#mask}
@VojtechVitek
VojtechVitek / gist:452b7f692197e765c6fc323366bd040a
Created May 15, 2020 14:20 — forked from madis/gist:4650014
Testing CORS OPTIONS request with curl
curl -v -X OPTIONS -H 'Access-Control-Request-Method: GET' -H 'Access-Control-Request-Headers: Origin, Accept, Content-Type' -H 'Origin: https://origin-host.example.com' https://target-host.example.com/ping
@VojtechVitek
VojtechVitek / removeexcept.sh
Created April 14, 2020 12:06 — forked from olavmrk/removeexcept.sh
git filter-branch command to remove all files except those of interest
# Remove every file except "./somefile.txt" and the directory "./somedir".
# --prune-empty to remove empty commits.
git filter-branch --tree-filter "find . -not -path './.git' -not -path './.git/*' -not -path './somefile.txt' -not -path './somedir/*' -not -path './somedir' -delete" --prune-empty
@VojtechVitek
VojtechVitek / uninstall_vmware.sh
Created April 3, 2020 08:13 — forked from boneskull/uninstall_vmware.sh
completely uninstall vmware on mac
#!/usr/bin/env bash
# Usage: bash uninstall_vmware.bash
remove() {
entry="$1"
echo -ne "Removing \e[1;34m$entry\e[0m... "
sudo rm -rf "$entry" &> /tmp/uninstall-vmware.log
if [[ ! -e "$entry" ]]; then
echo -e "\e[1;32mOK\e[0m"
@VojtechVitek
VojtechVitek / uninstall_vmware.sh
Created April 3, 2020 08:13 — forked from boneskull/uninstall_vmware.sh
completely uninstall vmware on mac
#!/usr/bin/env bash
# Usage: bash uninstall_vmware.bash
remove() {
entry="$1"
echo -ne "Removing \e[1;34m$entry\e[0m... "
sudo rm -rf "$entry" &> /tmp/uninstall-vmware.log
if [[ ! -e "$entry" ]]; then
echo -e "\e[1;32mOK\e[0m"
@VojtechVitek
VojtechVitek / toml-go.md
Last active September 16, 2019 11:11
Comparison of TOML go packages
+ TOML v0.4.0
+ MIT license
- doesn't preserve comments
- no tree structure available for recursion
- data is burried in multi-level tree of map[string]interface{}
+ preserves order in the metadata.Keys() [][]string, not very intuitive to use the metadata properly (TODO: link to example)

^ the best pkg out there, even though it's not perfect

@VojtechVitek
VojtechVitek / try-error-check.go
Created June 5, 2019 09:37
Proposal: try, a built-in Go error check function
func CopyFile(src, dst string) (err error) {
defer fmt.HandleErrorf(&err, "copy %s %s: %v", src, dst, err)
r := try(os.Open(src))
defer r.Close()
w := try(os.Create(dst))
defer func() {
w.Close()
if err != nil {
@VojtechVitek
VojtechVitek / aoe2hd.md
Created March 3, 2019 23:46 — forked from yocontra/aoe2hd.md
Age of Empires II HD - For Mac OSX