Skip to content

Instantly share code, notes, and snippets.

View siddydutta's full-sized avatar

Siddhartha Dutta siddydutta

View GitHub Profile
@siddydutta
siddydutta / xor_backprop.py
Last active October 19, 2021 19:05
XOR - Backpropagation NN
import numpy as np
#np.random.seed(0)
def sigmoid (x):
return 1/(1 + np.exp(-x))
def sigmoid_derivative(x):
return x * (1 - x)
#Input datasets
@siddydutta
siddydutta / web_scrape_covid.py
Last active April 19, 2020 03:07
Scraping Coronavirus Data from Worldometers
import requests
from bs4 import BeautifulSoup
import csv
url = 'https://www.worldometers.info/coronavirus/'
resp = requests.get(url)
soup = BeautifulSoup(resp.content, 'lxml')
data_table = soup.find('table', attrs={'id':'main_table_countries_today'})
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
raw_data = pd.read_csv('data.csv',encoding='latin1',thousands=',')
# Top 5 Countries Affected
data = raw_data[['Country,Other','TotalCases','TotalDeaths','TotalRecovered']]
most_affected = data.sort_values('TotalCases', ascending=False)[:5]
plt.figure(figsize=(10,5))
@siddydutta
siddydutta / convulation.py
Created November 26, 2020 15:19
A function that applies the convolution operation to a given image with a given kernel with or without padding.
# -*- coding: utf-8 -*-
import cv2
import numpy as np
def convulate(image, kernel, padding=False, paddingType=cv2.BORDER_CONSTANT):
'''
@param image: 2D array of type <numpy.ndarray> for given image.
@param kernel: 2D array of type <numpy.ndarray> for given kernel.
@param padding: Type <bool> to indicate if padding required.
@siddydutta
siddydutta / CodingMinutesDP.py
Last active August 9, 2021 09:26
Questions based on the session on Dynamic Programming by Apaar Kamal
# -*- coding: utf-8 -*-
"""
Questions based on the session on Dynamic Programming by Apaar Kamal.
https://join.codingminutes.com/dp-08
Alice and Bob are playing a game. Alice plays first.
We have a pile of n stones.
Q1.
@siddydutta
siddydutta / DSA_SubstringTemplate.py
Last active August 16, 2021 16:01
A Python template to solve most problems involving substrings using a two-pointer approach.
"""
A Python template to solve most problems involving substrings using a two-pointer approach.
Template based on this post: https://leetcode.com/problems/minimum-window-substring/discuss/26808/Here-is-a-10-line-template-that-can-solve-most-'substring'-problems
"""
def substring(string: str) -> int:
counter = int() # To check if the substring is valid
left, right = 0, 0 # Two pointers, right pointer is exclusive
length = int() # Length of the substring
map = dict() # Intialize the hash map here, collections.Counter is useful
@siddydutta
siddydutta / script.js
Created August 29, 2021 07:14
HackerRank - JavaScript Basic Assessment - Country Codes
// HackerRank's NodeJS environment allows the `request` package.
const request = require('request');
function fetch(url) {
return new Promise((resolve, reject) => {
request(url, function (error, response, body) {
if (error)
reject(error)
else
resolve(body)
@siddydutta
siddydutta / system_test_script.py
Created August 30, 2021 12:54
Coursera - Continuous Delivery & DevOps - System Test Example
# -*- coding: utf-8 -*-
'''
This is a program for University of Virginia's "Continous Delivery and DevOps"
course on Coursera. This script demonstrates the System Test example using
the Selenium webdriver.
'''
from random import randint
from selenium import webdriver
@siddydutta
siddydutta / AZ-900-Notes.txt
Created September 11, 2021 12:53
AZ-900 exam notes in byte sizes
Azure Fundamentals Part 1: Describe core Azure concepts
Cloud computing is the delivery of computing services over the internet by using a pay-as-you-go pricing model. You typically pay only for the cloud services you use, which helps you:
Lower your operating costs.
Run your infrastructure more efficiently.
Scale as your business needs change.
Types of Cloud Models
Public cloud
No capital expenditures to scale up.
@siddydutta
siddydutta / DSA_BinarySearchTemplate.py
Last active November 20, 2021 05:27
A Python template to solve problems involving binary search.
"""
A Python template to solve problems involving binary search.
Template based on this post: https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/discuss/769704/Python-Clear-explanation-Powerful-Ultimate-Binary-Search-Template.-Solved-many-problems.
"""
def binary_search(array) -> int:
def condition(value) -> bool:
# Conditional logic based on question
# Returns true if current value satisfies requirements
# binary search will take care of finding the minimal val
return