Skip to content

Instantly share code, notes, and snippets.

@vnext-nguyen-quyen
vnext-nguyen-quyen / m3u8-to-mp4.md
Created March 31, 2022 03:19 — forked from tzmartin/m3u8-to-mp4.md
m3u8 stream to mp4 using ffmpeg

1. Copy m3u8 link

Alt text

2. Run command

echo "Enter m3u8 link:";read link;echo "Enter output filename:";read filename;ffmpeg -i "$link" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 $filename.mp4
@vnext-nguyen-quyen
vnext-nguyen-quyen / refresh-env.sh
Created September 7, 2022 02:00 — forked from lex64/refresh-env.sh
Generate Laravel .env file from AWS Parameters Store
#!/bin/bash
PARAMATER="laravel-env"
REGION="eu-central-1"
WEB_DIR="/var/www/laravel"
WEB_USER="www-data"
# Get parameters and put it into .env file inside application root
aws ssm get-parameter --with-decryption --name $PARAMATER --region $REGION --query Parameter.Value | sed -e 's/^"//' -e 's/"$//' -e 's/\\n/\n/g' -e 's/\\//g' > $WEB_DIR/.env
@vnext-nguyen-quyen
vnext-nguyen-quyen / amazon-linux2-userdata
Created October 6, 2022 08:52 — forked from Ammly/amazon-linux2-userdata
Amazon Linux 2 Laravel, Nginx, PHP7.4, Mariadb Userdata
#!/bin/sh
sudo yum update -y
sudo amazon-linux-extras install nginx1 php7.4 -y
sudo yum clean metadata
sudo yum install git mariadb-server php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip} -y
# Back up existing config
sudo cp -R /etc/nginx /etc/nginx-backup
sudo chmod -R 777 /var/log
sudo chown -R ec2-user:ec2-user /usr/share/nginx/html
echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/index.php
@vnext-nguyen-quyen
vnext-nguyen-quyen / all_aws_lambda_modules_python.md
Created October 15, 2022 15:27 — forked from gene1wood/all_aws_lambda_modules_python.md
AWS Lambda function to list all available Python modules for Python 2.7 3.6 and 3.7
@vnext-nguyen-quyen
vnext-nguyen-quyen / Noto-Sans-Jp.md
Created December 23, 2022 07:00 — forked from manabuyasuda/Noto-Sans-Jp.md
Noto Sans JPを使うための手順。

Noto Sans JP

Noto Sans JPをWebサイトで使う場合、大きく分けて2つの方法があります。

  1. CDNを使う場合
  2. サーバーにフォントファイルを置く場合

CDNの場合は、他のサイトを含めて一度でも読み込まれていればブラウザ側でキャッシュを持っているので、読み込み速度が速くなることが期待できます。
サーバーのフォントファイルはサブセット化(不要なデータを削除すること)でファイルサイズを削減できるメリットがあります。

基本的にはCDNを利用して、フォールバックとしてサーバーに置いたフォントファイルとシステムフォントを指定するのがいいでしょう。

@vnext-nguyen-quyen
vnext-nguyen-quyen / cron-tab-docker-logs.txt
Last active January 9, 2023 07:40
See cron log ouput with docker logs
1. Alpine (No need for redirection)
using the default cron utility (busybox)
## Dockerfile
=====
FROM alpine:3.7
# Setting up crontab
COPY crontab /tmp/crontab
@vnext-nguyen-quyen
vnext-nguyen-quyen / install_mysql_client.sh
Created July 10, 2023 16:58
Install MySQL 8.0 client on Amazon Linux 2023
#!/bin/sh
# Docs: https://dev.mysql.com/doc/mysql-repo-excerpt/8.0/en/linux-installation-yum-repo.html
# Install repo
wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
sudo dnf install mysql80-community-release-el9-1.noarch.rpm
# Verify enabled mysql80-community repo
sudo dnf repolist enabled
@vnext-nguyen-quyen
vnext-nguyen-quyen / gist:2da0ec8e47aed54c667fe41db5b0811e
Created July 13, 2023 05:01
PHP get memory and excution usage
# Check excution time in seconds
$start = microtime(true);
// Excute PHP scripts
echo "Total execution time in seconds: " . (microtime(true) - $start);
# Check memory usage in MiB
"Real RAM: ".(memory_get_peak_usage(true)/1024/1024)." MiB\n\n"
There are two ways to efficiently (read: quickly) load 7000 rows.
LOAD DATA INFILE -- After you have built a 7000-line CSV file.
"Batch" INSERT -- like INSERT INTO t (a,b) VALUES (1,2),(5,6),(9,2), ...; -- Be cautious about the number of rows. 100 to 1000 is a good range of what to do at a time.
max_allowed_packet=536870912 -- NO, not in a tiny 2GB VM; change to 16M. Other likely settings to check:
key_buffer_size = 10M
innodb_buffer_pool_size = 1GB
1. Convert timestamp to microsecond bigint:
SELECT EXTRACT(EPOCH FROM to_timestamp('20210311 09','yyyymmdd TZH'))::bigint
2. Covnert string to timestampt with timemodified timezone +9:
to_timestamp(timemodified) >= to_timestamp(''20210309000000 09'',''yyyymmddhh24miss TZH'')