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 / slice-batch-in-parallel.go
Last active December 25, 2023 09:42
Golang - Loop over slice in batches (run something in parallel on a sub-slice)
package main
import "fmt"
func main() {
slice := make([]int, 159)
// Split the slice into batches of 20 items.
batch := 20
@VojtechVitek
VojtechVitek / redirects.go
Last active July 7, 2023 19:10
Golang: Workaround for too many redirects - "stopped after 10 redirects" error
sourceURL := "http://example.com"
// Resolve URL up to 12 redirects.
client := &http.Client{
CheckRedirect: func() func(req *http.Request, via []*http.Request) error {
redirects := 0
return func(req *http.Request, via []*http.Request) error {
if redirects > 12 {
return errors.New("stopped after 12 redirects")
}
@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 / map-type-reflect.go
Created September 24, 2014 11:27
Golang - How to get an underlying type of a map using reflect pkg
package main
import (
"fmt"
"reflect"
)
type Map map[string]string
type Object struct {
@VojtechVitek
VojtechVitek / aoe2hd.md
Created March 3, 2019 23:46 — forked from yocontra/aoe2hd.md
Age of Empires II HD - For Mac OSX
@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"