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
{"AWSTemplateFormatVersion":"2010-09-09","Description":"EKS cluster (dedicated VPC: true, dedicated IAM: true) [created and managed by eksctl]","Resources":{"ControlPlane":{"Type":"AWS::EKS::Cluster","Properties":{"Name":"dev3","ResourcesVpcConfig":{"SecurityGroupIds":[{"Ref":"ControlPlaneSecurityGroup"}],"SubnetIds":[{"Ref":"SubnetPublicUSWEST2C"},{"Ref":"SubnetPublicUSWEST2A"},{"Ref":"SubnetPublicUSWEST2B"},{"Ref":"SubnetPrivateUSWEST2C"},{"Ref":"SubnetPrivateUSWEST2A"},{"Ref":"SubnetPrivateUSWEST2B"}]},"RoleArn":{"Fn::GetAtt":"ServiceRole.Arn"},"Version":"1.11"}},"ControlPlaneSecurityGroup":{"Type":"AWS::EC2::SecurityGroup","Properties":{"GroupDescription":"Communication between the control plane and worker node groups","Tags":[{"Key":"Name","Value":{"Fn::Sub":"${AWS::StackName}/ControlPlaneSecurityGroup"}}],"VpcId":{"Ref":"VPC"}}},"InternetGateway":{"Type":"AWS::EC2::InternetGateway","Properties":{"Tags":[{"Key":"Name","Value":{"Fn::Sub":"${AWS::StackName}/InternetGateway"}}]}},"NATGateway":{"Type":"AWS::
$ eksctl create cluster -v 4 --name=dev3 --nodes-min=2 --nodes-max=10
2018-12-21T16:54:51Z [ℹ] using region us-west-2
2018-12-21T16:54:52Z [▶] role ARN for the current session is "arn:aws:iam::797098425712:user/vojtech"
2018-12-21T16:54:52Z [▶] determining availability zones
2018-12-21T16:54:52Z [ℹ] setting availability zones to [us-west-2c us-west-2a us-west-2b]
2018-12-21T16:54:52Z [▶] VPC CIDR (192.168.0.0/16) was divided into 8 subnets [192.168.0.0/19 192.168.32.0/19 192.168.64.0/19 192.168.96.0/19 192.168.128.0/19 192.168.160.0/19 192.168.192.0/19 192.168.224.0/19]
2018-12-21T16:54:52Z [ℹ] subnets for us-west-2c - public:192.168.0.0/19 private:192.168.96.0/19
2018-12-21T16:54:52Z [ℹ] subnets for us-west-2a - public:192.168.32.0/19 private:192.168.128.0/19
2018-12-21T16:54:52Z [ℹ] subnets for us-west-2b - public:192.168.64.0/19 private:192.168.160.0/19
2018-12-21T16:54:52Z [▶] resolving AMI using StaticGPUResolver for region us-west-2, instanceType m5.large and imageFamily AmazonLinux2
@VojtechVitek
VojtechVitek / git-checkout-pull-request.sh
Created June 19, 2017 19:59
git checkout Github Pull Request locally
git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
git fetch
git checkout -t origin/pr/12
# Based on https://gist.github.com/piscisaureus/3342247
@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
package zlib
import (
"bytes"
"io"
"testing"
)
type zlibTest struct {
desc string
@VojtechVitek
VojtechVitek / docker-postgres-change-owner.sh
Last active July 4, 2016 15:49
Postgres in Docker: Modify Owner of all Tables + Sequences
export new_user="your_user"
export dbname="your_db_name"
cat <<EOF | docker run -i --rm --link postgres:postgres postgres sh -c "psql -h \$POSTGRES_PORT_5432_TCP_ADDR -p \$POSTGRES_PORT_5432_TCP_PORT -U postgres -d $dbname" | grep ALTER | docker run -i --rm --link postgres:postgres postgres sh -c "psql -h \$POSTGRES_PORT_5432_TCP_ADDR -p \$POSTGRES_PORT_5432_TCP_PORT -U postgres -d $dbname"
SELECT 'ALTER TABLE '||schemaname||'.'||tablename||' OWNER TO $new_user;'
FROM pg_tables WHERE schemaname = 'public';
SELECT 'ALTER SEQUENCE '||relname||' OWNER TO $new_user;' FROM pg_class WHERE relkind = 'S';
EOF
@VojtechVitek
VojtechVitek / subrouters.go
Last active January 26, 2016 02:43
subrouters.go
package main
import (
"log"
"net/http"
"github.com/pressly/chi"
)
func main() {
@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 / 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 / run_jobs_parallel.sh
Created July 9, 2014 15:44
Bash script - Run commands/jobs in parallel and attach to its output and wait for the return codes sequentially
# Run job in background, redirect its output to a non-blocking pipe,
# and leave the rc and stdout/stderr to be handled by attach_wait_jobs()
jobs_tmp_dirs=""
function run_job() {
local dir=$(mktemp -d -t gearXXXXXX)
jobs_tmp_dirs="$jobs_tmp_dirs $dir"
mkfifo $dir/pipe
mkfifo $dir/pipe_nonblock
"$@" &>$dir/pipe_nonblock &
echo $! >$dir/pid