Skip to content

Instantly share code, notes, and snippets.

View zhu327's full-sized avatar
🥰
Out sick

Timmy zhu327

🥰
Out sick
View GitHub Profile
@zhu327
zhu327 / groq.ts
Created April 15, 2024 08:02
groq api proxy with deno deploy
import { serve } from "https://deno.land/std@0.181.0/http/server.ts";
async function handleRequest(request: Request): Promise<Response> {
if (request.method === "OPTIONS") {
return handleOPTIONS(request);
}
const url = new URL(request.url);
url.host = "api.groq.com";
url.pathname = "/openai" + url.pathname;
@zhu327
zhu327 / wrk_log.lua
Created August 14, 2018 02:15
logging response from wrk
wrk.path = "/rest/ping"
wrk.method = "POST"
wrk.body = "id=7579764573763278289&platformid=ANDROID&version=1.0.0"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
wrk.headers["deviceid"] = "354435052821931"
wrk.headers["Accept"] = "application/json"
logfile = io.open("wrk.log", "w");
local cnt = 0;
@zhu327
zhu327 / player.py
Last active January 19, 2022 06:05
XBMC 迅雷云播: 直接通过下载地址推送迅雷云播地址到XBMC上
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib, urllib2, json
RPC_URL = 'http://192.168.1.2/jsonrpc'
def pushStream(stream, rpc=RPC_URL):
'''
Push stream URL to XBMC jsonrpc api, XBMC play the streaming.
@zhu327
zhu327 / exporter.py
Created April 3, 2020 12:19
Prometheus Exporter
from gevent.wsgi import WSGIServer
from prometheus_client import multiprocess
from prometheus_client import generate_latest, CollectorRegistry, CONTENT_TYPE_LATEST
# Expose metrics.
def app(environ, start_response):
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
status = '200 OK'
@zhu327
zhu327 / thread_pool.py
Last active September 17, 2019 06:38
简单线程池
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
一个基于thread和queue的线程池,以任务为队列元素,动态创建线程,重复利用线程,
通过close和terminate方法关闭线程池。
"""
import queue
import threading
import contextlib
func (s *server) respond(w http.ResponseWriter, r *http.Request, data interface{}, status int) {
w.WriteHeader(status)
if data != nil {
err := json.NewEncoder(w).Encode(data)
s.logf("json encode %s", err)
}
}
func (s *server) decode(w http.ResponseWriter, r *http.Request, v interface{}) error {
return json.NewDecoder(r.Body).Decode(v)
@zhu327
zhu327 / utils.go
Last active December 27, 2018 02:53
string byte 转换, 不需要申请内存, 对于不可变的byte, 以及临时变量转换有用, 需要变的byte一定不要用
package utils
import (
"reflect"
"unsafe"
)
func BytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
@zhu327
zhu327 / curl.sh
Created December 24, 2018 06:36
检查服务请求在各个阶段的消耗
curl -w %{time_connect}:%{time_starttransfer}:%{time_total} -X POST 'http://service-uri' -H 'Content-Type: application/json' --data 'post-data'
@zhu327
zhu327 / ws.py
Created August 6, 2018 08:08
tornado websocket client example
# coding: utf-8
from tornado import gen
from tornado import httpclient
from tornado import httputil
from tornado import ioloop
from tornado import websocket
import json
@zhu327
zhu327 / tracer.py
Created July 27, 2018 03:10
Python调用栈跟踪
# coding: utf-8
from __future__ import print_function
import re
import sys
filter = re.compile(r'site-packages/requests/.*')
def tracer(frame, event, args):