Skip to content

Instantly share code, notes, and snippets.

@vinodjayachandran
vinodjayachandran / fetchParam.py
Last active July 8, 2020 06:00
Fetch named command line arguments in Python Script
import argparse
parser = argparse.ArgumentParser()
# String Argument
parser.add_argument('-c','--compName', type=str, metavar='compName', help='Competitor name as Input', required=True);
# Optional Integer Arguement,
parser.add_argument('-l','--limit', type=int, metavar='limit', help='Number of recrods to fetch', required=False);
# Date arguement with format validation
def lambda_date_args(s):
if(s is not None or s != '' ):
@vinodjayachandran
vinodjayachandran / fetchAWSSecrets.py
Created July 9, 2020 07:11
Fetch secrets from AWS Secret Manager
import boto3
from botocore.exceptions import ClientError
def get_secret():
secret_name = "mysql/lowes-matching-prod/demo"
region_name = "us-west-2"
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
@vinodjayachandran
vinodjayachandran / aws-ses.py
Created July 10, 2020 07:19
[AWS-SES][Python]Send e-mail with attachment using command line arguments
import os
import boto3
import argparse
from botocore.exceptions import ClientError
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
parser = argparse.ArgumentParser(description='Send e-mail through aws-ses')
@vinodjayachandran
vinodjayachandran / uploadToS3.py
Created July 24, 2020 05:52
[Python] Upload file to AWS S3
import boto3
from botocore.exceptions import ClientError
def upload_file(file_name, bucket, object_name):
"""Upload a file to an S3 bucket
:param file_name: File to upload
:param bucket: Bucket to upload to
:param object_name: S3 object name. If not specified then file_name is used
:return: True if file was uploaded, else False
@vinodjayachandran
vinodjayachandran / SubArrayWithGivenSum.java
Created August 14, 2020 18:12
Subarray with given sum - Given an unsorted array A of size N of non-negative integers, find the first occurrence of continuous sub-array which adds to a given number S. Print the start and end index (0 based) as output
import java.util.Scanner;
public class SubArrayWithGivenSum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the Array as space separated String");
String [] inputStrArray = input.nextLine().split(" ");
// Convert String array to int array
@vinodjayachandran
vinodjayachandran / CountTriplets.java
Created August 15, 2020 12:47
Count the triplets - Given an array of distinct integers. The task is to count all the triplets such that sum of two elements equals the third element.
import java.util.ArrayList;
import java.util.Collections;
public class CountTriplets {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Integer> inputList = new ArrayList<Integer>();
for (int i = 0; i < args.length; i++) {
inputList.add(Integer.parseInt(args[i]));
@vinodjayachandran
vinodjayachandran / Kadanes.java
Created August 16, 2020 10:54
Kadane's Algorithm - Given an array of N integers, Find the maximum sum in a contiguous sub-array
public class Kadanes {
public static void main(String args[]) {
int max_value = Integer.MIN_VALUE;
// Convert input to string array
int [] inputArray = new int [args.length];
for (int i = 0; i < args.length; i++) {
inputArray[i] = Integer.parseInt(args[i]);
}
int max_value_so_far = 0;
@vinodjayachandran
vinodjayachandran / MissingNumber.java
Last active August 16, 2020 11:15
Missing number in array - Given an array C of size N-1 and given that there are numbers from 1 to N with one element missing, the missing number is to be found.
import java.util.Scanner;
public class MissingNumber {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("Please enter the value of N");
int N = Integer.parseInt(input.nextLine());
int expectedSum = (N * (N+1))/2;
@vinodjayachandran
vinodjayachandran / MergeTwoSortedArray.java
Created August 17, 2020 06:54
Merge Without Extra Space - Given two sorted arrays arr1[] and arr2[] in non-decreasing order with size n and m. The task is to merge the two sorted arrays into one sorted array (in non-decreasing order).
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class MergeTwoSortedArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner userInput = new Scanner(System.in);
@vinodjayachandran
vinodjayachandran / crawl.py
Created June 26, 2021 15:07
Crawl Static HTML and Save it to File
from pathlib import Path
from urllib.request import Request, urlopen
class Crawl:
# Download the HTML Content of the URL and return absolute path of the HTML file
@staticmethod
def fetch(outputDirectory,url):
try:
# Create the output directory if not exists