Skip to content

Instantly share code, notes, and snippets.

@liuyangc3
liuyangc3 / Access AMP metrics.md
Last active August 11, 2022 10:59 — forked from robskillington/prometheus.proto
Example Python Prometheus remote write client

Install awscurl

pip install awscurl

Query metrics on ec2

TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
CREDENTIAL=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/amp-instance-role)
@liuyangc3
liuyangc3 / eth_base_fee_calc.py
Created June 15, 2022 08:46
Example of how a block's base gas fee is calculated on Ethereum
# Reference: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md
BASE_FEE_MAX_CHANGE_DENOMINATOR = 8
ELASTICITY_MULTIPLIER = 2
# Calculate expected base fee for block 12965001
current_block = 12965000 # London Upgrade block
# Get the following values from Etherscan: https://etherscan.io/block/12965000
parent_base_fee_per_gas = 1000000000 # 1 Gwei
@liuyangc3
liuyangc3 / oidc-thumbprint-regions.sh
Last active July 13, 2021 02:22 — forked from riccardomc/oidc-thumbprint-regions.sh
Extract OIDC provider thumbprint for all AWS Region with EKS support
#!/bin/bash
# https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html
set -e
if [ ! -z "$DEBUG" ] ; then
set -x
fi
@liuyangc3
liuyangc3 / parse_yaml.sh
Last active August 6, 2021 03:01 — forked from pkuczynski/parse_yaml.sh
Read YAML file from Bash script
#!/bin/sh
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
@liuyangc3
liuyangc3 / ca.md
Created May 29, 2020 06:00 — forked from soarez/ca.md
How to setup your own CA with OpenSSL

How to setup your own CA with OpenSSL

For educational reasons I've decided to create my own CA. Here is what I learned.

First things first

Lets get some context first.

@liuyangc3
liuyangc3 / ITERM2.md
Last active March 17, 2021 02:50 — forked from YumaInaura/ITERM2.md
iTerm2 — search keyword and copy and paste text

iTerm2 — search keyword and copy and paste text

Output example

image

Command + F to start search mode

image

@liuyangc3
liuyangc3 / gist:2def8aa8f2b0db8c973cc0d1aca78957
Created January 9, 2019 04:57 — forked from sing1ee/gist:5971946
Google面试题:扔鸡蛋问题

###Google面试题:扔鸡蛋问题

####原题描述 两个软硬程度一样但未知的鸡蛋,它们有可能都在一楼就摔碎,也可能从一百层楼摔下来没事。有座100层的建筑,要你用这两个鸡蛋通过最少的次数确定哪一层是鸡蛋可以安全落下的最高位置。可以摔碎两个鸡蛋

####方法分析 看到这个题目,最保险的方法就是一层一层试验,但这样只需要一个鸡蛋就可以了。我们现在有两个鸡蛋,完全可以用有更快的方法。

进一步呢?可能试验的方法是二分查找,例如,第一个鸡蛋再50层扔下,如果碎了,第二个鸡蛋从1-49逐层试验;如果没碎,第一个鸡蛋在75层扔下,如果碎了,第二个鸡蛋从51-74逐层试验…但是,这个方法,很容易悲剧,例如,当正好49层是可以安全落下的,需要尝试50次。比只有一个鸡蛋的情况,效果还要差。

@liuyangc3
liuyangc3 / find-futex-wait.sh
Last active October 8, 2019 12:19 — forked from amr/find-futex-wait.sh
Find processes executing futex with FUTEX_WAIT (helps find deadlock-ed processes)
#!/bin/bash
#
# Find all processes that are executing a futex(2) call with op=FUTEX_WAIT
# In some cases this can be helpful in finding deadlock-ed processes.
#
test ! $UID -eq 0 && echo -e "WARNING: Not running as root, only processes for this user are being scanned\n" >&2;
pids=$(ps -u $UID -opid --no-headers)
sub_pid=$(($$+1))