Skip to content

Instantly share code, notes, and snippets.

@a9QrX3Lu
a9QrX3Lu / field2json.py
Last active August 15, 2021 06:05
Transform field list like into json object. Field list looks like https://docs.ceph.com/en/latest/radosgw/lua-scripting/#id6.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
with open("temp.txt", 'r') as f:
lines = f.readlines()
output = []
for line in lines:
@a9QrX3Lu
a9QrX3Lu / oss-md5check.sh
Created August 12, 2021 06:06
Check md5 of multiple files on Aliyun OSS
#!/bin/bash
src_dir=/home/wzl/OneDrive/quant/data/data_md5
dst_dir=oss://edaoquant
check_file() {
src_file=$1
dst_file=$2
echo $dst_file
echo $src_file
@a9QrX3Lu
a9QrX3Lu / lat_breakdown.h
Created July 13, 2021 12:13
Breakdown latency of a C++ program
#ifndef LAT_BREAKDOWN_H_
#define LAT_BREAKDOWN_H_
#include <chrono>
namespace utils {
struct LatBreakdown {
std::chrono::nanoseconds total_lat_ = static_cast<std::chrono::nanoseconds>(0);
std::vector<std::chrono::nanoseconds> lats_;
@a9QrX3Lu
a9QrX3Lu / gen_plot.py
Last active July 15, 2021 09:59
Generate plot for a dataset
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import argparse
import matplotlib.axes
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
@a9QrX3Lu
a9QrX3Lu / git-record-obj.sh
Last active July 7, 2021 02:29
Save a copy of current output, which related to current git branch name, commit hash, system environment and time.
#!/usr/bin/env bash
repo=$(basename -s .git $(git config --get remote.origin.url))
tag=$(git name-rev --tags --name-only $(git rev-parse HEAD))
branch=$(git rev-parse --abbrev-ref HEAD)
timestamp=$(hostname)-$(uname -r)-$(date -I'seconds')
msg=$(git log -1 | cat)
DIR=~/testdata/${repo}/"${timestamp}-${branch}-${tag}"
@a9QrX3Lu
a9QrX3Lu / Makefile.common
Last active June 15, 2021 11:27
Common makefile
#usage: include Makefile.common at the end of your Makefile
# no builtin rules/vars (CC, CXX, etc. are still defined but will be empty)
MAKEFLAGS += -r -R
HDR = $(addsuffix .h,$(MODULES) $(HEADERS))
SRC = $(addsuffix .c,$(MODULES) $(SOURCES))
ASM = $(addsuffix .S,$(ASSMBLY))
OBJ = $(addsuffix .o,$(MODULES) $(SOURCES) $(ASSEMBLY))
DEP = Makefile.common Makefile $(HDR) $(EXTERNDEP) $(EXTERNSRC)
@a9QrX3Lu
a9QrX3Lu / jobnotifier.py
Last active June 13, 2021 11:27
Notification for a finished long-running job
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
SERVER = "smtp.office365.com"
PORT = "587"
FROM = "wzl574402791@outlook.com"
TO = ["zl31wang@gmail.com"]
SUBJECT = "A job finished"
TEXT = "Hi! A job finished. Please take a look."
@a9QrX3Lu
a9QrX3Lu / dump_cache.sh
Created April 12, 2021 03:53
Dump Intel CPU cache architecture
#!/bin/bash
unshared () {
grep '^[0-9]\+$' "$1" > /dev/null
}
for cpu in $(ls -d /sys/devices/system/cpu/cpu[0-9]* | sort -t u -k 3 -n); do
echo "${cpu##*/}: [Package #$(cat $cpu/topology/physical_package_id), Core #$(cat $cpu/topology/core_id)]"
if ! unshared $cpu/topology/core_siblings_list; then
echo " same package as $(cat $cpu/topology/core_siblings_list)"
@a9QrX3Lu
a9QrX3Lu / echo.py
Created March 5, 2021 08:19
simple tcpreplay implementation
import sys
import asyncio
async def handle_echo(reader, writer):
while True:
message = await reader.read(1000)
print(f'get message {message}')
writer.write(message)
#! /bin/bash
# Trace system calls in [ftrace] binary file
# Output to ftrace_out.log
tracefs=/sys/kernel/debug/tracing
gcc -o ftrace ftrace.c
echo nop > ${tracefs}/current_tracer # Use NOP tracer at first
echo 0 > ${tracefs}/tracing_on # Disable tracing