Skip to content

Instantly share code, notes, and snippets.

View SHi-ON's full-sized avatar
🎯
focused

Shawyan SHi-ON

🎯
focused
View GitHub Profile
@SHi-ON
SHi-ON / stratify_experiment.py
Created March 10, 2019 17:08
An expirement to show how stratify option works
# Experiment to confirm the effect of stratify option in Scikit Learn, tran_test_split() method.
# by Shayan Amani
from sklearn.model_selection import train_test_split
import pandas as pd
raw_data = pd.read_csv("codebase/adrel/dataset/train.csv")
cnt = raw_data.groupby('label').count()
''' experiment begins '''
@SHi-ON
SHi-ON / us_state_abbreviations.py
Last active November 12, 2019 01:17 — forked from JeffPaine/us_state_abbreviations.py
A python list of all US states abbreviations. Alphabetically sorted!
# alphabetically sorted
# 50 states + D.C = 51
STATES = ["AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL",
"GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA",
"MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE",
"NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI",
"SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV",
"WY"]
@SHi-ON
SHi-ON / regex_numbers_formatted.md
Last active July 21, 2021 15:52
specific-length formatted numbers

(?<!\d)([0-9]{5}-[0-9]{4}-[0-9]{2})(?!\d)

Explained:

  • ?> lookbehind
  • ?<! negative lookbehind
  • \d digit only
  • ? lookahead
  • ?! negative lookahead
  • [0-9]{5}-[0-9]{4}-[0-9]{2} a specific pattern #####-####-##
@SHi-ON
SHi-ON / decode_base64.py
Created March 15, 2022 17:01
Decode HTML files with inline Base64 images and store the image files separately.
import base64
import mimetypes
import os
from bs4 import BeautifulSoup
with open('example.html', 'rb') as file_handle: # Read in as a binary file
soup = BeautifulSoup(file_handle)
@SHi-ON
SHi-ON / logger.py
Last active June 27, 2023 11:43
Python Logger class to Capture the feed coming from system stderr and stdout and write it to a file on disk and back to their respective buffer as well. Designed as a context manager, you can add the logging functionality and redirection to any Python script by just adding a line of code.
import logging
import pathlib
import sys
from ml.common.const import LOG_DIR_PATH, ML_DIR
def create_log_file_path(file_path, root_dir=ML_DIR, log_dir=LOG_DIR_PATH):
path_parts = list(pathlib.Path(file_path).parts)
relative_path_parts = path_parts[path_parts.index(root_dir) + 1:]
@SHi-ON
SHi-ON / my_telegram_chats.py
Last active June 12, 2022 17:32
List Telegram chats (including Super Groups and Channels) of your own.
from pyrogram import Client
with Client(CLIENT_NAME, API_ID, API_HASH) as client:
chats = []
for d in client.get_dialogs():
if d.chat.is_creator or \
(d.chat.permissions and d.chat.permissions.can_change_info):
chats.append(d.chat.title)
print(*chats, sep='\n')
print('\t Chat count:', len(chats))
@SHi-ON
SHi-ON / pdf_color_replacement.py
Last active September 17, 2023 16:24
Replace colors in a given PDF file. The original goal was to print a PDF paper using a printer with no black cartridge!
import concurrent.futures
import itertools
import math
import pdf2image # $ brew install poppler
from tqdm import tqdm
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)