Skip to content

Instantly share code, notes, and snippets.

View Laxman-SM's full-sized avatar

Laxman Singh Laxman-SM

  • Ex-Phenome, Ex-Intertrust, Ex-Wipro
  • US, Hyderabad (india)
View GitHub Profile
@Laxman-SM
Laxman-SM / docker-login-ecr-sso.py
Created September 15, 2023 08:44 — forked from bdclark/docker-login-ecr-sso.py
Script to perform docker login to AWS ECR using AWS SSO config
#!/usr/bin/env python
import argparse
import configparser
from shutil import which
import subprocess
import sys
import os
CONFIG_PATH = os.path.expanduser("~/.aws/config")
@Laxman-SM
Laxman-SM / mirror-dockerhub-repos-to-ecr.sh
Created September 8, 2023 11:38 — forked from shmileee/mirror-dockerhub-repos-to-ecr.sh
Mirror all private images from DockerHub organisation to ECR
#!/bin/bash
ecr_url="<account id>.dkr.ecr.<region>.amazonaws.com"
# set username, password, and organization
dockerhub_username="<user>"
dockerhub_password="<password>"
dockerhub_organization="<org>"
dockerhub_api_url="https://hub.docker.com/v2"
dockerhub_token=$(curl -s -H "Content-Type: application/json" -X POST -d \
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: script
spec:
schedule: "*/2 * * * *"
jobTemplate:
spec:
template:
@Laxman-SM
Laxman-SM / myips.sh
Created August 11, 2023 04:07 — forked from haukurk/myips.sh
cli myips
# return my IP addresses
function myip() {
ExtIP=`dig TXT +short o-o.myaddr.l.google.com @ns1.google.com`
echo $ExtIP | tr -d '"' | awk '{print "external : " $1}'
ifconfig lo0 | grep 'inet ' | sed -e 's/:/ /' | awk '{print "lo0 : " $2}'
ifconfig en0 | grep 'inet ' | sed -e 's/:/ /' | awk '{print "en0 (IPv4): " $2 " " $3 " " $4 " " $5 " " $6}'
ifconfig en0 | grep 'inet6 ' | sed -e 's/ / /' | awk '{print "en0 (IPv6): " $2 " " $3 " " $4 " " $5 " " $6}'
ifconfig en1 | grep 'inet ' | sed -e 's/:/ /' | awk '{print "en1 (IPv4): " $2 " " $3 " " $4 " " $5 " " $6}'
ifconfig en1 | grep 'inet6 ' | sed -e 's/ / /' | awk '{print "en1 (IPv6): " $2 " " $3 " " $4 " " $5 " " $6}'
}
@Laxman-SM
Laxman-SM / atlas.py
Created August 11, 2023 04:06 — forked from kenseii/atlas.py
Automating the IAM role connection to MongoDB atlas
import os
from pulumi import get_stack, get_project # so that each resource has a project & staging/dev... in AWS console
import pulumi_mongodbatlas as mongodbatlas
ACCOUNT_ID = os.environ["ACCOUNT_ID"]
ATLAS_PROJECT_ID = os.environ["ATLAS_PROJECT_ID"]
my_func_role_arn = f"arn:aws:iam::{ACCOUNT_ID}:role/{get_project()}-{get_stack()}-my-func-iam-role"
lambda_cloud_provider_access = mongodbatlas.CloudProviderAccess(
@Laxman-SM
Laxman-SM / parse-inventory-progress.py
Created August 11, 2023 04:04 — forked from alukach/parse-inventory-progress.py
Parsing S3 Inventory results in Python
#! /usr/bin/env python3
"""
A utility to stream records from one or many S3 Inventory reports, with a progress bar.
./parse-inventory-progress s3://my-bucket/path/to/my/inventory/2019-12-15T00-00Z/manifest.json > out.csv
"""
import json
import csv
import gzip
import sys
@Laxman-SM
Laxman-SM / postgres-cheatsheet.md
Created July 21, 2023 09:59 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@Laxman-SM
Laxman-SM / secretsmanager.sh
Created July 10, 2023 09:39 — forked from mrcnc/secretsmanager.sh
aws secrets manager cli usage
aws secretsmanager list-secrets
aws secretsmanager describe-secret \
--secret-id arn:aws:secretsmanager:us-west-2:432117387956:secret:my-db-credentials-Ny5zb7
aws secretsmanager get-secret-value \
--secret-id arn:aws:secretsmanager:us-west-2:432117387956:secret:my-db-credentials-Ny5zb7
aws secretsmanager get-secret-value --secret-id my-db-credentials

Prompt Manipulation

Cursor Movement

Move the cursor to Destination.

Command Destination
Ctrl + a Start of line
Ctrl + e End of line
@Laxman-SM
Laxman-SM / docker-wsl2-setup.sh
Created April 26, 2023 04:32 — forked from Athou/docker-wsl2-setup.sh
install docker in Debian 11/WSL2 without Docker Desktop
# install docker in Debian 11/WSL2
# uses systemd-genie since docker requires systemd but it's not available for WSL
# this is an alternative to Docker Desktop
# prerequisites
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ca-certificates curl wget gnupg lsb-release apt-transport-https
# systemd-genie requires dotnet runtime, add Microsoft repo