Skip to content

Instantly share code, notes, and snippets.

View shashwata27's full-sized avatar
🎯
Focusing

Shashwata Saha shashwata27

🎯
Focusing
View GitHub Profile
@shashwata27
shashwata27 / pandas_labeled_csv_import_to_mongo.py
Last active February 21, 2024 20:32 — forked from jxub/pandas_labeled_csv_import_to_mongo.py
A simple mongoimport for importing csv files with python and pymongo
import pandas as pd
from pymongo import MongoClient
import json
def mongoimport(csv_path, db_name, coll_name, db_url='localhost', db_port=27000)
""" Imports a csv file at path csv_name to a mongo colection
returns: count of the documants in the new collection
"""
client = MongoClient(db_url, db_port)
db = client[db_name]
@shashwata27
shashwata27 / Action.ts
Last active January 22, 2024 17:04
Loaders And Actions: React Router
type TRequestType = "GET" | "POST" | "PUT" | "PATCH";
export const loaderAction = async ({
params,
request,
}: {
params: Object;
request: Request;
}) => {
const data = await request.formData();
@shashwata27
shashwata27 / Switch Java Version CMD.bat
Created July 5, 2022 16:19
Switch Java Version from CMD
:: In environment variables set JAVA_HOME as the latest jdk then set PATH as %JAVA_HOME%\bin
@echo off
if "%~1" == "15" (
set "JAVA_HOME=C:\Program Files\Java\jdk-15.0.2"
echo JAVA 15 Activated.
) else if "%~1" == "8" (
set "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_331"
echo JAVA 8 Activated.
)
set "Path=%JAVA_HOME%\bin;%Path%"
from pymongo import MongoClient
cur=MongoClient(MONGO_HOST,MONGO_PORT)
# create db, if db dosen't exsists
db=cur[DB_NAME]
# create collection, if db dosen't exsists
col=db[COLLECTION_NAME]
#decorators take a function as input and enhances it and returns the function
# function within a function which adds some features to the function and returns it
def decor(num):
def inner():
print("enhanced")
num()
return inner
def num1():
from string import ascii_lowercase
from words import get_random_word
def get_num_attempts():
"""Get user-inputted number of incorrect attempts for the game."""
while True:
num_attempts = input(
'How many incorrect attempts do you want? [1-25] ')
try:
@shashwata27
shashwata27 / BrandSurvey.py
Created May 5, 2020 15:06
Market Survey Season 8
QuestionNo=int(input())
ParticipentNo=int(input())
DefaultKey=input()
KeyRecord={}
lastkey=[0]*QuestionNo*5
def keyer(key,DK=False):
lastkeyindex=0
if not DK:
for y in range(ParticipentNo):
@shashwata27
shashwata27 / oyoTablechairs.py
Created May 2, 2020 11:48
For each of the four banks of the pool, he wants to have an equal number of tablechairs. There are three types of tablechairs set in the outlet. It is possible to buy a set of one tablechairs for R1 rupees, a set of two tablechairs for R2 rupees, and a set of three tablechairs for R3 rupees. The manager already has M tablechairs. What is the min…
testCases=int(input())
for y in range(testCases):
string=input()
Ch=0
index=string.find(" ")
M=int(string[:index])
string=string[index+1:]
index = string.find(" ")
R1 = int(string[:index])