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 December 3, 2017 20:23
PHP Autoload Class
<?php
spl_autoload_register(function ($class) {
include_once 'core' . DS . strtolower($class) . '.php';
});
@tieutantan
tieutantan / .htaccess
Created December 3, 2017 20:33
Htaccess remove extension ".php"
RewriteEngine on
RewriteRule ^(.+)\.php$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,END]
@tieutantan
tieutantan / file.php
Last active September 2, 2018 15:03
PHP CURL example
<?php
$url = 'https://api.ipify.org/?format=json';
$ip = '129.146.70.253:80';
$request = curl_init();
curl_setopt_array($request, [
CURLOPT_URL => $url,
CURLOPT_PROXY => $ip,
@tieutantan
tieutantan / file.php
Last active July 3, 2018 03:06
Function get content for package "paquettg/php-html-parser"
<?php
/* https://github.com/paquettg/php-html-parser */
public static function get_content(string $html_identity, string $needed_attribute, $source_html)
{
$dom = new \PHPHtmlParser\Dom;
$dom->load($source_html);
$array_content = [];
foreach ($dom->find($html_identity) as $content)
@tieutantan
tieutantan / file.php
Last active January 31, 2019 10:32
Caesar Cipher Encryption in PHP
<?php
// test case in https://www.hackerrank.com/challenges/linkedin-practice-caesar-cipher/problem
$input = 'DNFjxo?b5h*5<LWbgs6?V5{3M].1hG)pv1VWq4(!][DZ3G)riSJ.CmUj9]7Gzl?VyeJ2dIPEW4GYW*scT8(vhu9wCr]q!7eyaoy.';
$step = 45;
foreach (range('a', 'z') as $value)
{
@tieutantan
tieutantan / file.html
Created May 1, 2018 22:52
flipboard.com index html
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1">
<meta name="version" content="67d4b4487791dd9ee647028f7e531028b68abe9e">
<meta name="fragment" content="!">
<meta name="referrer" content="origin">
<title>Flipboard: News for our time</title>
@tieutantan
tieutantan / .htaccess
Last active May 26, 2018 13:00
Block direct access .env file in Laravel
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
@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();
@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 / 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);