Skip to content

Instantly share code, notes, and snippets.

@liuyangc3
liuyangc3 / main.go
Last active November 7, 2023 02:21
revert shell
package main
import (
"fmt"
"log"
"net/http"
"os/exec"
"strings"
)
@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 / query merge request
Last active March 12, 2022 01:49
using Github graphql API to get all MR in a repo
query {
repository(name: "zen", owner: "HorizenOfficial") {
pullRequests(first: 100, states: [MERGED], orderBy: {field: CREATED_AT, direction: DESC}) {
totalCount
nodes {
title
state
checksUrl
mergedAt
}
#!/bin/sh
# this script allow you run a container attached to node with root privilege
# see https://securek8s.dev/exercise/65-privileged/
# usage:
# kubectl get nodes
# ./k8s_attach_node.sh <node name>
node=${1}
if [ -n "${node}" ]; then
@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 / keybase.md
Created December 16, 2020 03:08
keybase.md

Keybase proof

I hereby claim:

  • I am liuyangc3 on github.
  • I am liuyangc3 (https://keybase.io/liuyangc3) on keybase.
  • I have a public key ASDvUyBrV6i1MHOYQgY3SyotpR62nkvo3gkKtlUB8UNZxAo

To claim this, I am signing this object:

@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