Generate a self-signed certificate for Golang

Use OpenSSL generate a self-signed certificate for Golang. In this code snippet I created a certificate with validity of 15 years. openssl genrsa -out server.key 2048 openssl req -new -x509 -sha256 -key server.key -out server.crt -days 5475 Once you create the certificate and key you can use it in your Golang HTTP like this log.Fatal(http.ListenAndServeTLS(“:”+port, […]

Continue Reading…

Randomly create a time.Sleep in Golang

To randomly create a time.Sleep in Golang you can use the code snippet below. You may want to simulate a load in your web server and have an arbitrary seconds or minutes before getting the reply. rand.Seed(time.Now().UnixNano()) delta := rand.Intn(60 + 1) // randomly generates numbers 1 to 60 time.Sleep(time.Duration(delta) * time.Second) // sleep and […]

Continue Reading…

HTML drop-down placeholder

Do you ever wanted to have an HTML drop-down with default selected value (placeholder) that the user cannot re-select once they selected any valid value options? It can be done easily by adding selected and disabled attributes on the option element. Code Snippet <div class="row form-group"> <label class="col-12 pl-0">Status</label> <select class="form-control col-12"> <option value="" selected="selected" […]

Continue Reading…

Create Android Studio Shortcut on Ubuntu 18.04

You can easily create an Android Studio shortcut by creating an desktop entry using the following the steps below. In this guide, my Android Studio is installed in /opt/android-studio folder. Your folder location may differ. 1. Open terminal and type cd ~/.local/share/applications 2. Create a .desktop file using your favorite text editor nano android-studio.desktop 3. […]

Continue Reading…