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 / graphics_cli.py
Last active September 2, 2024 04:21
Displaing rectangles, squares, and tables in the CLI.
#!/usr/bin/env python3.9
r_w3_h2 = """\
┌─┐
└─┘"""
r_w5_h3 = """\
┌───┐
│ │
└───┘"""
r_w7_h4 = """\
@duruyao
duruyao / qwer.py
Last active September 2, 2024 04:22
A command line game for typing practice.
#!/usr/bin/env python3
# date: 2022-07-08
# author: [email protected]
# desc: command line game for typing practice
import os
import sys
import time
import random
import string
@duruyao
duruyao / create-user.sh
Last active September 2, 2024 04:23
Creating new user in Linux and adding it to sudo or other groups.
#!/usr/bin/env bash
## date: 2022/02/21
## author: [email protected]
## desc: the shortcut to create user
## usage: bash create-user.sh [NEW_USERNAME] [NEW_USER_PASSWD]
set -euo pipefail
function warning_ln() {
@duruyao
duruyao / retry.sh
Last active September 2, 2024 04:25
Try running the command again until it succeeds.
#!/usr/bin/env bash
## date: 2022-01-19
## author: [email protected]
## desc: retry running a command if fails
## usage: bash retry.sh <COMMAND>
set -euo pipefail
command=("$@")
@duruyao
duruyao / docker-proxy-turn-off.sh
Last active September 2, 2024 04:47
Turning Docker's proxy off or on.
#!/usr/bin/env bash
## date: 2022-01-19
## author: [email protected]
## desc: disable proxy for docker
## usage: bash docker-proxy-turn-off.sh
rm -f "${HOME}/.docker/config.json"
@duruyao
duruyao / moving_docker_data.md
Last active September 2, 2024 04:29
Moving Docker data to the new directory.

Moving Docker Data

  1. Show docker root directory (default: /var/lib/docker).
docker_root="$(docker info -f '{{ .DockerRootDir }}')"
echo "${docker_root}"
  1. Start the docker containers and display the free size of the hard disk where the current docker root directory is located.
@duruyao
duruyao / docker-container-cleaner.sh
Last active September 2, 2024 04:32
Automatically cleaning up exited docker containers periodically.
#!/usr/bin/env bash
## date: 2022-01-14
## author: [email protected]
## desc: clean up exited docker containers
set -euo pipefail
tmp_path="${HOME}/.exited-containers"
log_path="${HOME}/.docker-container-cleaner.log"
@duruyao
duruyao / console_print.h
Last active September 2, 2024 04:33
Printing logs of different levels in different colors on the console (implemented in C/C++).
/*
* @date 2022-06-19
* @author [email protected]
* @desc print different levels of logs in the console
*/
#ifndef CONSOLE_PRINT_H
#define CONSOLE_PRINT_H
#include <stdio.h>
@duruyao
duruyao / read-2d-array.sh
Last active September 2, 2024 04:39
Reading two-dimensional array by Bash script.
#!/usr/bin/env bash
## date: 2021-12-14
## author: [email protected]
## desc: read two-dimensional array by Bash script
data=(
'00007887.JPEG JPEG 500x333 500x333+0+0 8-bit sRGB 81.6KB 0.000u 0:00.000'
'00007893.JPEG JPEG 480x411 480x411+0+0 8-bit Grayscale Gray 256c 54KB 0.000u 0:00.000'
'00007894.JPEG JPEG 500x375 500x375+0+0 8-bit sRGB 52.9KB 0.000u 0:00.000'
@duruyao
duruyao / dk-attach
Last active September 2, 2024 04:40
The shortcuts to run Docker container.
#!/usr/bin/env bash
## date: 2021-12-06
## author: [email protected]
## desc: the shortcut to attach docker container
##
## usage: dk-attach [CONTAINER]
##