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 / main.go
Last active November 16, 2023 20:06
Creating goroutines within cron job
package main
import (
"fmt"
"http://github.com/robfig/cron/v3"
"sync"
"time"
)
func one() {
@aashish-chaubey
aashish-chaubey / vowels_name.py
Created August 6, 2022 07:31
Count all the vowels in the name and show count of each of them
from collections import Counter
name = "Aashish Chaubey"
vowels = "aeiou"
vowels_list = list(filter(lambda x: x in vowels, name.lower()))
print(f"Number of vowels in name is: {len(vowels_list)}")
print(dict(Counter(vowels_list)))
@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
def taskOfPairing(freq):
count = 0
marker = False
for i in freq:
if i != 0:
count += i // 2
if i % 2 != 0 and marker:
count += 1
marker = False
elif i % 2 != 0:
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 / 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')
@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 / 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 / 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 / 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
*/