Skip to content

Instantly share code, notes, and snippets.

View johnny-godoy's full-sized avatar
🐄
moo

Johnny Godoy johnny-godoy

🐄
moo
View GitHub Profile
@johnny-godoy
johnny-godoy / tree_selection.ipynb
Last active March 26, 2023 14:42
Using XGBoost for feature selection in a Linear Model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@johnny-godoy
johnny-godoy / mc_rsg_any_cheats_route.md
Last active March 13, 2023 20:54
Minecraft Random Seed Survival Cheats Enabled Any% Speedrun Route

Preparation:

  1. Go to Minecraft options and bind Open Command to the Ctrl key.
  2. Copy the following to your clipboard: /setblock ~ ~ ~ end_portal.

Route:

  1. Create a new world with cheats enabled. It doesn’t need to be in creative mode, it can be Survival with Hard Difficulty.
  2. Wait for the world to create. When it starts loading the world, you may start holding Ctrl.
  3. When the Overworld loads, press v and Enter in quick succession, and then release Ctrl.
  4. Start holding Ctrl right after as you wait for The End to load. When The End loads, press v and Enter in quick succession.
@johnny-godoy
johnny-godoy / classify_regressor.py
Last active January 8, 2023 16:08
A zero inflated regressor.
import attrs
import numpy as np
import pandas as pd
from scipy.stats import norm
from sklearn.base import is_classifier, is_regressor, BaseEstimator, RegressorMixin
@attrs.define
class ClassifyRegressor(BaseEstimator, RegressorMixin):
"""A meta regressor for zero-inflated datasets, i.e. the targets contain a lot of zeroes.
@johnny-godoy
johnny-godoy / compress_dataframe.py
Last active April 1, 2023 18:30
Pandas DataFrame Compression
"""Implement the compress_dataframe function."""
from __future__ import annotations
from typing import TYPE_CHECKING
import numpy as np
if TYPE_CHECKING:
import pandas as pd
from pandas.core.indexes.base import Index
@johnny-godoy
johnny-godoy / tabulate_query.py
Last active October 2, 2022 19:08
Function for getting pretty-printable tables out of sqlalchemy queries
from __future__ import annotations
import tabulate
def tabulate_query(query: Query, **kwargs):
return tabulate.tabulate(query,
headers=(column.get('name') for column in query.column_descriptions),
**kwargs)
@johnny-godoy
johnny-godoy / log_system_info.py
Last active June 25, 2022 03:11
Logging the system information as a table
import logging
import platform
import tabulate
import sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger("SYSTEM_INFORMATION").info(
f"\n{tabulate.tabulate(platform.uname()._asdict().items())}")
@johnny-godoy
johnny-godoy / matplotlib_configs.py
Last active June 25, 2022 03:10
Configurations for matplotlib
import matplotlib.pyplot as plt
plt.style.use('ggplot')
plt.rc('axes', titlesize=14)
plt.rc('legend', fontsize=14)
plt.rc('xtick', labelsize=12)
plt.rc('ytick', labelsize=12)
plt.rcParams.update({'font.size': 16})
plt.rcParams['axes.titlesize'] = 16
@johnny-godoy
johnny-godoy / add_timing_argument.py
Last active April 2, 2023 22:40
A Python decorator for easily getting the execution time of a function (in nanoseconds).
"""Implement the function add_timing_argument."""
from time import perf_counter_ns # For timing the execution of the function
import functools # For the wraps decorator
import inspect # Inspection of function arguments
try:
from os import sched_yield
except ImportError:
@johnny-godoy
johnny-godoy / subplots.py
Last active June 27, 2022 17:04
A matplotlib subplots function that scales each axis to the current figsize
from __future__ import annotations
import matplotlib.pyplot as plt
import numpy as np
def subplots(nrows: int, ncols: int, **kwargs) -> tuple[matplotlib.figure.Figure, matplotlib.axes.Axes|np.ndarray[matplotlib.axes.Axes]]:
"""Returns the value of plt.subplots, but each axis has the figsize size."""
return plt.subplots(nrows=nrows, ncols=ncols, constrained_layout=True, **kwargs,
figsize=np.array((ncols, nrows))*plt.rcParams["figure.figsize"])