Skip to content

Instantly share code, notes, and snippets.

View viiftw's full-sized avatar
❄️
Try not to be lulled into a false sense of security!

Dat Doan viiftw

❄️
Try not to be lulled into a false sense of security!
  • Hanoi, Vietnam
View GitHub Profile
@viiftw
viiftw / fileinfo.go
Created August 19, 2024 10:53 — forked from toddlers/fileinfo.go
getting fileinfo in go
package main
import (
"fmt"
"os"
)
func main() {
// can handle symbolic link, but will no follow the link
@viiftw
viiftw / nginx.conf
Created June 12, 2024 09:33 — forked from kmjones1979/nginx.conf
Example NGINX configuration to route based on country code using GeoIP
# load dynamic modules
load_module /etc/nginx/modules/ngx_http_geoip_module.so;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events { worker_connections 1024; }
http {

I don't expect moby/moby#24170 to be solved by Docker team on near future so this gist is about looking for least ugly workarounds which are available today and on near future.

What is possible on Docker 19.03

Network

It is possible to create overlay network with use user specified subnet. On this example I create network which is size is two C -class networks ( IP range 10.0.0.0 - 10.0.1.255 ) and force Docker to use IPs from second part of it ( 10.0.1.0 - 10.0.1.255 ).

That way I can make sure that IPs 10.0.0.2 - 10.0.0.254 can be specified to containers and they do not collide with IPs which Docker engine assign for service(s)/container(s).

@viiftw
viiftw / clone-git-repo.txt
Last active July 11, 2023 08:18 — forked from fernandoaleman/clone-git-repo.txt
How to clone git repo with all branches and tags
# Clone repo
git clone --mirror [email protected]/fernandoaleman/app.git app/.git
# Change into app directory
cd app
# Update git config
git config --unset core.bare
# Checkout master branch
@viiftw
viiftw / nginx-tuning.md
Created July 3, 2023 10:42 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@viiftw
viiftw / copy_photos.go
Created November 22, 2022 16:52
Đọc từng dòng tên ảnh trong file name.txt, copy ảnh cùng tên từ thư mục input => output
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
)
func Contains(s, value interface{}) bool {
v := reflect.ValueOf(s)
for i := 0; i < v.NumField(); i++ {
field := v.Field(i)
typeOfField := field.Type()
switch typeOfField {
case stringType:
if containsString(field.String(), value) {
return true
}
@viiftw
viiftw / reflect_like_a_boss.go
Last active February 17, 2022 05:30 — forked from olivere/example_test.go
nice way to walk through on an unknown type and put data into
package main
import (
"encoding/json"
"fmt"
"reflect"
)
// nicest way to walk through on an unknown type and put data into
// the Result is an array of JSON content
@viiftw
viiftw / truth.go
Last active February 9, 2022 08:20
An optimization truth
package main
import (
"fmt"
"rsc.io/quote"
)
func main() {
fmt.Println(quote.Opt())
@viiftw
viiftw / interface_to_bytes.go
Created April 19, 2021 08:51 — forked from miguelmota/interface_to_bytes.go
Golang interface to bytes using gob encoder
package main
import (
"encoding/gob"
"bytes"
)
func GetBytes(key interface{}) ([]byte, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)