Skip to content

Instantly share code, notes, and snippets.

View Shihab-Shahriar's full-sized avatar

Shihab Shahriar Khan Shihab-Shahriar

View GitHub Profile
@Shihab-Shahriar
Shihab-Shahriar / chaining.py
Created January 15, 2021 20:46
Simple chaining pattern demonstration in Python
class Balance:
def __init__(self):
self.bal = 0
def add(self, x):
self.bal += x
return self
def deduct(self, x):
self.bal -= x
@Shihab-Shahriar
Shihab-Shahriar / pyLOC.py
Last active August 16, 2020 16:59
Count total lines of Python code in a file or folder, excluding comments or empty lines.
from io import StringIO
import tokenize, sys, os
import argparse
pref_skips = ('__', '.') # Skip folders that starts with ...
# From https://stackoverflow.com/a/2962727/4553309
def remove_comnts(source):
io_obj = StringIO(source)
@Shihab-Shahriar
Shihab-Shahriar / coarse_vs_fine.py
Last active September 8, 2019 12:12
performance of InstanceHardnessThreshold: Compares coarse parallelism using cross_val_predict with parallelizing estimator
from collections import Counter
from time import perf_counter
import numpy as np
from sklearn.base import ClassifierMixin, clone
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import StratifiedKFold, cross_val_predict
from sklearn.utils import safe_indexing
from imblearn.under_sampling import InstanceHardnessThreshold