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 / gen.py
Last active July 31, 2024 07:42
gen24
from dataclasses import dataclass
from operator import add, sub, mul, truediv
from tabnanny import check
from typing import Self, Literal
import random
type OP = Literal["+", "-", "*", "/"]
OPERATIONS = {"+": add, "-": sub, "*": mul, "/": truediv}
@duyixian1234
duyixian1234 / agent.py
Last active July 11, 2025 07:53
Ai Agent
import json
from collections.abc import Callable
import sys
from typing import Annotated
from function_schema import get_function_schema
from openai import OpenAI
from openai.types.chat import ChatCompletionMessageParam
@duyixian1234
duyixian1234 / lock.ts
Created January 24, 2024 07:56
etcd lock
import { Etcd3 } from "etcd3";
const client = new Etcd3();
async function withLock(
key: string,
action: () => Promise<void>,
client: Etcd3
): Promise<void> {
const lockKey = `locks/${key}`;
const lock = client.lock(lockKey);
@duyixian1234
duyixian1234 / index.html
Last active January 14, 2024 02:11
gps
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>GPS Stat</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
@duyixian1234
duyixian1234 / index.html
Last active December 31, 2023 13:20
firework
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>firework</title>
<script src="script.js"></script>
</head>
@duyixian1234
duyixian1234 / index.html
Last active December 29, 2023 09:13
comments
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Comment Component</title>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css"
rel="stylesheet"
/>
@duyixian1234
duyixian1234 / index.html
Last active December 20, 2023 09:04
Double Pendulum Animation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Double Pendulum Animation</title>
</head>
<body>
<canvas id="canvas" width="800" height="600"></canvas>
<script src="script.js"></script>
@duyixian1234
duyixian1234 / main.py
Created December 15, 2023 08:37
fastapi simple api
from datetime import UTC, datetime
from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import JSONResponse
from pydantic import BaseModel
class Response[T](BaseModel):
code: int
success: bool
from collections import defaultdict
from typing import Self
class TrieNode(defaultdict):
def __init__(self):
super().__init__(TrieNode)
self.end = False
def insert(self, word: str) -> None:
@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] = [