Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

dakait

🏠
Working from home
View GitHub Profile
@dakait
dakait / help.txt
Last active Mar 29, 2019
Mysql install/remove
View help.txt
Removing mysql completely
sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
sudo apt-get autoremove -y
sudo apt-get autoclean
rm -rf /etc/mysql
sudo find / -iname 'mysql*' -exec rm -rf {} \;
Installing mysql:
sudo apt install mysql-server mysql-client
@dakait
dakait / decorators.go
Created Aug 29, 2018
Chaining handler functions with gin
View decorators.go
//Golang doesn't have python-Django like decorators but here is
//a small example of what you can do
package main
import "github.com/gin-gonic/gin"
func Handler(h gin.HandlerFunc, decors ...func(gin.HandlerFunc)gin.HandlerFunc) gin.HandlerFunc {
for i := range decors {
@dakait
dakait / code.go
Created Aug 29, 2018
Generate random code golang
View code.go
import "crypto/rand"
func generateRandomSecret(size int) string {
alphanum := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefbgijklmnopqrstuvwxyz0123456789"
var bytes = make([]byte, size)
rand.Read(bytes)
for i, b := range bytes {
bytes[i] = alphanum[b%byte(len(alphanum))]
}
return string(bytes)
@dakait
dakait / cipher.go
Last active Dec 18, 2020
AES-256 GCM Encryption/Decryption Example in Golang
View cipher.go
package secure
import (
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"fmt"
"crypto/sha512"
)
@dakait
dakait / validators.go
Last active Aug 28, 2018
Golang Custom Validator examples
View validators.go
package main
import (
"fmt"
"github.com/satori/go.uuid" //for uuid
"gopkg.in/validator.v2"
"reflect"
"regexp"
"time"
)