Skip to content

Instantly share code, notes, and snippets.

View benbenbang's full-sized avatar
👻
Ghostttttty

Ben Chen benbenbang

👻
Ghostttttty
View GitHub Profile
@benbenbang
benbenbang / gpg_cheatsheet.md
Last active May 28, 2022 15:25
GPG Cheatsheet

Quick'n easy gpg cheatsheet

  • To create a key: gpg --full-generate-key generally you can select the defaults by gpg --gen-key, or you prefer a rsa4096 encrypted key like gpg --default-new-key-algo rsa4096 --gen-key

    NOTE: You "must" to associate your author/commiter email with your GPG key, if you didn't get prompted to enter the email, username, etc. You will need to

    • gpg --edit-key KeyID
    • you will see gpg>, type adduid and follow the instructions
    • type save
  • To export a public key into file public.key:

@benbenbang
benbenbang / apple_m1_python_deps.sh
Created May 14, 2022 09:55
Apple M1 python dependencies
# tensorflow full guide:
# https://developer.apple.com/metal/tensorflow-plugin/
# grpcio & h5py issue
export CFLAGS="-I/opt/homebrew/opt/openssl/include"
export LDFLAGS="-L/opt/homebrew/opt/openssl/lib"
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1
brew install hdf5
@benbenbang
benbenbang / git-rewrite-commiter-email.sh
Last active August 26, 2021 12:29
Simple bash function to overwrite git commit username and email
# Simple bash function to rewrite the wrong commiter & email
# > git-rewrite-commiter-email old@email.com new_username new@email.com
git-rewrite-commiter-email(){
OLD_EMAIL="$1"
NEW_USERNAME="$2"
NEW_EMAIL="$3"
if [[ -z $OLD_EMAIL || -z $NEW_USERNAME || -z NEW_EMAIL ]]; then
echo "Positional args needed: \`OLD_EMAIL NEW_USERNAME NEW_EMAIL\`"
else
@benbenbang
benbenbang / patch_pip.sh
Last active February 6, 2020 10:33
For patching conda pip flag with virtual env
# When creating virtulaenv with conda, if you're using PIP_REQUIRE_VIRTUALENV=true
# You might end up with you cannot install by pip even you already activated the virtualenv
# This patch is another approach to let your conda venv work with the PIP_REQUIRE_VIRTUALENV flag
# By patching your pip library with this file, and add another flag CONDA_ENVS in your bashrc
# For instance, export CONDA_ENVS="/Users/$USER/conda/envs"
# Then, the pip flag should not prevent you installing anything in your conda venv anymore.
python_path=$(which python)
python_version=$(echo "$(python -V 2>&1)" | grep -E -o '[0-9]{1,}\.[0-9]{1,}(\.[0-9]{1,})?' | grep -E -o '[0-9]{1,}.[0-9]{1,}')
pip_version=$(conda list | grep pip | grep -E -o '[0-9]{2,}\.[0-9]{1,}(\.[0-9]{1,})?' | grep -E -o '[0-9]{2,}.[0-9]{1,}')
@benbenbang
benbenbang / py_namespace_pandas_question.py
Created December 12, 2019 08:26
Pandas and Python Namespace Question on Py Tw Facebook Group
import pandas as pd
data = {"name": ["A", "A", "B", "B", "B", "C", "C"], "expense": [2, 3.4, 5, 3, 2, 1, 7]}
for name, data in df.groupby("name"):
# replace f-string if you're not using python 3.6 up
locals()[f"df_{name}"] = data
"""
df_A
@benbenbang
benbenbang / sympy_get_coeff.py
Last active December 7, 2019 19:54
PTT Sympy Get Coeff Question
# Example
from sympy import *
x, y = symbols('x y')
f = x + 2*y + 1
g = Rational(3,2)*pi + exp(I*x) / (x**2 + y)
# coeff(x, n): As you can see, it is for finding the coefficient of "variables" in mathematical expressions.
# So if you want to get the constant, `coeff` is not the method you're looking for
lgbm_params = {
"bagging_freq": 5,
"bagging_fraction": 0.6,
"bagging_seed": 123,
"boost_from_average": "false",
"boost": "gbdt",
"feature_fraction": 0.3,
"learning_rate": 0.005,
"max_depth": 3,
"metric": "rmse",
xgb_params = {
"max_depth": 4,
"eta": 0.01,
"objective": "reg:squarederror",
"eval_metric": ["rmse"],
"booster": "gbtree",
"verbosity": 0,
"sample_type": "weighted",
"max_delta_step": 4,
"subsample": 0.5,
ngb = NGBRegressor(
Base=default_tree_learner,
Dist=Normal,
Score=MLE,
learning_rate=lr, # [0.009, 0.007]
natural_gradient=True,
minibatch_frac=0.2,
n_estimators=est, # [1000, 5000]
verbose=False,
)
#####################################################
# Origine: Nanashi's solution # https://www.kaggle.com/jesucristo/1-house-prices-solution-top-1
# Rewrite and refine some processes
#######################################################
def make_data(test_size):
dataframe = pd.read_csv(os.path.join("data", "train.csv"))
...