Skip to content

Instantly share code, notes, and snippets.

View leonmax's full-sized avatar

Yangming leonmax

View GitHub Profile
@leonmax
leonmax / nav.lua
Last active August 29, 2015 14:02
nav module for turtle in computercraft
local SlotManager = {}
SlotManager.__index = SlotManager
function SlotManager.new()
local self = setmetatable({}, SlotManager)
self.selectedSlot = 1
return self
end
function SlotManager:select(s)
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
var getUrl = function(bucket, path, callback) {
var params = {Bucket: bucket, Key: path};
s3.getSignedUrl('getObject', params, callback);
}
@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
# -*- mode: ruby -*-
# vi: set ft=ruby :
boxes = [{
:name => "luffy",
:eth1 => "192.168.88.10",
}, {
:name => "zoro",
:eth1 => "192.168.88.11",
}, {
@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.

@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 / 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 / exec.py
Last active September 12, 2021 20:15
sample to run subprocess and log stdout/stderr with asyncio
__author__ = 'leonmax'
import asyncio
from asyncio import (coroutine, subprocess)
import sys
import logging
FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(level=logging.INFO, format=FORMAT)
@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(