Skip to content

Instantly share code, notes, and snippets.

View aashish-chaubey's full-sized avatar
💻
Furiously Coding

Aashish Chaubey aashish-chaubey

💻
Furiously Coding
View GitHub Profile
@aashish-chaubey
aashish-chaubey / sample_threading.py
Last active December 9, 2018 14:17
Creating threads in python using threading module
from threading import Thread
import time
def job(name):
# Create a process heavy job
time.sleep(2)
print("The name is: %s" % name)
def main():
print("Program starts!")
@aashish-chaubey
aashish-chaubey / Todo.js
Created July 11, 2019 06:07
Making use of `useReducer` React hook for managing the state of the functional component
import React, { useReducer } from 'react';
const reducer = (state, action) => {
switch(action.type) {
case 'add': {
return [
...state,
{
id: Date.now(),
text: '',
/**
* @author: Aashish
* Date: 13-07-2019
*/
import java.util.*;
class Solution {
static class Graph {
@aashish-chaubey
aashish-chaubey / promise.js
Created August 20, 2019 20:25
Implementing and using the basic promise
/**
* @author Aashish Chaubey
* @link https://github.com/aashish-chaubey
*/
/**
* First Create a Promise my implementing it with a `new` keyword
* Do all the heavy weight operations in the promise
* Store the promise in a variable
*/
@aashish-chaubey
aashish-chaubey / Levenshtein Distance - Using fuzzywuzzy package
Created October 30, 2019 05:41
Using the fuzzywuzzy package to calculate the distance between 2 strings
### Using the fuzzywuzzy package
fuzzywuzzy package in python implements the Lavenshtein distance between two string to calculate the similarity between the two.
Install 2 packages:
pip install fuzzywuzzy
pip install python-Levenshtein / conda install -c conda-forge python-levenshtein
`[I actually had an issue installing the package, so I used the conda installation for this this package]`
This package is required to suppress the warning for the default slow fuzzywuzzy package.
@aashish-chaubey
aashish-chaubey / ibm_cos_data.py
Created January 12, 2020 18:27
Python Code to pull out data from IBM Cloud Object Store
import ibm_boto3
from ibm_botocore.client import Config, ClientError
# Constants for IBM COS values
COS_ENDPOINT = # Current list avaiable at https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints
COS_API_KEY_ID = # eg "W00YiRnLW4a3fTjMB-odB-2ySfTrFBIQQWanc--P3byk"
COS_AUTH_ENDPOINT = "https://iam.cloud.ibm.com/identity/token"
COS_RESOURCE_CRN = # eg "crn:v1:bluemix:public:cloud-object-storage:global:a/3bf0d9003abfb5d29761c3e97696b71c:d6f04d83-6c4f-4a62-a165-696756d63903::"
# Create resource
@aashish-chaubey
aashish-chaubey / filetype.py
Last active February 14, 2020 07:41
Checking if the file binary is a RIFF type or any other type
start_text = "RIFF"
import os
for i, filename in enumerate(os.listdir('./')):
with open(filename, 'rb') as imageFile:
if imageFile.read().startswith(b'RIFF'):
print(f"{i+1}: {filename} - found!")
else:
continue
@aashish-chaubey
aashish-chaubey / firebase_create_user.py
Last active February 15, 2020 09:12
manual user registraion
import firebase_admin
from firebase_admin import credentials
from firebase_admin import auth
cred = credentials.Certificate('secreatFile.json')
default_app = firebase_admin.initialize_app(cred)
# Search a user by email, ig registered
user = auth.get_user_by_email('chaubey.aashish@gmail.com')
import pandas as pd
df = pd.DataFrame({'agent_id': [1, 1, 1, 1, 2, 2, 2, 2],
'date': ["2021-01-01", "2021-04-01", "2021-05-01", "2021-06-01", "2021-01-01", "2021-02-01", "2021-03-01", "2021-06-01"],
'txn_amount': [100, 200, 100, 200, 100, 200, 100, 200],
'txn_status': ["Failure", "Success", "Failure", "Success", "Failure", "Success", "Failure", "Success"]})
df['date'] = pd.to_datetime(df['date'], format='%Y-%m-%d')
df1 = df.set_index('date')
@aashish-chaubey
aashish-chaubey / prime_numbers.py
Created August 6, 2022 07:18
Find all the numbers between 1-50 and print them in a list
import math
l = 50
def is_prime(num: int) -> bool:
lim = math.floor(math.sqrt(num))
for i in range(2, lim+1):
if num % i == 0:
return False
return True