Skip to content

Instantly share code, notes, and snippets.

View JotaRata's full-sized avatar
💥

JotaRata

💥
  • 04:30 (UTC -03:00)
View GitHub Profile
@JotaRata
JotaRata / bootstrap.py
Last active October 7, 2024 02:52
Bootstrap sampling methods
import math
import random
from typing import Any, Callable, Concatenate, List, ParamSpec, ParamSpecKwargs, Tuple, cast
import numpy as np
from numpy.typing import NDArray,ArrayLike
from pandas import DataFrame, Series
# ---------------- Bootstrapping -------------------------------
_ArrayLike = NDArray[np.floating] | None
_NumFunction = Callable[..., float]
@JotaRata
JotaRata / ztfutils.py
Last active June 27, 2024 01:12
ZTF Forced Photometry service utilities
import math
import re
from typing import Literal
import numpy as np
import pandas as pd
import requests
import multiprocessing
from multiprocessing.pool import ThreadPool
import os
@JotaRata
JotaRata / list.py
Last active August 6, 2023 05:19
Python Generic List
'''
C# like generic lists for python!
Description
A cool trick that uses a singleton variable called "List" which is an instance of a "hidden" class _GenericList
this class defines a __getitem__ method that returns a type object that internally stores the type given by the getter
because it is a type object you can instanstiate in python using curly braces, hence behaving exactly like a normal class
The class _GenericList also returns a regular list instance if no type were provided, this is done by defining the __call__ method
Usage:
@JotaRata
JotaRata / stubs.py
Last active August 1, 2023 01:05
Auto stub generator for Cython files
'''
Auto stub generator for cython files.
LIMITATIONS:
Can only parse declared cdef variables with public/readonly keywords
Cannot parse plain defined variables (ex: "my_var = 2")
Cannot parse special members imported from C/C++
Cannot parse ctypedef types
Can only parse functions prefixed with 'def' and 'cpdef
@JotaRata
JotaRata / get_axis.py
Last active July 5, 2023 20:52
Matplotlib subplots shortcut
class get_axis():
"""
Context manager to generate subplots quickly
Parameters:
- rows, cols (int): Rows and columns to draw.
- xlabel, ylabel (str / list): Labels for the horizontal and vertical axis, If xlabel/ylabel are lists then each corresponding subplot will have its own labels.
- title (str / list): Title of the plot, If title is a list then each subplot will have its own title.
- figzise (tuple): Size of the figure in inches (same as figure.figsize).
- figargs (dict): Additionl arguments passed to plt.subplots
@JotaRata
JotaRata / TextEditor.cs
Last active April 26, 2024 21:14
A really really simple text editor for Unity
/*
This is a really simple text editor to be used within Unity
It's useful to write memos, notes or ideas inside your Unity Editor window
Kinda like Blender's Text Editor
*/
using UnityEngine;
using UnityEditor;
using System;
using System.IO;