Skip to content

Instantly share code, notes, and snippets.

@nileshsimaria
nileshsimaria / ifdb_batch_write.go
Last active May 2, 2018 08:22
tsdb write performance
package main
import (
"fmt"
"github.com/influxdata/influxdb/client/v2"
flag "github.com/spf13/pflag"
"log"
"math/rand"
"time"
)
package main
import (
"fmt"
"time"
)
const BufferedChLen = 1024
func consumer() chan<- int {
@nileshsimaria
nileshsimaria / protoc3 on Ubuntu
Last active December 3, 2018 21:33
protoc3 on Ubuntu
I am on Ubuntu 16.04.5 LTS.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial
I wanted to install latest protoc (which at the time of writing this is version 3.6.1).
@nileshsimaria
nileshsimaria / docker-default-directory
Last active April 4, 2024 09:13
Change docker's default /var/lib/docker to different directory on Ubuntu
1. Take a backup of docker.service file.
$ cp /lib/systemd/system/docker.service /lib/systemd/system/docker.service.orig
2. Modify /lib/systemd/system/docker.service to tell docker to use our own directory
instead of default /var/lib/docker. In this example, I am using /p/var/lib/docker
Apply below patch.
$ diff -uP -N /lib/systemd/system/docker.service.orig /lib/systemd/system/docker.service
--- /lib/systemd/system/docker.service.orig 2018-12-05 21:24:20.544852391 -0800
@nileshsimaria
nileshsimaria / Prevent SSH session timeout
Created December 6, 2018 06:03
Prevent SSH from kicking you out from inactive session
Modify /etc/ssh/sshd_config
ClientAliveInterval 120
ClientAliveCountMax 720
This will not kick you off even if you are inactive for 24 hours. After that it will kick you out.
$ sudo service ssh reload
@nileshsimaria
nileshsimaria / User belongs to docker group
Last active May 8, 2023 03:57
A user belongs to docker group can gain root access on your host
Be careful if you are adding user to docker group.
1. As a root, create a file (owner root and group root)
$ touch /etc/foo
$ ls -l /etc/foo
-rw-r--r-- 1 root root 0 Dec 5 17:40 /etc/foo
2. Login as a non-root user belongs to docker group. In my example its user u1.
$ id
@nileshsimaria
nileshsimaria / for_range.go
Last active July 18, 2019 03:19
golang: for + range
package main
import "fmt"
func main() {
a := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
b := make([]*int, 10)
for i, v := range a {
b[i] = &v
package main
import (
"fmt"
"os"
)
func main() {
fmt.Println("len", len(os.Args))
package main
import (
"flag"
"fmt"
)
var (
file = flag.String("file", "", "file-name")
count = flag.Int("count", 2, "count params")
package main
import (
"flag"
"fmt"
)
var (
file = flag.String("file", "", "file-name")
count = flag.Int("count", 2, "count params")