Skip to content

Instantly share code, notes, and snippets.

View leonmax's full-sized avatar

Yangming leonmax

View GitHub Profile

Implementing gtree & gcd

TL;DR

add the following line to your ~/.bashrc

alias gtree="fd '\.git$' --prune -utd |  tree --fromfile ."

And then you can use gtree to find all repos under current directory. With some extra effort, one can cd into any repo folder with tab completion.

Details

@leonmax
leonmax / import-ali-kubeconfig
Last active November 14, 2022 03:03
import each aliyun ACK cluster into it's own kubeconfig
#!/usr/bin/env bash
CMD=`basename "$0"`
if [ -z $1 ] ; then
echo "Usage:"
echo " $CMD cluster_name [save_to_path]"
echo "To list cluster names:"
echo " aliyun cs DescribeClusters | jq -r '.[].name'"
echo "Dependencies:"
echo " - aliyun-cli"
@leonmax
leonmax / oss_auth_code.py
Last active November 14, 2022 04:34
sample to load from oss auth_code and download files recurisvely
import base64
import json
import pathlib
import re
import sys
from urllib.error import URLError
import oss2
OSS_URL_PATTERN = re.compile(
@leonmax
leonmax / find_dup.awk
Last active November 14, 2022 04:34
Find duplicated files (of the same md5) within a folder using awk.
#!/usr/bin/env -S awk -f
# Example usage:
# `fd -tf -x md5 -r | find_dup | jq -s`
# (the example assume you have `fd` and `jq`, which is not required for this script.
{
md5=$1; # md5 is expected as 1st argument
$1=""; # shift
gsub(/^[ \t]+|[ \t]+$/, ""); # trim
@leonmax
leonmax / swap_display.py
Last active November 14, 2022 04:36
Swap displays position
#!/usr/bin/env python
import os
import sys
import subprocess
import re
import json
import pickle
from dataclasses import dataclass
from typing import Tuple, List
@leonmax
leonmax / gen_pb.sh
Created June 13, 2020 16:28
generate `*_pb*.py` with bazel and copy to project
#!/usr/bin/env bash
function info () {
printf "\r \033[00;34m>>>\033[0m %s \n" "$1"
}
function remove_old() {
info "Remove all previous generated files!"
local VERBOSE="$1"
if [ -z "$VERBOSE" ]
@leonmax
leonmax / explain.md
Last active June 10, 2020 08:03
move image file into their time separated folders based on their EXIF (or fallback to creation time)

requires exifread

pip install exifread
@leonmax
leonmax / explain.md
Last active March 27, 2020 03:53
Apple Interview question

The first code piece input[0] is required. If it is an empty string it will not work. This is just to be defensive (of course your probably need to check None or other types as well to be even more defensive)

One of the difference I have is a treat the first element no different from the rest. And I've made function and assert (tests) to verify them. If I see this in the exam, I know this is a experienced engineer who has a good sense how to test rather than relying on stardard output.

# -*- mode: ruby -*-
# vi: set ft=ruby :
boxes = [{
:name => "luffy",
:eth1 => "192.168.88.10",
}, {
:name => "zoro",
:eth1 => "192.168.88.11",
}, {
@leonmax
leonmax / open_safe.py
Last active August 29, 2015 14:20
open safe
__author__ = 'leonmax'
'''
You are given a SAFE, with 4 dials on it
dials are numbered 0-9, continuous, integral
key to this safe -> can *only* be opened in the
fewest number of turns