Skip to content

Instantly share code, notes, and snippets.

@yaozongyou
yaozongyou / get_machine_physical_ipv4.cpp
Created March 10, 2023 12:54
get machine physical ipv4 using netlink
#include <arpa/inet.h>
#include <asm/types.h>
#include <linux/if_link.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
@yaozongyou
yaozongyou / epub_change_title.sh
Created March 13, 2020 02:07
epub change title
#!/bin/bash
echo "$1" "$2"
mkdir tmp
cp "$1" "${1}.bak"
mv "$1" tmp/
pushd tmp
unzip "$1"
sed -i "/dc:title/c\ <dc:title>$2</dc:title>" ./content.opf
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"copyOnSelect": true,
"launchMode": "maximized",
"profiles":
[
{
@yaozongyou
yaozongyou / create_bucket.sh
Last active August 8, 2018 13:51
Some bash scripts for operating with ceph object gateway.
#!/bin/bash
access_key='0555b35654ad1656d804'
secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=='
date=$(date -R -u)
string_to_sign="PUT\n\n\n${date}\n/testbucket/"
signature=$(echo -en ${string_to_sign} | openssl sha1 -hmac ${secret_key} -binary | base64)
curl "http://127.0.0.1:8000/testbucket/" \
-H "Date: ${date}" \
-H "Content-Length: 0" \
#include <vector>
#include "common/log_message.h"
#include "include/rados/librados.hpp"
#include "common/config.h"
#include "common/ceph_argparse.h"
#include "global/global_init.h"
#include "global/global_context.h"
#include "include/rados/rados_types.hpp"
using namespace librados;
@yaozongyou
yaozongyou / crush.cpp
Created January 31, 2018 05:59
crush test
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <map>
#include <random>
#include <vector>
double DrawStraw(uint32_t pg_id, uint32_t osd_id, double weight) {
@yaozongyou
yaozongyou / outline.c
Last active November 1, 2017 15:25
xml parser
#include <stdio.h>
#include <expat.h>
#define BUFFSIZE 8192
char Buff[BUFFSIZE];
int Depth;
void start(void *data, const char *el, const char **attr) {
@yaozongyou
yaozongyou / executor.h
Created October 26, 2017 07:07
c++11 threadpool
#pragma once
#include <atomic>
#include <cassert>
#include <functional>
#include <mutex>
#include <queue>
#include <thread>
#include <unordered_map>
#include "semaphore.h"
@yaozongyou
yaozongyou / s3_test.go
Created October 15, 2017 03:07
Access rgw use golang.
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
@yaozongyou
yaozongyou / test.cpp
Created September 21, 2017 12:32
test for rgw file
#include <errno.h>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int32_t main(int32_t argc, char* argv[]) {
if (argc != 2) {