Skip to content

Instantly share code, notes, and snippets.

def docstring_decorator(s):
"""
动态修改docstring装饰器
>>> a = "test"
>>> @docstring_decorator(f"a={a}")
>>> def f():
>>> pass
>>> print(f.__doc__) # a=test
"""
releases_api=https://api.github.com/repos/indygreg/python-build-standalone/releases/latest
urls=$(curl -s $releases_api | jq '.assets[].browser_download_url' -r | grep -E 'x86_64-unknown-linux-gnu-pgo%2Blto-full.tar.zst$')
echo "Available versions:"
echo "$urls" | awk -F "/" '{print $NF}' | awk -F "-" '{print $2}' | sed 's/%2B.*//g' | sort -V | uniq
echo "Enter the version you want to install: "
read version
url=$(echo "$urls" | grep "cpython-$version" | head -n 1)
version=$(echo "$url" | awk -F "/" '{print $NF}' | awk -F "-" '{print $2}' | sed 's/%2B.*//g')
from db.models import Comment, User
from django.db.models import Prefetch
from django_print_sql import print_sql
import rich
import uuid
class User(models.Model):
name = models.CharField(max_length=100)
echo "PS1='\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[35;40m\]\W\[\e[0m\]]\$'" >> ~/.bashrc
@sunfkny
sunfkny / file_cache.py
Last active March 31, 2024 05:03
origin from https://github.com/sweepai/sweep/blob/main/docs/public/file_cache.py , add typehint and improve code quality
import functools
import hashlib
import inspect
import os
import pathlib
import pickle
import tempfile
from typing import Any, Callable, Concatenate, ParamSpec, TypeVar
from loguru import logger
from typing import Generic, TypeVar, cast
import eth_abi
import web3
from eth_abi.exceptions import DecodingError
from eth_typing import ChecksumAddress, HexStr
from eth_utils.abi import function_signature_to_4byte_selector
from eth_utils.address import to_checksum_address
from hexbytes import HexBytes
from typing_extensions import ParamSpec
export SSH_AUTH_SOCK=$(ls -t /tmp/ssh-**/* | head -1)
# https://github.com/microsoft/vscode/issues/168202
# https://github.com/Bogdanp/dramatiq
# start worker: dramatiq <module.name>
import sys
import dramatiq
import requests
from dramatiq.brokers.redis import RedisBroker
from dramatiq.middleware import CurrentMessage
from dramatiq.results import Results
from dramatiq.results.backends.redis import RedisBackend
from django.db import models
class User(models.Model):
id = models.AutoField(primary_key=True)
parent = models.ForeignKey("self", null=True, blank=True, on_delete=models.CASCADE)
def get_tree_users_recursive(self) -> "models.QuerySet[User]":
return User.objects.extra(
where=[
import inspect
import logging
import os
import argparse
import pathlib
import signal
import subprocess
import sys
import time
import loguru