Skip to content

Instantly share code, notes, and snippets.

View amalgjose's full-sized avatar
🎯
Focusing

Amal G Jose amalgjose

🎯
Focusing
View GitHub Profile
@amalgjose
amalgjose / connect_private_rds.py
Created March 22, 2022 06:03 — forked from riddhi89/connect_private_rds.py
Connecting to a private AWS RDS instance in python
from sshtunnel import SSHTunnelForwarder
import pymysql
with SSHTunnelForwarder(
('ec2-52-202-194-76.public-ec2-instance.amazonaws.com'),
ssh_username="ec2-user",
ssh_pkey="~/ssh-tunnel-rds.pem",
remote_bind_address=('private-rds-instance.ckfkidfytpr4.us-east-1.rds.amazonaws.com', 3306)
) as tunnel:
print("****SSH Tunnel Established****")
@amalgjose
amalgjose / euclidean_distance.py
Last active January 26, 2022 16:54
Python program to find the points which is closer to a point P in a two dimensional plane.
import math
n = int(input("Enter the number of points\n"))
line_points = []
for i in range(n):
x, y = input("Enter the coordinate x,y \n").split(',')
coordinates = [int(x), int(y)]
line_points.append(coordinates)
xp, yp = input("Enter the coordinate of center point P \n").split(',')
@amalgjose
amalgjose / list_ec2_instances.py
Last active February 22, 2024 13:06
Python program to list all ec2 instances in a region using boto3
import boto3
access_key = "XXXXXXXXXXXXXXXXXX"
secret_key = "XXXXXXXXXXXXXXXXXX"
region = 'us-east-1'
client = boto3.client('ec2', aws_access_key_id=access_key, aws_secret_access_key=secret_key,
region_name=region)
conn = boto3.resource('ec2', aws_access_key_id=access_key, aws_secret_access_key=secret_key, region_name=region)
@amalgjose
amalgjose / chrony.conf
Created May 26, 2021 18:45
Chrony configuration file to sync the system timestamp with host server's timestamp. For more details visit https://amalgjose.com
apt-get update
apt-get install chrony -y
cp -pr /etc/chrony/chrony.conf /etc/chrony/chrony.conf.bk
vim /etc/chrony/chrony.conf
=========================chrony.conf==============================
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usuable directives.
from pprint import pprint
sample_json = {
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
@amalgjose
amalgjose / python_adls_connect_service_principle.py
Created April 22, 2021 17:07
A Python program to connect to Azure ADLS Gen2 (Storage Account) using azure service principle instead of the connection string.
from azure.identity import ClientSecretCredential
from azure.storage.blob import BlobServiceClient
# Tenant ID for your Azure Subscription
TENANT_ID = "85XXX93e-XXXX-XXXX-XXXXX-96150XXX893e"
# Your Service Principal App ID (Client ID)
CLIENT_ID = "a3XXX40d-xxxxxxx-0ff72XXXX66a"
# Your Service Principal Password (Client Secret)
@amalgjose
amalgjose / gunicorn_hooks_config.py
Created March 23, 2021 10:17
A sample gunicorn hooks configuration
def on_starting(server):
"""
Do something on server start
"""
print("Server has started")
def on_reload(server):
"""
@amalgjose
amalgjose / fast_api_sample.py
Created February 28, 2021 05:33
A sample GET API implementation using Python FastAPI. For more details, refer to https://amalgjose.com
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def my_first_get_api():
"""
Sample GET method implementation using FastAPI
:return:
@amalgjose
amalgjose / slack_send_notification.py
Created December 20, 2020 04:05
Sample program to send slack notification using webhook
import json
import sys
import requests
URL = ""
message = ""
def send_notification(url, message):
title = (f"DMP Notification :zap:")
@amalgjose
amalgjose / split_large_csv_file.py
Created October 10, 2020 12:59
Python program to split a large csv or delimited file into smaller file. For more details, refer to https://amalgjose.com
import os
import json
import pandas as pd
def data_extractor(file_path, delimiter, required_fields=[]):
"""
:param file_path:
:param delimiter:
:param required_fields: