Skip to content

Instantly share code, notes, and snippets.

View selfboot's full-sized avatar
🎯
Focusing

selfboot selfboot

🎯
Focusing
View GitHub Profile
@selfboot
selfboot / demo.yaml
Created December 25, 2023 12:57
clash yaml
mixed-port: 7890
allow-lan: true
bind-address: '*'
mode: rule
log-level: info
external-controller: '127.0.0.1:9090'
dns:
enable: true
listen: 0.0.0.0:53
ipv6: true
@selfboot
selfboot / lawer_train.py
Last active January 22, 2024 09:27
Train a classification task, see Full Introduction https://selfboot.cn/2023/12/06/bert_nlp_classify/
#!pip install torch
#!pip install transformers
#!pip install scikit-learn
#!pip install numpy
import json
from sklearn.model_selection import train_test_split
import random
from datetime import datetime
from transformers import BertTokenizer, BertModel
import torch
@selfboot
selfboot / automator_cosupload
Created October 30, 2023 01:43
mac automator tool,Monitor folder, automatically compress and upload images to COS.
on run {input, parameters}
set currentDate to do shell script "date '+%Y%m%d'"
tell application "System Events"
repeat with i in input
set filePath to POSIX path of i
set fileExtension to name extension of i
set folderName to do shell script "dirname " & filePath
set fileName to name of i
set AppleScript's text item delimiters to "."
set baseName to first text item of fileName
#include <zip.h>
#include <iostream>
#include <string>
#include <vector>
struct FileInfo {
std::string htmltemlate;
std::string filename;
};
@selfboot
selfboot / FP_dynamic_demo
Created October 17, 2023 03:28
In the case of dynamic linking, if there are third-party dependencies in the middle without the compilation option '-fno-omit-frame-pointer', theoretically it should be the same as static linking, and the stack information will be out of order
$ tree
.
├── dynamic_A
│   ├── dynamic_A.cpp
│   └── dynamic_A.h
├── dynamic_B
│   ├── dynamic_B.cpp
│   └── dynamic_B.h
├── main.cpp
├── Makefile
@selfboot
selfboot / FP_static_demo
Last active October 17, 2023 02:35
Suppose there is a main.cpp which depends on utils.cpp and static libraries static_A, and static libraries static_A depend on static libraries static_B, here static_A compile without -fno-omit-frame-pointer, but everything else with -fno-omit-frame-pointer, and the final generated binary, each static library and cpp Do functions in files have fr…
$ tree
.
├── main.cpp
├── Makefile
├── static_A
│   ├── static_A.cpp
│   └── static_A.h
├── static_B
│   ├── static_B.cpp
│   └── static_B.h
@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")