Skip to content

Instantly share code, notes, and snippets.

View nmvuong92's full-sized avatar
🎯
Focusing

Vượng Nguyễn nmvuong92

🎯
Focusing
View GitHub Profile
@nmvuong92
nmvuong92 / golang s3 download with progressbar.go
Last active October 12, 2023 05:07
golang s3 download with progressbar
package awss3
import (
"crypto/tls"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"time"
@nmvuong92
nmvuong92 / kubernetes_commands.md
Created September 18, 2023 02:57 — forked from edsiper/kubernetes_commands.md
Kubernetes Useful Commands
@nmvuong92
nmvuong92 / ec2-node-amzn.sh
Created September 3, 2023 05:31 — forked from matwerber1/ec2-node-amzn.sh
ec2-amazon-linux-node-userdata
#!/bin/bash
# Program:
# EC2 initially install node.js, git for development environment.
# You can modify nodev and nvmv for changing node and nvm version.
# Set permission to ec2-user install above.
# History:
# 2017/07/25 Hans First release
home=/home/ec2-user
nodev='8.11.2'
nvmv='0.33.11'
@nmvuong92
nmvuong92 / user-data.sh
Created September 3, 2023 05:30 — forked from abhilash1in/user-data.sh
Install nvm and NodeJS using AWS EC2 user data script
#!/bin/bash
apt-get -y update
cat > /tmp/subscript.sh << EOF
# START UBUNTU USERSPACE
echo "Setting up NodeJS Environment"
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.9/install.sh | bash
echo 'export NVM_DIR="/home/ubuntu/.nvm"' >> /home/ubuntu/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> /home/ubuntu/.bashrc
# Dot source the files to ensure that variables are available within the current shell
. /home/ubuntu/.nvm/nvm.sh
@nmvuong92
nmvuong92 / middleware trong react redux.md
Last active July 3, 2023 15:59
middleware trong react redux

Async action là gì?

  • Async => bất đồng bộ?, Action => hành động?
  • là một action trong trạng thái chưa sẵn sàng thực thi ví dụ Fetch API request lên server

Tại sao cần Middleware khi sử dụng Async action?

  • React không hỗ trợ async action => cần 1 middleware trung gian điều phối việc nhận kết quả fetch trả về từ api rồi khi nào mới được dispatch => đảm bảo không bị lỗi chương trình react

Middleware là gì?

  • khác với middleware ở server
@nmvuong92
nmvuong92 / DOCKER.md
Last active July 10, 2021 19:03
DOCKER

DOCKER

pull docker images

docker pull busybox

run docker pulled

docker pull busybox

run and echo

@nmvuong92
nmvuong92 / jquery-ajax-standard.js
Last active March 22, 2019 04:33
jquery-ajax-standard.js
//tham request số gọi ajax
var _param = {
pid:1,
color:'red'
};
//gọi ajax
$.ajax({
url:'https://jsonplaceholder.typicode.com/posts', //lấy danh sách bài viết
method:'get', //phương thức post/get
dataType:'json', //kiểu json
@nmvuong92
nmvuong92 / Unix timestamp - Thời gian Unix.md
Last active January 18, 2019 07:09
Unix timestamp - Thời gian Unix

1

Khái niệm quen thuộc trong hệ thống Unix và lập trình PHP. Thời gian Unix, là hệ thống nhằm diễn tả một điểm trên trục thời gian, theo trục thời gian nó sử dụng số giây kể để xác định thời điểm, với điểm gốc từ thời điểm 00:00:00 ngày 1/1/1970 (UTC).

Ví dụ lúc 00:00:00 - 1/1/2017 có giá trị timestamp là 1483228800; Có nghĩa là tính từ 00:00:00 - 1/1/1970 đến 00:00:00 - 1/1/20171483228800 giây.

Trong PHP sử dụng hàm time() để lấy timestamp hiện tại. Để đổi thời gian dạng timestamp sang các định dạng ngày tháng khác dùng hàm date()

2

Hàm time() trong PHP cung cấp cho bạn tất cả thông tin bạn cần về date và time hiện tại. Nó không yêu cầu tham số nhưng trả về một integer.

@nmvuong92
nmvuong92 / php datetime.md
Last active January 18, 2019 06:28
php xử lý datetime timestamp

Datetime Class

Tạo biến dữ liệu thời gian theo chuẩn UTC/GMT/Z bằng Datetime Class

$date1 = new DateTime('now', new DateTimeZone('utc')); //DateTime tạo đối tượng Datetime múi giờ utc chuẩn london có giá trị là hiện tại
$date2 = new DateTime('2019-01-17', new DateTimeZone('utc')); //DateTime  tạo đối tượng Datetime múi giờ utc chuẩn london có giá trị 17/01/2019 00:00:00
var_dump($date1,$date2);

kết quả

D:\www\vsmarty\crfs\demo.php:24:
@nmvuong92
nmvuong92 / index.php
Created January 17, 2019 17:15 — forked from ziadoz/index.php
Simple PHP / jQuery CSRF Protection
<?php
// See: http://blog.ircmaxell.com/2013/02/preventing-csrf-attacks.html
// Start a session (which should use cookies over HTTP only).
session_start();
// Create a new CSRF token.
if (! isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = base64_encode(openssl_random_pseudo_bytes(32));
}