Skip to content

Instantly share code, notes, and snippets.

View dexhunter's full-sized avatar
🏠
Working from home

Dixing (Dex) Xu dexhunter

🏠
Working from home
View GitHub Profile
import os
from openai import OpenAI, APIError, APITimeoutError
import copy
import json
# Ensure the OPENAI_API_KEY environment variable is set
api_key = os.environ.get("OPENAI_API_KEY")
if not api_key:
print("Error: OPENAI_API_KEY environment variable not set.")
exit(1)
@dexhunter
dexhunter / simple-server.py
Last active March 19, 2025 04:22
Full example for fastapi integration with mcp
"""
Simple example of using MCP to add an MCP server to a FastAPI app.
"""
import inspect
import json
import re
from typing import List, Optional
import click
@dexhunter
dexhunter / rng.js
Last active March 12, 2025 12:25
idleon hack
Math.originalRandom = Math.random;
Math.lowRandom = function() {
return Math.originalRandom() / 100000000000;}
Math.highRandom = function() {
return 1 - Math.lowRandom();}
let breakCycle = false;function luckyCycle() {
return setTimeout(function() {
if (breakCycle) return;
@dexhunter
dexhunter / bulk-remove-youtube-subscription.js
Last active December 1, 2024 10:54
do it at chrome console
/**
* YouTube bulk unsubscribe fn.
* Wrapping this in an IIFE for browser compatibility.
*/
(async function iife() {
// This is the time delay after which the "unsubscribe" button is "clicked"; Change it as per your need!
var UNSUBSCRIBE_DELAY_TIME = 2000
/**
@dexhunter
dexhunter / 10g-nccl-fast.json
Last active July 1, 2021 07:42
horovod timeline json
[
{"name": "process_name", "ph": "M", "pid": 0, "args": {"start_time_since_epoch_in_micros":1624937181806323}},
{"name": "process_sort_index", "ph": "M", "pid": 0, "args": {"sort_index": 0}},
{"name": "process_name", "ph": "M", "pid": 1, "args": {"name": "allreduce.noname.1"}},
{"name": "process_sort_index", "ph": "M", "pid": 1, "args": {"sort_index": 1}},
{"ph": "B", "name": "NEGOTIATE_ALLREDUCE", "ts": 3399382, "pid": 1},{"ph": "X", "name": "8", "ts": 3399384, "pid": 1, "dur": 0},{"ph": "X", "name": "9", "ts": 3399390, "pid": 1, "dur": 0},{"ph": "X", "name": "10", "ts": 3399392, "pid": 1, "dur": 0},{"ph": "X", "name": "11", "ts": 3399393, "pid": 1, "dur": 0},{"ph": "X", "name": "5", "ts": 7133998, "pid": 1, "dur": 0},{"ph": "X", "name": "4", "ts": 7207126, "pid": 1, "dur": 0},{"ph": "X", "name": "15", "ts": 7239969, "pid": 1, "dur": 0},{"ph": "X", "name": "7", "ts": 7248450, "pid": 1, "dur": 0},{"ph": "X", "name": "6", "ts": 7255862, "pid": 1, "dur": 0},{"ph": "X", "name": "13", "ts": 7283415, "pid": 1, "du
@dexhunter
dexhunter / 2dmesh.cc
Last active June 14, 2021 15:17
2d mesh algorithm in horovod (based on NCCLHierarchicalAllreduce)
#if HAVE_MPI
Status
NCCL2DMesh::Execute(std::vector<TensorTableEntry>& entries,
const Response& response) {
auto& first_entry = entries[0];
// Determine GPU IDs of the devices participating in this communicator.
std::vector<int32_t> nccl_device_map;
nccl_device_map.reserve(
global_state_->controller->GetLocalCommRanks().size());
public interface FitnessCustomer {
private static enum Level {
BRONZE, SILVER, GOLD
}
private Level level;
public void setLevel(Level level) {
this.level = level;
}
public Level getLevel() {
return this.level;
@dexhunter
dexhunter / daemon.json
Created February 24, 2020 08:37
public /etc/docker/daemon.json
{
"registry-mirrors" : [
"http://registry.docker-cn.com",
"http://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com",
"http://ovfftd6p.mirror.aliyuncs.com"
],
"insecure-registries" : [
"registry.docker-cn.com",
"docker.mirrors.ustc.edu.cn"
@dexhunter
dexhunter / hosts-github-cn
Created February 9, 2020 22:20
Github hosts for China
192.30.253.112 github.com
192.30.253.113 github.com
192.30.253.119 gist.github.com
151.101.185.194 github.global.ssl.fastly.net
151.101.100.133 assets-cdn.github.com
151.101.100.133 raw.githubusercontent.com
@dexhunter
dexhunter / docker-compose-simple.yaml
Created February 9, 2020 13:01
config with counchdb
version: '2'
services:
orderer:
container_name: orderer
image: hyperledger/fabric-orderer
environment:
- FABRIC_LOGGING_SPEC=debug
- ORDERER_GENERAL_LISTENADDRESS=orderer
- ORDERER_GENERAL_BOOTSTRAPMETHOD=file