Skip to content

Instantly share code, notes, and snippets.

View duyixian1234's full-sized avatar
🎯
Focusing

Yixian Du duyixian1234

🎯
Focusing
View GitHub Profile
@duyixian1234
duyixian1234 / chat.py
Last active December 1, 2023 07:22
openai
import openai
from openai.types.chat import ChatCompletionMessageParam
class Chat:
def __init__(self, system=None):
self.messages: list[ChatCompletionMessageParam] = [
@duyixian1234
duyixian1234 / fractal.py
Created May 26, 2023 08:16
fractal patterns
import pygame
import math
# 初始化Pygame
pygame.init()
# 设置窗口大小
size = (700, 700)
screen = pygame.display.set_mode(size)
# 定义一个玩家类
class Player:
def __init__(self, name, elo):
self.name = name
self.elo = elo
# 定义一个函数来更新玩家的 ELO 分数
def update_elo(players, rankings):
# 计算期望胜率
def expected_score(player, opponent):
@duyixian1234
duyixian1234 / fetch_movies.py
Last active March 14, 2023 15:03
fetch_movies.py
import asyncio
import contextlib
import json
import logging
from pathlib import Path
from typing import Literal
import httpx
from playwright.async_api import (
BrowserContext,
@duyixian1234
duyixian1234 / rle.py
Created July 4, 2022 02:37
Compression Algorithms
from itertools import takewhile
from typing import TypeVar
T = TypeVar("T", str, bytes)
def parse_raw(raw: T) -> tuple[tuple[T, int], T]:
first, rest = raw[0], raw[1:]
index = 0
while index < len(rest) and rest[index] == first:
@duyixian1234
duyixian1234 / pyprj.py
Created May 6, 2021 22:46
Parse "Pyproject.toml" to Pydantic Models
from typing import Dict, List, Optional, Union
import toml
from pydantic import BaseModel, Extra, Field
class Version(BaseModel):
extras: List[str]
version: str
@duyixian1234
duyixian1234 / index.md
Last active March 22, 2021 14:24
Talks: Functional Programming VS Procedural Programming
marp true

Functional Programming with TypeScript

Du Yixian


@duyixian1234
duyixian1234 / bing-today.py
Created November 16, 2020 13:59
palywright
import asyncio
from datetime import datetime
from playwright import async_playwright
from playwright.async_api import BrowserContext, Response
from playwright.page import Page
coroutines = []
@duyixian1234
duyixian1234 / base_model.py
Created November 12, 2020 13:43
py-avro-grpc
import json
from dataclasses import asdict, dataclass
from io import BytesIO
from typing import TypedDict
from avro import schema
from avro.io import BinaryDecoder, BinaryEncoder, DatumReader, DatumWriter
class Field(TypedDict):
@duyixian1234
duyixian1234 / compose.py
Last active November 7, 2020 14:33
Python Functional Programming
def compose(*funcs):
def inner(arg):
return functools.reduce(lambda pre, func:func(pre), funcs, arg)
return inner