Skip to content

Instantly share code, notes, and snippets.

View bhuiyanmobasshir94's full-sized avatar
🎖️
Focused on achievement

Mobasshir Bhuiya bhuiyanmobasshir94

🎖️
Focused on achievement
View GitHub Profile
def extract_error_message(value, message = ''):
for k, v in value.items():
if isinstance(v,dict):
message += f'{k} -> '
message = extract_error_message(v, message)
else:
if isinstance(v,list):
message += f'{k} : {v[0]}, '
else:
message += f'{k} : {v}, '
import string
import re
def clean_text(text):
text = text.translate(string.punctuation)
## Convert words to lower case and split them
text = text.lower().split()
## Remove stop words
stops = set(stopwords.words("english"))
@bhuiyanmobasshir94
bhuiyanmobasshir94 / json_key_extractor.py
Created April 18, 2020 00:41
How to find a particular json value by key?
from __future__ import print_function
import json
def find_values(id, json_repr):
results = []
def _decode_dict(a_dict):
try:
results.append(a_dict[id])
except KeyError:
def column_dropper(df, threshold):
# Takes a dataframe and threshold for missing values. Returns a dataframe.
total_records = df.count()
for col in df.columns:
# Calculate the percentage of missing values
missing = df.where(df[col].isNull()).count()
missing_percent = missing / total_records
# Drop column if percent of missing is more than threshold
if missing_percent > threshold:
df = df.drop(col)
# pip install modin[all]
# import modin.pandas as mpd
import pandas as pd
import math
def handler(df, n_rows, file_name):
if df.shape[0] >= n_rows:
split_index_ = int(df.index[0]) + n_rows
split_index = n_rows
new_df = df.iloc[:split_index,:]
[program:celery]
directory = <django_project_directory> example:[/home/ubuntu/prod/api]
command = <virual_environment_directory/bin/celery> <command_to_be_executed> example: [/home/ubuntu/anaconda3/envs/api_env/bin/celery] [-A prodapi worker -l info --without-gossip --without-mingle --without-heartbeat -Ofair --pool=solo]
stdout_logfile=/var/log/supervisor/celery.log
stderr_logfile=/var/log/supervisor/celery.log
user=<username> example: [ubuntu]
@bhuiyanmobasshir94
bhuiyanmobasshir94 / docker-help.md
Created June 4, 2019 03:00 — forked from bradtraversy/docker-help.md
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info

@bhuiyanmobasshir94
bhuiyanmobasshir94 / tf_session.py
Created May 22, 2019 02:51
Example of per process gpu memory limit. This isn't specific to Mask RCNN and is a simple tensorflow config option. Example below will use 20% of your GPU memory per process.
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
tf_config = tf.ConfigProto()
tf_config.gpu_options.per_process_gpu_memory_fraction = 0.2
set_session(tf.Session(config=tf_config))
import requests
import cv2
import numpy as np
url = 'http://172.17.17.118:8080/shot.jpg'
while True:
img_resp = requests.get(url)
img_arr = np.array(bytearray(img_resp.content), dtype=np.uint8)
img = cv2.imdecode(img_arr, -1)