Skip to content

Instantly share code, notes, and snippets.

View ahmetozer's full-sized avatar
🖐️
Hi , thank you for visiting.

Ahmet ÖZER ahmetozer

🖐️
Hi , thank you for visiting.
View GitHub Profile
@ahmetozer
ahmetozer / check-required-apps.go
Created May 20, 2020 19:15
Golang check required apps
requiredPrograms := []string{"nc", "ls", "bash", "mkdir"}
var requiredapps [4]bool
for i, s := range requiredPrograms {
// Get path of required programs
path, err := exec.LookPath(s)
if err == nil {
fmt.Printf("Required program %v %v found at %v\n", i+1, s, path)
requiredapps[i] = true //save to array
} else {
fmt.Printf("Required program %v %v cannot found.\n", i+1, s)
@ahmetozer
ahmetozer / IPv4-IPv6-domain-regex.go
Last active October 28, 2024 07:25
Ipv4 - IPv6 - domain Regex Golang
ipv6_regex := `^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$`
ipv4_regex := `^(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4})`
domain_regex := `^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$`
match, _ := regexp.MatchString(ipv4_regex+`|`+ipv6_regex+`|`+domain_regex, host)
if match {
fmt.Println("Input is valid")
} else {
fmt.Println("Given input does not match")
re
@ahmetozer
ahmetozer / Gocker-auto-run.sh
Created May 19, 2020 14:41
Golang auto run for every change in folder
#!/bin/bash
# Gocker is my docker alias to create temporarily conteiner to test go aplications.
# You can find alias https://gist.github.com/ahmetozer/cf32f7f3a8cc9ad0f4ee83765649a1dc
while inotifywait -r -q -e modify,create,delete,move .
do
killall go
kill -9 `netstat -ltnp | grep -v -E "Program name" | grep -v "Active Internet connections (only servers)" | cut -d"N" -f2 |sed 's/ //g' | cut -d"/" -f1` > /dev/null
go run *.go &
done
@ahmetozer
ahmetozer / .gitconfig
Created May 13, 2020 17:06
Use SSH instead of HTTPS in Git
[url "ssh://[email protected]/"]
insteadOf = https://github.com/
[url "ssh://[email protected]/"]
insteadOf = https://gitlab.com/
[url "ssh://[email protected]/"]
insteadOf = https://bitbucket.org/
@ahmetozer
ahmetozer / Regex.lib.sh
Created May 12, 2020 21:40
My regex liblary
port_regex="^((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([1-9][0-9]{3})|([1-9][0-9]{2})|([1-9][0-9])|([1-9]))$"
user_regex="^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$"
@ahmetozer
ahmetozer / nginx.conf
Created April 21, 2020 10:17
Convert HTTP server to HTTPS with NGINX - SSL Proxy
server {
listen 443 http2 ssl;
listen [::]:443 http2 ssl;
server_name yourdomain;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
@ahmetozer
ahmetozer / nginx.conf
Created April 21, 2020 10:08
Convert HTTP server to HTTPS server with NGINX Stream - SSL Termination
stream {
server {
listen 443 ssl;
proxy_pass my.local.application:80;
ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/certs/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_session_cache shared:SSL:20m;
@ahmetozer
ahmetozer / multiple-exec-at-go-example.go
Created April 20, 2020 16:23
Golang Multiple exec.Command at same time with pipelining
package main
import (
// "fmt"
"os/exec"
"os"
)
func main() {
topCommand := exec.Command("top","-d 0.5", "-b", "-n 5")
@ahmetozer
ahmetozer / docker.profile
Created April 18, 2020 15:06
Container bash profile.
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
# To use --mount type=bind,source=/root/docker.profile,target=/root/.bashrc,readonly argument on your docker run command
if [ "${PS1-}" ]; then
if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
@ahmetozer
ahmetozer / alias.sh
Created April 18, 2020 14:12
My aliases for build env
git_profile_url='github.com/AhmetOZER'
alias gocker='docker run -it --rm -v $(pwd):/go/src/$git_profile_url/golang/$(basename $(pwd)) golang'