Skip to content

Instantly share code, notes, and snippets.

View abersheeran's full-sized avatar
👋
玉楼金阙慵归去,且插梅花醉洛阳

Aber abersheeran

👋
玉楼金阙慵归去,且插梅花醉洛阳
View GitHub Profile
@abersheeran
abersheeran / pypi-mirror.worker.js
Last active January 4, 2024 03:16
A pypi mirror cloudflare worker
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
async function handleRequest(request) {
const { host, pathname } = new URL(request.url)
@abersheeran
abersheeran / proxy.worker.js
Last active April 13, 2024 08:45
A proxy download cloudflare worker
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
async function handleRequest(request) {
const url = getUrl(request)
@abersheeran
abersheeran / runmodule.py
Last active April 12, 2024 08:59
Run Cython module
#!/usr/bin/python3.10
# -*- coding: utf-8 -*-
import asyncio
import sys
import importlib
from functools import reduce
from typing import Any
def import_from_string(import_str: str) -> Any:
@abersheeran
abersheeran / is_windows_path.py
Last active May 31, 2022 07:44
Determines whether a string is a Windows path.
import re
is_windows_path = lambda path: bool(re.compile(r"^[a-zA-Z]:").match(path))
[Unit]
Description=Visual Studio Code Server
After=network.target
[Service]
Type=exec
Restart=always
User=%i
ExecStart=dbus-run-session -- sh -c "(echo 'somecredstorepass' | gnome-keyring-daemon --unlock) && /usr/local/bin/code-server serve-local --accept-server-license-terms --connection-token=somecredstorepass"
@abersheeran
abersheeran / youtube.yaml
Created August 25, 2022 07:09
给 Clash Pro 用的 youtube 列表
payload:
- '+.youtube.be'
- '+.youtube.ch'
- '+.youtube.co'
- '+.youtube.co.id'
- '+.youtube.com'
- '+.youtube.com.bd'
- '+.youtube.com.co'
- '+.youtube.com.do'
- '+.youtube.com.ee'
from __future__ import annotations
import html
import inspect
import os
import traceback
from baize.typing import ASGIApp, Message, Receive, Scope, Send
from baize.asgi import Request, Response, HTMLResponse, PlainTextResponse
@abersheeran
abersheeran / llama2-2-7b-chat-int8-worker.js
Last active December 5, 2023 06:02
llama2-2-7b-chat-int8 in Cloudflare workers
import { Ai } from './vendor/@cloudflare/ai.js';
export default {
async fetch(request, env) {
const ai = new Ai(env.AI);
// prompt - simple completion style input
// let simple = {
// prompt: 'Tell me a joke about Cloudflare'
// };
@abersheeran
abersheeran / multiworker.py
Last active May 11, 2024 06:36
Python:在多个进程中分别使用线程池处理任务
from concurrent.futures import ThreadPoolExecutor
import gc
import multiprocessing
import queue
import signal
import threading
import time
from typing import Callable, ParamSpec
from loguru import logger
@abersheeran
abersheeran / writecache.py
Created October 31, 2023 05:57
Write after timing or accumulation.
import abc
import threading
from typing import Any
class WriteCache(metaclass=abc.ABCMeta):
def __init__(self, max_size: int = 100, min_time: float = 1) -> None:
self.max_size = max_size
self.min_time = min_time