Skip to content

Instantly share code, notes, and snippets.

View mkamrani's full-sized avatar
💭
Building Utopiops & Do10X

Sam(Mohsen) Kamrani mkamrani

💭
Building Utopiops & Do10X
View GitHub Profile
@mkamrani
mkamrani / add-gtag.sh
Created May 30, 2023 01:12
Add Google Analytics to all HTML files in a directory
#!/bin/bash
# From: dotenx.com
# description:
# Add Google Analytics to all HTML files in a directory. Google Analytics code should be in a file called google-analytics in the same directory as this script.
# usage:
# ./add-gtag.sh directory
@mkamrani
mkamrani / acm_cert.go
Created August 18, 2022 10:53
Request ACM certificate and validate
func requestCertificate(domainName, hostedZoneId string) (string, error) {
cfg := &aws.Config{
Region: aws.String(config.Region),
}
svc := acm.New(session.New(), cfg)
input := &acm.RequestCertificateInput{
DomainName: aws.String(domainName),
IdempotencyToken: aws.String(strings.Replace(domainName, ".", "", -1)),
ValidationMethod: aws.String("DNS"),
@mkamrani
mkamrani / formspree-ajax-contact-form.js
Last active July 12, 2021 12:03 — forked from siamkreative/formspree-ajax-contact-form.js
A plain JavaScript AJAX Contact Form that is designed to work with http://formspree.io/
/**
* AJAX Form
* http://stackoverflow.com/a/13038218/1414881
*/
var requestDemoForm = document.getElementById('aaa_form');
var subscribeNewsLetterForm = document.getElementById('bbb_form');
// Append the form status (you can just alert instead of these)
var formStatus = document.createElement('div');
@mkamrani
mkamrani / enum.go
Created October 31, 2020 10:30 — forked from lummie/enum.go
Golang Enum pattern that can be serialized to json
package enum_example
import (
"bytes"
"encoding/json"
)
// TaskState represents the state of task, moving through Created, Running then Finished or Errorred
type TaskState int
@mkamrani
mkamrani / unmarshal_interface.go
Created June 21, 2020 01:18 — forked from tkrajina/unmarshal_interface.go
Unmarshal JSON to specific interface implementation
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type Something interface{}
@mkamrani
mkamrani / Connecting_postgress_RDS_from_local_via_bastion.md
Created April 6, 2020 04:38 — forked from kshailen/Connecting_postgress_RDS_from_local_via_bastion.md
Ways to connect to postgress RDS instance from bastion host and from local host

When it comes to databases and AWS VPC, best practice is to place your database in private subnet. By definition, private subnet in AWS is not reachable from the Internet because no Internet gateway is attached to private subnet. This is the way you protect your data. This kind of configuration is good for security but bad for data management.

How can you easily access and manage your secured data?

basic_RDS_bastion_architecture

There are two basic ways to acees it.

  1. Access postgres RDS from bastion host. There are following requirements for this.
@mkamrani
mkamrani / docker exec alias
Created October 3, 2019 02:15
A handy alias to execute a command inside a docker container with a specific name (interactive mode)
# put this in ~/.bashrc, or ~/.zshrc, etc., then source ~/.bashrc or source ~/.zshrc
# Use it like dexec <containername> <command> : dexec node bash
dexec() {
name=${1}
command=${2}
docker exec -ti $(docker ps | grep $name | awk '{print $1}') $command
}
@mkamrani
mkamrani / aws-ec2-redis-cli.md
Created September 5, 2019 05:47 — forked from paladini/aws-ec2-redis-cli.md
AWS redis-cli without redis server on AWS EC2

Setup redis-cli without the whole Redis Server on AWS EC2

This fast tutorial will teach you how to install redis-clion AWS EC2 without having to install the whole Redis Server. Firstly, SSH into your EC2 instance and run the following command:

$ sudo yum install gcc

This may return an "already installed" message, but that's OK. After that, just run:

$ wget http://download.redis.io/redis-stable.tar.gz && tar xvzf redis-stable.tar.gz && cd redis-stable && make && sudo cp src/redis-cli /usr/local/bin/ && sudo chmod 755 /usr/local/bin/redis-cli

@mkamrani
mkamrani / CreateJob.sh
Created May 14, 2019 22:11 — forked from stuart-warren/CreateJob.sh
Create a job in Jenkins (or folder) using the HTTP API
# check if job exists
curl -XGET 'http://jenkins/checkJobName?value=yourJobFolderName' --user user.name:YourAPIToken
# with folder plugin
curl -s -XPOST 'http://jenkins/job/FolderName/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
# without folder plugin
curl -s -XPOST 'http://jenkins/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
# create folder
@mkamrani
mkamrani / audit.rules
Created January 13, 2019 23:57 — forked from Neo23x0/audit.rules
Linux Auditd Best Practice Configuration
# IMPORTANT!
# This gist has been transformed into a github repo
# You can find the most recent version there:
# https://github.com/Neo23x0/auditd
# ___ ___ __ __
# / | __ ______/ (_) /_____/ /
# / /| |/ / / / __ / / __/ __ /
# / ___ / /_/ / /_/ / / /_/ /_/ /
# /_/ |_\__,_/\__,_/_/\__/\__,_/