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.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 / 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 / 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.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 / 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 / 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 / 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 / check.php
Last active February 10, 2019 15:04
Check proxy simple by PHP
<?php
$ip = '77.37.130.187:38578';
$url = 'https://api.ipify.org'; // https://api.ipify.org/?format=json
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $ip);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@tieutantan
tieutantan / 2018_08_08_000000_create_users_table.php
Created May 29, 2018 03:00
Assigned created_at, updated_at on create table in Laravel
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
@tieutantan
tieutantan / file.php
Created May 26, 2018 19:58
Simple Pagination
<?php
$limit = config('custom.config.appPerPage');
$offset = ($page > 1) ? (($page - 1) * $limit) : 0;
$apps = App::where('publish', 1)->orderBy('updated_at', 'desc')->take($limit)->skip($offset)->get();