Skip to content

Instantly share code, notes, and snippets.

View duruyao's full-sized avatar
🏢
Coding in office

Ryan Du duruyao

🏢
Coding in office
View GitHub Profile
@duruyao
duruyao / auto_restore_gitlab.sh
Last active March 4, 2024 06:33
Automatically restore for Omnibus Gitlab installations from backups periodically.
#!/usr/bin/env bash
## date: 2021-11-11
## author: duruyao@vimicro.com
## desc: automatically restore for omnibus gitlab installations from backups at 14:00
set -euo pipefail
script_path="/home/duruyao/bin/gitlab-tools/restore-gitlab.sh"
auto_tasks=("0 14 * * * root ${script_path} CRON=1")
@duruyao
duruyao / auto_backup_gitlab.sh
Last active March 4, 2024 06:30
Automatically backup Omnibus GitLab packages to local and remote periodically.
#!/usr/bin/env bash
## date: 2021-11-11
## author: duruyao@vimicro.com
## desc: automatically backup omnibus gitlab packages to local and remote at 2:00
set -euo pipefail
script_path="/home/duruyao/bin/gitlab-tools/backup-gitlab.sh"
auto_tasks=("0 2 * * * root ${script_path} CRON=1")
@duruyao
duruyao / docker-run.sh
Last active January 5, 2024 02:30
Docker container running tool: use the host's user and configuration within the container and cache the software packages to the host.
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
# usage: bash docker-run.sh [OPTIONS] IMAGE [COMMAND] [ARG...]
function get_valid_port() {
local random_port
@duruyao
duruyao / custom_routing_table.md
Last active September 19, 2023 01:42
Custom routing table.

I have an Ubuntu system that uses two wired networks simultaneously (PCI Ethernet, USB Ethernet). I would like it to use the USB wired network for internet access and the PCI wired network for accessing the internal network (e.g., 10.0.13.120, 10.0.13.134, 10.0.12.1, 10.0.10.16, 10.0.10.17, etc).

1.

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.1   0.0.0.0         UG    101    0        0 usb0
0.0.0.0         192.168.31.1    0.0.0.0         UG    102    0        0 enp4s0
@duruyao
duruyao / console_print.h
Last active March 16, 2023 03:54
An example of printing logs of different levels in different colors on the console (implemented in C/C++).
/*
* @date 2022-06-19
* @author duruyao@gmail.com
* @desc print different levels of logs in the console
*/
#ifndef CONSOLE_PRINT_H
#define CONSOLE_PRINT_H
#include <stdio.h>
@duruyao
duruyao / protobuf_rw_file.cpp
Last active March 15, 2023 08:27
Save files to and load files from Protocol Buffers Messages (implemented in C++).
/*
* @author duruyao
* @date 2023-03-14
* @desc save files to and load files from protobuf messages
* @usage EXECUTABLE <SRC_FILENAME> <DST_FILENAME>
*/
#include <cstdio>
#include <string>
@duruyao
duruyao / setup.py
Last active March 15, 2023 08:27
Use Cython to compile the Python3 sources to C/C++ shared libraries and executables.
#!/usr/bin/env python3.9
import os
import re
import sys
import glob
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
@duruyao
duruyao / get_ball.py
Created January 5, 2023 04:08
The game of getting balls.
import sys
def have_wining_strategy(*bags: int) -> bool:
if 0 == sum(bags):
return False
for i in range(len(bags)):
for n in range(bags[i]):
if not have_wining_strategy(*bags[:i], n, *bags[i + 1:]):
return True
@duruyao
duruyao / py_project_coding_style_example.py
Last active November 2, 2022 09:59
Python3 project coding style example.
#!/usr/bin/env python3
from typing import Union, Optional, Dict
def multiply(arg1: Union[int, float, str, None] = 0.0,
arg2: Union[int, float, str, None] = 0.0) -> Optional[Dict[str, Union[int, float, str]]]:
"""
Calculate the product of two numbers.
:param arg1: a factor (default: 0.0)