Skip to content

Instantly share code, notes, and snippets.

View hzhangxyz's full-sized avatar

Hao Zhang hzhangxyz

  • University of Science and Technology of China
  • Hefei, China
  • 15:51 (UTC +08:00)
View GitHub Profile
@hzhangxyz
hzhangxyz / main.py
Last active September 23, 2023 13:26
gpt-3.5-instruct-webui.py
import os
import openai
import asyncio
import gradio as gr
MODEL = "gpt-3.5-turbo-instruct"
if "OPENAI_PROXY" in os.environ:
openai.proxy = os.environ["OPENAI_PROXY"]
openai.api_key = os.environ["OPENAI_API_KEY"]
@hzhangxyz
hzhangxyz / Tools.f90
Created August 30, 2023 13:40
For lfortran issue reproduction
!
! _ooOoo_
! o8888888o
! 88" . "88
! (| -_- |)
! O\ = /O
! ____/`---'\____
! .' \\| |// `.
! / \\||| : |||// \
! / _||||| -:- |||||- \
@hzhangxyz
hzhangxyz / P2M.py
Created August 19, 2023 03:33
Python AST Transformer
import ast
import inspect
import types
class Apply(ast.NodeTransformer):
def __init__(self):
super().__init__()
self._never_function = True
@hzhangxyz
hzhangxyz / nonebot_zhipuai.py
Last active December 23, 2023 06:34
nonebot_zhipuai_bot
from nonebot.adapters import Event, Message
from nonebot.params import EventPlainText, CommandArg
from nonebot.plugin.on import on_message, on_command
from nonebot.adapters.onebot.v11.message import MessageSegment
import os
import ast
import json
import shelve
import aiohttp
@hzhangxyz
hzhangxyz / main.py
Last active April 22, 2023 10:53
Cli chatgpt bot program(The main part of this program is copied from https://github.com/zzh1996/chatgpt-telegram-bot/blob/master/main.py)
import asyncio
import fire
import openai
import os
import prompt_toolkit
import tiktoken
# Authenticate with OpenAI API
assert "OPENAI_API_KEY" in os.environ, "OPENAI_API_KEY environment variable not set."
openai.api_key = os.environ["OPENAI_API_KEY"]
@hzhangxyz
hzhangxyz / mwe.py
Created February 28, 2023 10:39
An example to reproduce a bug(maybe) of mkl
import TAT
Tensor = TAT.No.D.Tensor
L1 = 2
L2 = 4
D = 5
def construct_tensor(l1, l2):
@hzhangxyz
hzhangxyz / index.html
Last active February 22, 2023 01:56
Show all image in a single folder
<div id=container />
<script>
async function getList() {
const resp = await fetch("list.txt", {cache: "no-store"})
const text = await resp.text()
const list = text.split("\n")
return list.filter(name => name.includes(".png"))
}
var container = document.getElementById("container")
var oldList = []
@hzhangxyz
hzhangxyz / main.cpp
Last active September 24, 2019 09:26
use variant like julia union
#include <iostream>
#include <random>
#include <type_traits>
#include <variant>
template <class T> struct replace_void { using type = T; };
template <> struct replace_void<void> { using type = std::monostate; };
template <class T> using replace_void_t = typename replace_void<T>::type;
template <class... Fn> struct overloaded : Fn... {
class metaA(type):
def __new__(cls, n, b, a):
#a["__add__"] = lambda x,y:4
obj = type.__new__(cls, n, b, a)
#obj.__add__ = lambda x,y:4
return obj
def __getattr__(self, name):
if name == "__add__":
return lambda x,y:4
raise AttributeError()
@hzhangxyz
hzhangxyz / currify.c
Created September 21, 2018 13:11
currify
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
typedef int (*SIN)(int);
typedef int (*DOU)(int,int);
int proto(int b){
DOU fun=(DOU)'+';