Skip to content

Instantly share code, notes, and snippets.

View tieutantan's full-sized avatar
🍉
Focusing

Tran Ngoc Tan tieutantan

🍉
Focusing
View GitHub Profile
@tieutantan
tieutantan / file.html
Last active March 14, 2019 00:30
JS - convert Title to Slug
<script>
// title to slug
function title_to_slug(title_id, slug_id)
{
string = document.getElementById(title_id).value;
string = string.toString().trim().toLowerCase()
.replace(/\s+/g, "-")
.replace(/[^\w\-]+/g, "")
.replace(/[0-9]/g, "")
.replace(/-that|-keyword|-need|-to|-remove|-from|-slug/gi, "")
@tieutantan
tieutantan / httpd-vhosts.conf
Last active August 11, 2018 15:06
httpd-vhosts.conf of XAMPP on Ubuntu 16.04
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/domain.cn/public"
ServerName domain.cn
ErrorLog "logs/domain.cn-error_log"
CustomLog "logs/domain.cn-access_log" common
<Directory /opt/lampp/htdocs/domain.cn/public>
Options Indexes FollowSymLinks
Require all granted
@tieutantan
tieutantan / data.xml
Created August 14, 2018 16:43
Sample Data for Wordpress
This file has been truncated, but you can view the full file.
<?xml version="1.0" encoding="UTF-8" ?>
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your site. -->
<!-- To import this information into a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Go to Tools: Import in the WordPress admin panel. -->
<!-- 3. Install the "WordPress" importer from the list. -->
@tieutantan
tieutantan / file.sh
Last active September 2, 2018 18:26
Internet Speed Test for Linux
wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
chmod +x speedtest.py
python speedtest.py --server=3172 --bytes && python speedtest.py --server=15711 --bytes && python speedtest.py --server=18250 --bytes && python speedtest.py --server=15711 --bytes && python speedtest.py --server=12329 --bytes && python speedtest.py --server=15711 --bytes && python speedtest.py --server=11214 --bytes && python speedtest.py --server=15711 --bytes && python speedtest.py --server=11701 --bytes && python speedtest.py --server=15711 --bytes && python speedtest.py --server=12037 --bytes
@tieutantan
tieutantan / Magento2.md
Created September 12, 2018 10:41 — forked from JeansBolong/Magento2.md
Magento2 CheatSheet

Magento 2 tutorial

http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/bk-frontend-dev-guide.html
https://www.creare.co.uk/blog/magento/theming-in-magento-2-part-1
https://www.creare.co.uk/blog/magento/theming-in-magento-2-part-2
http://alanstorm.com/category/magento-2/

I have installed Magento 2 successfully, but icons are not displaying and not able to click anywhere in backend.

Please try running following command.

@tieutantan
tieutantan / file.php
Last active September 29, 2018 15:37
PHP Regex patterns
<?php
// Remove attributes of HTML tag
$data = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i",'<$1$2>', $data);
// Remove empty HTML tag
$data = preg_replace('#<([^ >]+)[^>]*>([[:space:]]|&nbsp;)*</\1>#', '', $data);
// Remove non unicode character
$data = preg_replace('/[^\00-\255]+/u', '', $data);
@tieutantan
tieutantan / file.php
Created September 29, 2018 15:26
PHP custom exceptions for catch "Notice" errors
<?php // https://stackoverflow.com/a/5373824
set_error_handler('exceptions_error_handler');
function exceptions_error_handler($severity, $message, $filename, $lineno) {
if (error_reporting() == 0) {
return;
}
if (error_reporting() & $severity) {
throw new ErrorException($message, 0, $severity, $filename, $lineno);
}
@tieutantan
tieutantan / sources.list
Last active September 30, 2018 07:21
Ubuntu 18.04 Bionic default /etc/apt/sources.list with server best of speed to VN
#deb cdrom:[Ubuntu 18.04 LTS _Bionic Beaver_ - Release amd64 (20180426)]/ bionic main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.bangmod.cloud/ubuntu/ bionic main restricted
# deb-src http://mirrors.bangmod.cloud/ubuntu/ bionic main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.bangmod.cloud/ubuntu/ bionic-updates main restricted
@tieutantan
tieutantan / file.php
Last active October 4, 2018 04:40
PHP time manipulation
<?php
// counter 2018-09-23 10:01:27 to days old
function days_old($time)
{
$date = strtotime($time); # Converted to a PHP date (a second count)
$diff = $date - time(); # time returns current time in seconds
$days = floor($diff / (60 * 60 * 24)); # seconds/minute*minutes/hour*hours/day)
return abs($days); // number of days old
}
@tieutantan
tieutantan / backup.sh
Created October 10, 2018 03:58
Shell Script Backup Mysql Database
#!/bin/sh
DUMPFILE=/home/thisisusername/backups/db-`date +%Y-%m-%d-%H-%M`.sql.gz
mysqldump -uthisisusername -p'ZjOGUxPass' -hlocalhost database_name --force --triggers --single-transaction --opt --skip-lock-tables | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | gzip -9 -c > $DUMPFILE