Skip to content

Instantly share code, notes, and snippets.

View ngohuytrieu's full-sized avatar
👨‍🍳
Coding is cooking

TRIEU NGO HUY ngohuytrieu

👨‍🍳
Coding is cooking
View GitHub Profile
@ngohuytrieu
ngohuytrieu / aws.md
Created January 19, 2024 02:35
Create AWS EC2, SSH to EC2, add domain and setup SSL for domain

Create EC2 instance

Go to https://console.aws.amazon.com/ec2 Click on Launch Instance button to add new EC2 Launch instanece button

Step 1: Choose an Amazon Machine Image (AMI)

Choose the OS type you want then click Select OS type

Step 2: Choose an Instance Type

@ngohuytrieu
ngohuytrieu / aws-s3-bucket-policy-configuration.md
Last active August 27, 2023 09:56
AWS S3 bucket policy configuration

1. Public access, allow all users, single action

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
@ngohuytrieu
ngohuytrieu / recover-deleted-branch.sh
Created June 7, 2023 10:06 — forked from umayr/recover-deleted-branch.sh
How to recover a deleted branch
## Pre-requisite: You have to know your last commit message from your deleted branch.
git reflog
# Search for message in the list
# a901eda HEAD@{18}: commit: <last commit message>
# Now you have two options, either checkout revision or HEAD
git checkout a901eda
# Or
git checkout HEAD@{18}
@ngohuytrieu
ngohuytrieu / curl.php
Created March 2, 2023 03:18
PHP curl get headers
<?php
$url = "https://www.google.com/";
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $url);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_HEADER, 1); // must set this line
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curlObj);

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@ngohuytrieu
ngohuytrieu / moment-js-timezones.txt
Created May 16, 2022 15:10 — forked from diogocapela/moment-js-timezones.txt
List of All Moment.js Timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
@ngohuytrieu
ngohuytrieu / script.js
Last active April 9, 2022 08:57
Run async/await in javascript event functions
const data = []
// using promise.all
const data = await Promise.all(data.map(async (item, index) => {
// call async function here
item.products = await asyncawaitfunction()
return item
}));
@ngohuytrieu
ngohuytrieu / ssh-config
Last active May 5, 2022 10:15
VSCODE connect to remote server with pem file
#.ssh/config
Host domain.com
HostName [ip_addres]
User username
IdentityFile /path/to/pem/file/file.pem
@ngohuytrieu
ngohuytrieu / Ubuntu show branch name in terminal.md
Last active April 4, 2022 10:23
Ubuntu show branch name in terminal

Ubuntu show branch name in terminal

Add these lines in your ~/.bashrc file

sudo nano ~/.bashrc
# Show git branch name
force_color_prompt=yes
color_prompt=yes
@ngohuytrieu
ngohuytrieu / macOS-install-php7.2.md
Last active March 3, 2022 10:11
macOS install php@7.2

macOS install php@7.2

Since PHP 7.2 is not supported anymore, it's got delisted from the Hombrew core repository.

You've to find a third-party repository that still contains an older PHP version, such as the shivammathur/php repository.

You need to tap the repository like this in your Homebrew:

brew tap shivammathur/php