Skip to content

Instantly share code, notes, and snippets.

View RahulDas-dev's full-sized avatar
🏠
Working from home

Rahul Das RahulDas-dev

🏠
Working from home
View GitHub Profile
@RahulDas-dev
RahulDas-dev / dataclass.py
Last active December 18, 2022 16:20
Dataclass Example
from dataclasses import dataclass, field
from pprint import pprint
import inspect
@dataclass(frozen=True)
class Dimension:
height: float
width: float
depth: float
@RahulDas-dev
RahulDas-dev / Dataclass_with_init.py
Created January 13, 2022 19:11
Dataclass with init ,field modification while object initialization
@dataclass(frozen=True, init= False)
class Dimension:
height: float
width: float
depth: float
def __init__(self,height,width,depth ):
object.__setattr__(self, "height", int(round(height)))
object.__setattr__(self, "width", int(round(width)))
object.__setattr__(self, "depth", int(round(depth)))
@RahulDas-dev
RahulDas-dev / dataclass_inheritance.py
Created January 13, 2022 19:12
Dataclass with inheritanceExample.
from dataclasses import dataclass, field
from pprint import pprint
import inspect
@dataclass(frozen=True, init= False)
class Dimension:
height: float
width: float
depth: float
@RahulDas-dev
RahulDas-dev / import.py
Created January 15, 2022 14:23
Jupyter notebook import relative module from parent folder
import os
import sys
import inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
#print(currentdir)
parentdir = os.path.dirname(currentdir)
lib_path = os.path.join(parentdir,'src')
#print(parentdir, lib_path)
sys.path.insert(0,lib_path)
@RahulDas-dev
RahulDas-dev / sliding_window.py
Created August 8, 2022 08:29
1D Sliding Window
import math
from typing import List
def sliding_window(input_: List[int], kernel_: List[int]) -> List[int]:
# Checking input and kernel length constraint
if len(kernel_) > len(input_):
raise ValueError("Input Size must be gratter than Kernel size")
start_index = 0
@RahulDas-dev
RahulDas-dev / test_train_split.py
Last active August 8, 2022 10:41
Spliting Pandas Dataframe into Train and Test Datasets
import math
import pandas
# Loading data into pandas Dataframe
dataset = pd.read_csv(dataset_path)
print(f'dataset {dataset.shape}')
dataset.head()
#Shuffling the Dataset
@RahulDas-dev
RahulDas-dev / plots_graph_side_by_side.ipynb
Last active August 11, 2022 11:53
Matplotlib Plot Graph Side by Side
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@RahulDas-dev
RahulDas-dev / pipleline.py
Last active August 25, 2022 11:05
Simple Pipeline Patteren using reduce method
from functools import reduce
# creates pipeline object from list of callables
def make_pipeline(list_of_callables):
return reduce(lambda f,g: lambda x: g(f(x)), list_of_callables)
add1 = lambda x: x+'1' # Oprtaion 1
add2 = lambda x: x+'2' # Oprtaion 2
add3 = lambda x: x+'3' # Oprtaion 3
add4 = lambda x: x+'4' # Oprtaion 4
@RahulDas-dev
RahulDas-dev / pipleline_01.py
Last active August 28, 2022 11:18
Pipeline Patterns Implementation Python
def make_pipeline2(list_of_callables):
def map_2_partials(item):
func = item[0]
#return func if len(item) < 2 else partial(func, **item[1])
if len(item) < 2:
return func
else :
return partial(func, **item[1])
list_of_partials = map(map_2_partials, list_of_callables)
@RahulDas-dev
RahulDas-dev / jupyter_installation.md
Last active October 4, 2022 06:28
The Jupyter Notebook Installation for the Virtual Environment

The Jupyter Notebook Installation for the Virtual Environment

Installation can be done pip install Jupyter. However big list dependency of Jupyter can be avoided by installting ipython kernel module only, if you have Jupyter installed Globally.

  1. Install the ipython kernrl pip install ipykernel
  2. Create a new kernel for your current virtual environment python -m ipykernel install --user --name=<promt>
  3. Launch the notebook with jupyter notebbok from virtual Environment.
  4. You should now be able to see your kernel in the IPython notebook menu: Kernel -> Change kernel

ipython-kernel-selection