Skip to content

Instantly share code, notes, and snippets.

View Edison-Hsu's full-sized avatar
🎯
Focusing

Edison.Hsu Edison-Hsu

🎯
Focusing
View GitHub Profile
@Edison-Hsu
Edison-Hsu / gist:3dc918c6e2a60189ffa5c686a2b9776e
Created November 17, 2022 14:21
assume a role in one line command
export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \ $(aws_prompt_info)
$(aws sts assume-role \
--role-arn arn:aws-cn:iam::xxxx:role/xxxx \
--role-session-name MySessionName \
--query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \
--output text))
@Edison-Hsu
Edison-Hsu / golang_work_queue_example.go
Created December 16, 2019 06:48
golang_work_queue_example
func worker(jobChan <-chan Job) {
for job := range jobChan {
process(job)
}
}
// make a channel with a capacity of 100.
jobChan := make(chan Job, 100)
// start the worker
while true ; do ./check_domain.sh & sleep 5; done
#!/bin/sh
IP=${1:-"221.125.113.13"}
echo $IP
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables -t nat -F
iptables -X
#! /bin/sh
DOMAIN="us0.0bad.com"
IP=`dig +short $DOMAIN`
OLD_IP=`cat ip.txt`
if [ "$OLD_IP" = "$IP" ]; then
echo "query $DOMAIN address: $IP" >> query_ip.log
else
echo "query $DOMAIN address changed, old: $OLD_IP, new: $IP" >> query_ip.log
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.daocloud.io/docker/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository \
"deb [arch=$(dpkg --print-architecture)] https://download.daocloud.io/docker/linux/ubuntu \
$(lsb_release -cs) \
@Edison-Hsu
Edison-Hsu / ubuntu_install_docker.sh
Last active January 13, 2018 14:57
ubuntu_install_docker
#! /bin/bash
apt-get upgrade
apt-get update
apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
@Edison-Hsu
Edison-Hsu / add_user.sh
Last active December 12, 2017 06:24
add_user.sh
#! /bin/sh
user=$1
group=${2:-wheel} # wheel/sudo
if [ -z "$user" ]; then
exit 1
fi
home=/home/$user
@Edison-Hsu
Edison-Hsu / new_user_with_sudo.txt
Last active August 23, 2017 10:41
new user with sudo
# Use the adduser command to add a new user to your system.
adduser #{username}
# Use the usermod command to add the user to the sudo group.
usermod -aG sudo #{username}
# Test sudo access on new user account
su - #{username}
sudo ls -la /root
@Edison-Hsu
Edison-Hsu / wechat-useragent.js
Created June 11, 2017 08:39 — forked from GiaoGiaoCat/wechat-useragent.js
微信内置浏览器UserAgent的判断
// 检测浏览器的 User Agent 应该是非常简单的事情
// 微信在 Android 下的 User Agent
mozilla/5.0 (linux; u; android 4.1.2; zh-cn; mi-one plus build/jzo54k) applewebkit/534.30 (khtml, like gecko) version/4.0 mobile safari/534.30 micromessenger/5.0.1.352
// 微信在 iPhone 下的 User Agent
mozilla/5.0 (iphone; cpu iphone os 5_1_1 like mac os x) applewebkit/534.46 (khtml, like gecko) mobile/9b206 micromessenger/5.0
// 通过javascript判断
// 很容易看出来,微信的 User Agent 都有‘micromessenger’字符串标示,我们判断是否含有这些字符串就OK了
function isWeixinBrowser(){