Skip to content

Instantly share code, notes, and snippets.

Hà Viết Tráng tranghaviet

Block or report user

Report or block tranghaviet

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tranghaviet
tranghaviet / postgres-cheatsheet.md
Created Oct 29, 2019 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet
View postgres-cheatsheet.md

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@tranghaviet
tranghaviet / iso-639-1-codes.php
Created Oct 24, 2019 — forked from DimazzzZ/iso-639-1-codes.php
ISO 639-1 language codes array
View iso-639-1-codes.php
<?php
$codes = [
'ab' => 'Abkhazian',
'aa' => 'Afar',
'af' => 'Afrikaans',
'ak' => 'Akan',
'sq' => 'Albanian',
'am' => 'Amharic',
'ar' => 'Arabic',
@tranghaviet
tranghaviet / Google TTS
Last active Sep 14, 2019
Englist to Vietnamese translation script (can use in GoldenDict)
View Google TTS
# Add Audio Program type to GoldenDict
bash -c "p=$(echo "%GDWORD%" |sed 's/ /+/g'); wget -q -U Mozilla -O - translate.google.com.vn/translate_tts?ie=UTF-8\&q=$p\&tl=en\&client=tw-ob | mpg123 -"
@tranghaviet
tranghaviet / convention.md
Last active Jul 12, 2019
Git Branch Naming Convention
View convention.md

#Branch Naming

Branches being created should have the following format:

<story type>/<story id>-<3-4 word story description>

#Example

chore/123-change-title

@tranghaviet
tranghaviet / placeCaretAtEnd.js
Created Jul 11, 2019
place caret at end of contenteditable element
View placeCaretAtEnd.js
function placeCaretAtEnd(el) {
el.focus()
if (typeof window.getSelection != "undefined"
&& typeof document.createRange != "undefined") {
const range = document.createRange()
range.selectNodeContents(el)
range.collapse(false)
const sel = window.getSelection()
sel.removeAllRanges()
sel.addRange(range)
@tranghaviet
tranghaviet / crypto-aes-gcm.js
Created Jun 14, 2019 — forked from chrisveness/crypto-aes-gcm.js
Uses the SubtleCrypto interface of the Web Cryptography API to encrypt and decrypt text using AES-GCM (AES Galois counter mode).
View crypto-aes-gcm.js
/**
* Encrypts plaintext using AES-GCM with supplied password, for decryption with aesGcmDecrypt().
* (c) Chris Veness MIT Licence
*
* @param {String} plaintext - Plaintext to be encrypted.
* @param {String} password - Password to use to encrypt plaintext.
* @returns {String} Encrypted ciphertext.
*
* @example
* const ciphertext = await aesGcmEncrypt('my secret text', 'pw');
@tranghaviet
tranghaviet / latlong.php
Created Dec 6, 2018 — forked from arubacao/latlong.php
Latitude Longitude Regular Expression Validation PHP
View latlong.php
<?php
/**
* Validates a given latitude $lat
*
* @param float|int|string $lat Latitude
* @return bool `true` if $lat is valid, `false` if not
*/
function validateLatitude($lat) {
return preg_match('/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/', $lat);
View deploy-pm2.md

1. Preparing the server

Install git

sudo apt install git-all

Generate Server's SSH public key

ssh-keygen -t rsa -b 4096 -C "deploy"
cat ~/.ssh/id_rsa.pub
You can’t perform that action at this time.