Skip to content

Instantly share code, notes, and snippets.

View selfboot's full-sized avatar
🎯
Focusing

selfboot selfboot

🎯
Focusing
View GitHub Profile
@selfboot
selfboot / mock_client.go
Created August 7, 2023 03:55
A simple go client that simulates an HTTP request
package main
import (
"bytes"
"context"
"github.com/golang/protobuf/proto"
myproto "github.com/selfboot/demo/proto" // This assumes that the generated protobuf code is in this package
"io/ioutil"
"log"
"net/http"
@selfboot
selfboot / mock_server.go
Created August 7, 2023 03:19
A simple gin server reads the requested package content and outputs random content.
package main
import (
"github.com/gin-gonic/gin"
"io/ioutil"
"log"
"math/rand"
"net/http"
"strconv"
"time"
@selfboot
selfboot / redis_bug_reproduct.py
Created July 31, 2023 12:19
Reproduce the redis-py asynchronous request cancel bug
import asyncio
from redis.asyncio import Redis
async def pipe(reader: asyncio.StreamReader, writer: asyncio.StreamWriter, delay: float, name=''):
while data := await reader.read(1000):
# print(name, 'received:', data)
await asyncio.sleep(delay)
writer.write(data)
@selfboot
selfboot / func_time.py
Created June 30, 2023 11:24
The average time elapsed and P99 elapsed time for a function in the analysis process
from __future__ import print_function
import os
from bcc import BPF
from time import sleep
import argparse
import ctypes
# Argument parsing
parser = argparse.ArgumentParser(description="Measure function duration for a specific PID")
parser.add_argument("pid", help="The PID of the process")
@selfboot
selfboot / ebpf-func-time.cpp
Last active June 30, 2023 06:20
In the common product business, the distribution of time consumption of functions is usually uneven, so in order to get closer to the real world, we deliberately designed this function so that its P99 (99th percentile) time consumption is significantly larger than the average time consumed.
#include <iostream>
#include <vector>
#include <chrono>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <thread>
class Timer {
public:
@selfboot
selfboot / func_time_hist.py
Last active June 30, 2023 08:34
bcc monitors process function execution time
from __future__ import print_function
import os
from bcc import BPF
from time import sleep
import numpy as np
import argparse
from collections import defaultdict
# Argument parsing
parser = argparse.ArgumentParser(description="Measure function duration for a specific PID")

ai_tutor

Name: Mr. Ranedeer Author: JushBJJ Version: 2.5

Features

Personalization

Depth

This is the level of depth of the content the student wants to learn. The lowest depth level is 1, and the highest is 10.

@selfboot
selfboot / waiter.h
Created October 11, 2019 10:05 — forked from chenshuo/waiter.h
A handful of implementations of Waiter class for discussion.
#include <boost/noncopyable.hpp>
#include <pthread.h>
#include <stdlib.h>
// a superfluous check for pedantic people
inline void CHECK_SUCCESS(int ret)
{
if (ret != 0)
{
abort();
@selfboot
selfboot / test_backtrace.cpp
Created June 17, 2019 02:48 — forked from owent/test_backtrace.cpp
test_backtrace
/**
* traceback for cpp
*
* Created on: 2018-01-27
* Author: owent
*
* Released under the MIT license
*
* @note Required flag -rdynamic or addr2line to get the function name when using gcc/clang in unix like system
* @note Using addr2line -Cfpe <exe_path> [func_addr...] for more detail when using gcc/clang
@selfboot
selfboot / py_scripts.md
Last active April 29, 2019 07:51
py_scripts.md

You can use os.path.expanduser to convert ~ into your home directory:

>>> import os
>>> os.path.expanduser('~/.config.txt')
'/root/.config.txt'
>>>

This works on both *nix and Windows systems.