Skip to content

Instantly share code, notes, and snippets.

View phainamikaze's full-sized avatar

Witsanu Boonamakam phainamikaze

View GitHub Profile
@phainamikaze
phainamikaze / gist:82a57d398e37da2e7f24fb1037420f66
Created February 6, 2021 08:09
Alibaba Cloud Tech Share – Install Cloud Hosted Router (CHR) RouterOS MikroTik
Minimal requirements:
64bit CPU with virtualization support
128 MB or more RAM for the CHR instance
128 MB disk space for the CHR virtual hard drive
You can use Elastic Compute Engine Starter Package Plan/ Entry Level Using Ubuntu 16.04 64bit
1. Open Putty, Login to your ECS using IP address root. (SSH port 22)
2. Paste this script to your terminal
wget https://download2.mikrotik.com/routeros/6.40.5/chr-6.40.5.img.zip -O chr.img.zip && \
const fs = require('fs');
async function example() {
const client = new ftp.Client()
client.ftp.verbose = true
try {
const secureOptions = {
// Necessary only if the server requires client certificate authentication.
key: fs.readFileSync('client-key.pem'),
cert: fs.readFileSync('client-cert.pem'),
@phainamikaze
phainamikaze / imgbase64
Created October 10, 2021 07:50
image base64
<img src="data:image/png;base64,xxxxx"/>
xxxxx is imgbase64
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+gAAAdNCAYAAADwPXCqAAN3YUlEQVR4AezBCXiUhaHv4d/3zSRMEpZggYQb2wRPrwmgBo4mIW6BNtK6oSxiUdlOxbZRrO1RC2qr1qpUe8TWGq22CmrdUFKpiEA0iwomQWFYsig2M0LMhjIhkkxm+b57x/PMuWmaICI699H/+xojRh5vIyIiIiIiIiIxZSIiIiIiIiIiMWciIiIiIiIiIjFnIiIiIiIiIiIxZyIiIiIiIiIiMWciIiIiIiIiIjFnIiIiIiIiIiIxZyIiIiIiIiIiMWciIiIiIiIiIjFnIiIiIiIiIiIxZyIiIiIiIiIiMWciIiIiIiIiIjFnIiIiIiIiIiIxZyIiIiIiIiIiMWciIiIiIiIiIjFnIiIiIiIiIiIxZyIiIiIiIiIiMedERERE5GskJXU0rkEuIvw9flpbmhEREfn/gRMRERGRrziXK4HcvElkZ08kOTmZ3nw+H273VioryhAREYklJyIiIiJfYSmpo5k7dwEJCQn4OnxUV23G7/cTMSw5mczMsRQUTCEzM4s1a/5Ga0szhyM9YwyZx2eRkjoaf083Xo+H7e5t+P3dRCQPS+akCRPpq8Pnw+tpxNfhIyp5WDInTZjIoXi9HryeRpKHJXPShIkcitfrwetpJD1jDOnpGfTV4fPR0FCP399Nb+kZY0hPz+DTVFaUEZGdPZFhyckMpMPnw+3eSpTLlcBJ2RNITUllWPJwWlua8XobaWioJ+rMgil8mg6fD7d7K//27ePZu+d9enr8iIh8FTgRERER+YpKSR3N3LkLSEhIYMP6dVRVbaYvl+tl8vImcWbBFObOXcCfH3oAX4ePQ5k2bTrZEybSW1bmWM48czIbN7yM272VYcOHU1AwhYFUVJRRWVFGxLDhwykomMKhVFaU4fU0
@phainamikaze
phainamikaze / wrk install
Created October 11, 2021 16:36
load test tools
sudo apt-get install build-essential libssl-dev git -y
git clone https://github.com/wg/wrk.git wrk
cd wrk
sudo make
# move the executable to somewhere in your PATH, ex:
sudo cp wrk /usr/local/bin
#!/bin/sh -e
/root/OoklaServer —daemon
exit 0
def isPrime(num):
flag = False
if num == 1:
return False
elif num > 1:
# check for factors
for i in range(2, num):
if (num % i) == 0:
# if factor is found, set flag to True
@phainamikaze
phainamikaze / query.sql
Created November 15, 2023 06:20
Write a query to rank the countries in each region by their population from largest to smallest.
SELECT Region, Name, Population, RANK() over(partition by region ORDER BY population desc) as 'Ranked' FROM world.country ;
create database aws;
use aws;
CREATE TABLE RESTART (
StudentID int not null AUTO_INCREMENT,
StudentName varchar(255),
RestartCity varchar(255),
GraduationDate Datetime,
PRIMARY KEY (StudentID)
);
@phainamikaze
phainamikaze / EC2 Instance Connect session
Created November 27, 2023 12:23
EC2 Instance Connect session lab 171
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
#Set the Region
AZ=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone -H "X-aws-ec2-metadata-token: $TOKEN"`
export AWS_DEFAULT_REGION=${AZ::-1}
echo $AWS_DEFAULT_REGION
#Retrieve latest Linux AMI
AMI=$(aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 --query 'Parameters[0].[Value]' --output text)
echo $AMI
import json
import urllib.parse
import boto3
import os
print('Loading function')
s3 = boto3.client('s3')
TOPIC_ARN = os.environ['topicARN']
def lambda_handler(event, context):