Skip to content

Instantly share code, notes, and snippets.

View Sheikh2Imran's full-sized avatar
😃
Senior Software Engineer

Md Imran Sheikh Sheikh2Imran

😃
Senior Software Engineer
View GitHub Profile
import ast
import json
def parse_json_string(text, default={}):
"""
function to parse the json string
into json parse or dict
:param `text` is the value of text model to parse.
:paran `default` is default output, eg: {}, []
@Sheikh2Imran
Sheikh2Imran / gist:a2669865bd3ab19b8ac3b1d4c4d4fc84
Created February 23, 2020 13:07
Fuzzy merge function to merge two dataframe
def fuzzy_merge_df1_and_df2(self, df_1, df_2, key1, key2, threshold=50, limit=2):
"""
df_1 is the left table to join
df_2 is the right table to join
key1 is the key column of the left table
key2 is the key column of the right table
threshold is how close the matches should be to return a match, based on Levenshtein distance
limit is the amount of matches that will get returned, these are sorted high to low
"""
s = df_2[key2].tolist()
Q. What attributes do you look for in a company when applying for a position?
A. Technical stack, learning graph, company's vision and culture.
Q. What are the three to five expectations that you have of senior leaders in an organization where you’ll work successfully?
A. My senior should be helpful, co-operative, friendly and have clear understanding about what we are doing and going to do.
Q. At times your workload may feel unmanageable. Describe a time when you recognized that you were unable to meet multiple deadlines. What did you do about it?
A. I will try to meet at least one deadline according to product priority.
Q. Tell me about a time you worked on a team with individuals from different cultural backgrounds.
@Sheikh2Imran
Sheikh2Imran / javascript_counter.html
Created December 20, 2019 05:09
How to make a counter in JavaScript
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
p {
text-align: center;
font-size: 60px;
margin-top: 0px;
}
@Sheikh2Imran
Sheikh2Imran / settings.py
Last active December 20, 2019 11:31
How to setup template path in Django settings.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
@Sheikh2Imran
Sheikh2Imran / clean_database_scripts.py
Last active December 15, 2019 14:37
Clean all postgres database model By running script
from django.db import connections, OperationalError
# Drop all tables from a given database
"""
python manage.py runscript clean_database_tables
"""
def run():
@Sheikh2Imran
Sheikh2Imran / create_user_and_database.txt
Last active December 15, 2019 14:36
How to setup postgres database in Django
-> sudo su - postgres # To perform administrative tasks
-> password # Enter user password
-> psql # Log into a Postgres session
-> CREATE DATABASE db_name;
-> CREATE USER db_user WITH PASSWORD 'your_password';
-> ALTER ROLE db_user SET client_encoding TO 'utf8';
-> ALTER ROLE db_user SET default_transaction_isolation TO 'read committed';
-> ALTER ROLE db_user SET timezone TO 'UTC';
@Sheikh2Imran
Sheikh2Imran / create_or_get.py
Last active December 15, 2019 14:38
create_or_get ORM in Django
# should not use
try:
Account.objects.get(username='testuser', password='test1234')
except ObjectDoesNotExist:
Account.objects.create(username='testuser', password='test1234')
# should use
try:
Account.objects.get_or_create(username='testuser', password='test1234')
except Exception as e:
@Sheikh2Imran
Sheikh2Imran / decorators.py
Last active December 21, 2021 14:28
Custom method decorator in Django
def authentication_decorator(function):
def wrap(request, *args, **kwargs):
user_token = request.META.get('HTTP_AUTHORIZATION')
user_response, status_code = backend_obj.get_user(user_token)
if status_code == 200:
kwargs = user_response
return function(request, *args, **kwargs)
return wrap
@Sheikh2Imran
Sheikh2Imran / json_to_xml.py
Last active December 15, 2019 14:32
Convert json object to xml object
data = {
"id": "124324",
"name": "testname",
"email": "[email protected]",
"password": "test1234"
}
def get_json_to_xml_data(data):
return f'''
<?xml version="1.0"?>