Skip to content

Instantly share code, notes, and snippets.

@vinodjayachandran
vinodjayachandran / open_exchange.py
Created April 12, 2024 06:27
Python Script to fetch Open exchange rates
import requests
import os
def fetchExchangeRate(currencyDate, baseCurrency, currencySymbol):
"""
Method to fetch open Currency exchange rate of base currency (1 Unit) to a currencySymbol
Reference : https://docs.openexchangerates.org/reference/api-introduction
Args:
currencyDate: Date for which you need open exchange rate.
baseCurrency: ISO currency code
@vinodjayachandran
vinodjayachandran / LanguageTranslator.py
Created April 4, 2024 06:19
Language translations using OpenAI
from openai import OpenAI
# Read OpenAI API Key from environment variable
api_key = os.environ.get("OPENAI_API_KEY")
client = OpenAI(api_key=api_key)
def translate_text(text):
model = "gpt-4-turbo-preview",
response = client.chat.completions.create(
model="gpt-3.5-turbo-0125",
@vinodjayachandran
vinodjayachandran / main.py
Last active April 3, 2024 11:33
From a folder containing Invoice/Receipt Images, extract Information using Open AI (gpt-4-vision-preview)
# File showing usage of openaiUtil.py
import openaiUtil
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print(" Welcome")
print(openaiUtil.question_image(openaiUtil.generate_payload("image_folder_path")))
@vinodjayachandran
vinodjayachandran / LRUCache.java
Created October 26, 2023 11:57
Implementation of LRUCache using LinkedHashMap
import java.util.LinkedHashMap;
import java.util.Map;
public class LRUCache {
int capacity;
LinkedHashMap<String,String> cache;
public LRUCache(int capacity) {
@vinodjayachandran
vinodjayachandran / ElastiCache.ts
Last active April 12, 2023 03:27
Create AWS ElastiCache (Redis) Cluster with encryption in transit and AUTH token
const redisParameterGroup = new elasticache.CfnParameterGroup(this, 'redisParameterGroup', {
cacheParameterGroupFamily: 'redis7',
description: 'Redis Cluster Parameter Overrides',
properties: {
timeout: '120', // Close connection if client is idle for a given number of seconds
},
});
const redisPrimaryReplicationGroup = new elasticache.CfnReplicationGroup(this, 'redisPrimaryReplicationGroup', {
replicationGroupDescription: '{CLUSTER_DESCRIPTION}',
@vinodjayachandran
vinodjayachandran / JedisConnection.java
Created March 2, 2023 05:26
Connect to ElastiCache (Redis) with Encryption in Transit and Auth token enabled
package com.elasticache;
import lombok.extern.log4j.Log4j2;
import redis.clients.jedis.Jedis;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocketFactory;
import java.net.URI;
/**
@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
@vinodjayachandran
vinodjayachandran / PubSub.py
Last active September 6, 2021 13:18
Publish and Subscribe on a topic of GCP PubSub
import os
from google.cloud import pubsub
from concurrent.futures import TimeoutError
project_id = "your-project-id"
topic_id = "topic-id-from-gcp-console"
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path-to-your-credential-json-file"
publisher = pubsub.PublisherClient()
@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 / 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;