Skip to content

Instantly share code, notes, and snippets.

View tranghaviet's full-sized avatar

Hà Viết Tráng tranghaviet

View GitHub Profile
@tranghaviet
tranghaviet / jQuery Change Event: Proper Binding
Created September 21, 2018 02:06 — forked from brandonaaskov/jQuery Change Event: Proper Binding
jQuery's change() event doesn't work as expected with input text fields. This, however, does work.
/*
For some reason, the change() event only fires when the input field loses focus.
Binding to other options ('change keypress paste focus textInput input') will
fire the event several times, which is bad. The below code works even when
content is pasted into the text field, and only fires once as expected.
*/
$('#search-form .term').bind('input', function(){
console.log('this actually works');
});
@tranghaviet
tranghaviet / php7-fpm_xdebug_nginx.md
Created September 29, 2018 03:44 — forked from rahilwazir/php7-fpm_xdebug_nginx.md
Quick guide to setup Nginx with PHP7-FPM and XDebug

PHP7

  • Ubuntu 16.04+
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt update
$ sudo apt install nginx php7.1-fpm php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-phpdbg php7.1-mbstring php7.1-gd php7.1-imap php7.1-ldap php7.1-pgsql php7.1-pspell php7.1-recode php7.1-soap php7.1-tidy php7.1-dev php7.1-intl php7.1-curl php7.1-zip php7.1-xml php-xdebug
@tranghaviet
tranghaviet / bootstrap-4-sass-mixins-cheat-sheet.scss
Created October 4, 2018 11:35 — forked from anschaef/bootstrap-4-sass-mixins-cheat-sheet.scss
Bootstrap 4 Sass Mixins [Cheat sheet with examples]
/* -------------------------------------------------------------------------- */
// All Bootstrap 4 Sass Mixins [Cheat sheet]
// Updated to Bootstrap v4.1.x
// @author https://anschaef.de
// @see https://github.com/twbs/bootstrap/tree/v4-dev/scss/mixins
/* -------------------------------------------------------------------------- */
// Grid variables
$grid-columns: 12 !default;
$grid-gutter-width: 30px !default;
@tranghaviet
tranghaviet / deploy-pm2.md
Created November 22, 2018 16:43 — forked from hoangmirs/deploy-pm2.md
Deploy pm2 guide

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
@tranghaviet
tranghaviet / latlong.php
Created December 6, 2018 09:43 — forked from arubacao/latlong.php
Latitude Longitude Regular Expression Validation 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);
@tranghaviet
tranghaviet / README.md
Created December 20, 2018 06:25 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@tranghaviet
tranghaviet / crypto-aes-gcm.js
Created June 14, 2019 08:35 — 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).
/**
* 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 / iso-639-1-codes.php
Created October 24, 2019 23:56 — forked from DimazzzZ/iso-639-1-codes.php
ISO 639-1 language codes array
<?php
$codes = [
'ab' => 'Abkhazian',
'aa' => 'Afar',
'af' => 'Afrikaans',
'ak' => 'Akan',
'sq' => 'Albanian',
'am' => 'Amharic',
'ar' => 'Arabic',
@tranghaviet
tranghaviet / postgres-cheatsheet.md
Created October 29, 2019 04:22 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

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)