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 / GetAllInstances.py
Last active October 3, 2017 19:42
Python Program for getting all the details of running instances and tagging the instances
__author__ = 'Amal G Jose'
import sys
import boto
class GetAllInstances(object):
def __init__(self):
self.aws_access_key = 'XXXXXXXXXXXXXXX'
self.aws_secret_key = 'XXXXXXXXXXXXXXX'
if self.aws_access_key == '' or self.aws_secret_key == '':
@amalgjose
amalgjose / get_account_id.py
Last active January 1, 2018 22:51
Code snippet to find the account id.
import boto3
client = boto3.client("sts", aws_access_key_id="XXXXXXXX", aws_secret_access_key="XXXXXXXX")
account_id = client.get_caller_identity()["Account"]
print account_id
@amalgjose
amalgjose / generate_signed_url.py
Last active January 2, 2018 18:41
This code snippet generates a time-bound signed URL for an S3 object.
import boto3
from urlparse import urlparse
__aws_access_key__ = "XXXXXXXXXXXXXXX"
__aws_secret_key__ = "XXXXXXXXXXXXX"
def s3_client():
"""
This method establishes the connection to S3.
@amalgjose
amalgjose / EC2Reboot.py
Created February 27, 2016 08:29
Python program to reboot multiple ec2 instances together. This can be used for performing some scheduled restart of EC2 machines in an Amazon account. I used python boto library for performing this operation.
__author__ = 'Amal G Jose'
import boto.ec2
class EC2Reboot(object):
def __init__(self):
self.instance_id_list = ["i-xxxxxx", "i-xxxxxx", "i-xxxxx", "i-xxxx", "i-xxxxx", "i-xxxxx", "i-xxxxx"]
self.aws_access_key = "XXXXXXXXXXX"
self.aws_secret_key = "XXXXXXXXXXX"
@amalgjose
amalgjose / background_function.py
Last active July 18, 2018 14:27
An example of execution a function in the background. The main execution will continue in the same flow without waiting for the background function to complete and the function set for background will continue its execution in the background
import time
import threading
def background(f):
'''
a threading decorator
use @background above the function you want to run in the background
'''
def backgrnd_func(*a, **kw):
threading.Thread(target=f, args=a, kwargs=kw).start()
@amalgjose
amalgjose / deltalake-example.py
Created October 13, 2019 07:35
Code snippet for demonstrating Delta Lake
%python
# Create a temparory dataset
data = spark.range(0, 50)
data.write.format("delta").save("/tmp/myfirst-delta-table")
# Read the data
df = spark.read.format("delta").load("/tmp/myfirst-delta-table")
df.show()
# Updating the dataset
@amalgjose
amalgjose / send_email.py
Created February 25, 2020 12:41
Python program to send email to multiple users using Send Grid
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
message = Mail(
from_email=('amal@gmail.com', 'Amal G Jose'),
to_emails=[('receiver01@mail.com', 'Receiver 02'), ('receiver02@mail.com', 'Receiver 02')],
subject='Sample Email',
html_content='My test email')
@amalgjose
amalgjose / stack_using_list.py
Created March 7, 2020 05:35
Sample implementation of stack in python using list.
my_first_stack = []
# Push elements to stack using append()
my_first_stack.append('edward')
my_first_stack.append('sabitha')
print('My First Stack')
print(my_first_stack)
@amalgjose
amalgjose / stack_using_queue.py
Created March 7, 2020 06:06
Stack implementation in python using Queue
from queue import LifoQueue as lq
# Initializing a stack with max size as 2
sample_stack = lq(maxsize=2)
# The qsize() function shows the size of the stack
print(sample_stack.qsize())
# Now lets push some elements to stack
# put() will push elements to stack
@amalgjose
amalgjose / stack_using_collections.py
Created March 7, 2020 06:13
Stack implementation using collections module in python
from collections import deque as dq
sample_stack = dq()
# Push elements to stack using append() function
# This is similar to the way we push elements to list
sample_stack.append('Sabitha')
sample_stack.append('Edward')
# Print all the elements in the stack