Skip to content

Instantly share code, notes, and snippets.

View zucchinidev's full-sized avatar
🎯
Focusing

Andrea Zucchini zucchinidev

🎯
Focusing
View GitHub Profile
@zucchinidev
zucchinidev / client.go
Created January 5, 2023 17:34 — forked from xjdrew/client.go
golang tls client and server, require and verify certificate in double direction
package main
import (
"crypto/tls"
"crypto/x509"
"flag"
"io"
"io/ioutil"
"log"
"os"
@zucchinidev
zucchinidev / Built-in_shell_variables.md
Last active August 25, 2021 16:46
Built-in shell variables.

$# Stores the number of command-line arguments that were passed to the shell program.

$? Stores the exit value of the last command that was executed.

$0 Stores the first word of the entered command (the name of the shell program).

$* Stores all the arguments that were entered on the

@zucchinidev
zucchinidev / Optimistic concurrency
Created May 15, 2021 12:43
Optimistic concurrency
// Optimistic concurrency control assumes that many transactions can frequently
// complete without interfering with each other. While running, transactions use
// data resources without acquiring locks on those resources. Before committing,
// each transaction verifies that no other transaction has modified the data it has read.
// If the check reveals conflicting modifications, the committing transaction rolls back
// and can be restarted.
for ns in $(kubectl get ns --no-headers | cut -d " " -f1); do
if { [ "$ns" != "kube-system" ]; }; then
kubectl --namespace="${ns}" get --export -o=json svc,rc,rs,deployments,cm,secrets,ds,statefulsets,ing | \
jq '.items[] |
select(.type!="kubernetes.io/service-account-token") |
del(
.spec.clusterIP,
.metadata.uid,
.metadata.selfLink,
.metadata.resourceVersion,
@zucchinidev
zucchinidev / readdir.go
Created March 3, 2019 18:09
Concurrent Directory Traversal: program that reports the disk usage of one or more directories specified on the command line, like the Unix du command.
// go build -o du && ./du $HOME /usr /bin
// Root: /bin - 1781 files 0.5 GB
// Root: /usr - 189710 files 7.1 GB
// Root: /home/zucchinidev - 849059 files 39.4 GB
package main
import (
"flag"
"fmt"
export class RetryRequest {
private maxRetries: number[];
constructor(private timeout: number, maxRetries = 10) {
this.maxRetries = [...Array(maxRetries)].map((_, i) => i)
}
wait(timeout: number) {
return new Promise((resolve) => setTimeout(() => resolve(), timeout))
}
@zucchinidev
zucchinidev / createBigFile.sh
Created May 31, 2018 15:06
Create a big file with dd command
// newFile 24-25MB
dd if=/dev/urandom of=newfile bs=1M count=24
@zucchinidev
zucchinidev / main.go
Created October 5, 2017 13:34
The purpose of the work package is to show how you can use an unbuffered channel to create a pool of goroutines that will perform and control the amount of work that gets done concurrently
package main
import (
"log"
"github.com/zucchinidev/work/work"
"sync"
"time"
)
var names = []string{
@zucchinidev
zucchinidev / main.go
Last active October 4, 2017 14:25
Runner: The purpose of the runner package is to show how channels can be used to monitor the amount of time a program is running and terminate the program if it runs too long. This pattern is useful when developing a program that will be scheduled to run as a background task process.
package main
import (
"time"
"log"
"github.com/zucchinidev/runnerWork/runner"
"os"
)
const timeout = 3 * time.Second
@zucchinidev
zucchinidev / repare.sh
Last active September 15, 2017 08:36
Git: “Corrupt loose object”
# Create a backup of the corrupt directory:
cp -R foo foo-backup
# Make a new clone of the remote repository to a new directory:
git clone git@www.mydomain.de:foo foo-newclone
# Delete the corrupt .git subdirectory:
rm -rf foo/.git
# Move the newly cloned .git subdirectory into foo:
mv foo-newclone/.git foo
# Delete the rest of the temporary new clone:
rm -rf foo-newclone