Skip to content

Instantly share code, notes, and snippets.

View altescy's full-sized avatar
👋

Yasuhiro Yamaguchi altescy

👋
View GitHub Profile
@altescy
altescy / progress.py
Last active May 29, 2023 04:00
Show iteration progress with estimated running time.
from __future__ import annotations
import functools
import os
import re
import sys
import time
from collections.abc import Sized
from typing import Any, Callable, ClassVar, Generic, Iterable, Iterator, TextIO, TypeVar, cast
from typing import Optional, cast
import torch
class MAB(torch.nn.Module):
def __init__(
self,
input_dim: int,
num_heads: int,
@altescy
altescy / selector.py
Created August 11, 2022 09:43
Example of interactive selector in Python
from __future__ import annotations
import os
import shutil
import subprocess
class Selector:
SUPPORTED_SELECTOR_COMMANDS = {"fzf", "peco"}
ENVKEY_SELECTOR_COMMAND = "SELECTOR_COMMAND"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from typing import TypeVar
import numpy
from sklearn.base import BaseEstimator, ClusterMixin
from sklearn.cluster import KMeans
Self = TypeVar("Self", bound="HierarchicalKmeans")
class HierarchicalKmeans(BaseEstimator, ClusterMixin):
import dataclasses
import datetime
import re
import socket
import socketserver
import time
class config:
SOCKET_TIMEOUT = 10
@altescy
altescy / multiprocess_queue_iterator.py
Created January 8, 2023 08:15
Iterator wrapper generating values with multi-processing queue
import time
from collections.abc import Iterable, Iterator
from multiprocessing import Process, Queue
from types import TracebackType
from typing import Generic, Type, TypeVar
T = TypeVar("T")
class NumberIterator:
@altescy
altescy / spinner.py
Last active January 10, 2023 18:33
Simple spinner decorator for Python
import functools
import itertools
import sys
import threading
import time
from collections.abc import Callable, Iterable
from concurrent.futures import ThreadPoolExecutor
from typing import Any, TextIO, TypeVar
T = TypeVar("T")
import abc
import functools
from os import PathLike
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Union
import fugashi
import minato
class Token(NamedTuple):
from typing import Generic, Hashable, Iterable, Mapping, Optional, Sequence, TypeVar
import numpy
from sklearn.base import TransformerMixin
T_Token = TypeVar("T_Token", bound=Hashable)
Self = TypeVar("Self", bound="SwemVectorizer")
class SwemVectorizer(Generic[T_Token], TransformerMixin): # type: ignore[misc]