Skip to content

Instantly share code, notes, and snippets.

@minghao51
minghao51 / class_2_dict.py
Created October 17, 2024 06:11
convert class to dict
class Config:
# MODE
PROD = True
IS_SANDBOX_ENV = True
TRAINING = False # Prepare data for training/inference if True/False. No Training or Inference executed. Use DO_TRAIN or DO_SERVE.
DO_TRAIN = False # Run model training if True
DO_SERVE = True # Run model predict if True
GENERATE_DATA = True # generate, features, targets if True
PRINT_CHECKS = True
@minghao51
minghao51 / format cells for excell
Created October 17, 2024 03:22
excel cell format to human readable format
[<999950]0.0,"K";[<999950000]0.0,,"M";0.0,,,"B"
# Convert
# 7000 -> 7K
# 2000000 -> 2M
@minghao51
minghao51 / dataframe_downcast.py
Created October 17, 2024 02:33
downcast/downcast.py at master · deepak7376/downcast · GitHub
import pandas as pd
import numpy as np
def reduce(df):
cols = df.dtypes.index.tolist()
types = df.dtypes.values.tolist()
for i,t in enumerate(types):
if 'int' in str(t):
if df[cols[i]].min() > np.iinfo(np.int8).min and df[cols[i]].max() < np.iinfo(np.int8).max:
df[cols[i]] = df[cols[i]].astype(np.int8)
@minghao51
minghao51 / python_number_formatter.py
Last active October 17, 2024 02:35
This script defines a function human_format that converts a large number into a readable format with suffixes like K (thousand), M (million), etc. It takes three parameters: num (the number), precision (decimal places), and suffixes (list of suffixes). The function calculates the appropriate suffix and formats the number accordingly. Example: hu…
# python number formatter into string with unit
def human_format(num, precision=2, suffixes=['', 'K', 'M', 'G', 'T', 'P']):
m = sum([abs(num/1000.0**x) >= 1 for x in range(1, len(suffixes))])
return f'{num/1000.0**m:.{precision}f}{suffixes[m]}'
print('the answer is %s' % human_format(7454538))
# prints 'the answer is 7.45M'
@minghao51
minghao51 / onenote_export.py
Last active January 9, 2020 08:44 — forked from danmou/onenote_export.py
Onenote export to HTML
### README
# This Python scripts exports all the OneNote notebooks linked to your Microsoft account to HTML files.
## Output
# The notebooks will each become a subdirectory of the `output` folder, with further subdirectories
# for the sections within each notebook and the pages within each section. Each page is a directory
# containing the HTML file `main.html` and two directories `images` and `attachments` (if necessary)
# for the images and attachments. Any sub-pages will be subdirectories within this one.
## Setup
@minghao51
minghao51 / ScriptLab Search Wiki.POWERPOINT.yaml
Last active November 9, 2019 06:08
Search Wikipedia based on the selected text.
name: ScriptLab Search Wiki
description: Search Wikipedia based on the selected text.
host: POWERPOINT
api_set: {}
script:
content: |
$("#insert").click(run);
Office.onReady((info) => {
console.log(info.host);