Skip to content

Instantly share code, notes, and snippets.

View phamquocbuu's full-sized avatar
💻

Buu Pham phamquocbuu

💻
View GitHub Profile
@phamquocbuu
phamquocbuu / import.sh
Created August 14, 2018 08:41
GUnzip and import latest database file
find /PATH/ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2 | tail -n 1 | xargs gunzip ;
find /PATH/ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2 | tail -n 1 | perl -pe 'chomp' | xargs cat | mysql -u DB_USER DB_NAME ;
@phamquocbuu
phamquocbuu / import.sh
Created August 14, 2018 08:41
GUnzip and import latest database file
find /PATH/ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2 | tail -n 1 | xargs gunzip ;
find /PATH/ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2 | tail -n 1 | perl -pe 'chomp' | xargs cat | mysql -u DB_USER DB_NAME ;
@phamquocbuu
phamquocbuu / apache-badbots.conf
Last active August 14, 2018 06:39
Protect WordPress wp-login with nginx HTTP Auth + fail2ban - NGINX Proxy Access.log
[Definition]
badbotscustom = EmailCollector|WebEMailExtrac|TrackBack/1\.02|sogou music spider
badbots = atSpider/1\.0|autoemailspider|China Local Browse 2\.6|ContentSmartz|DataCha0s/2\.0|DBrowse 1\.4b|DBrowse 1\.4d|Demo Bot DOT 16b|Demo Bot Z 16b|DSurf15a 01|DSurf15a 71|DSurf15a 81|DSurf15a VA|EBrowse 1\.4b|Educate Search VxB|EmailSiphon|EmailWolf 1\.00|ESurf15a 15|ExtractorPro|Franklin Locator 1\.8|FSurf15a 01|Full Web Bot 0416B|Full Web Bot 0516B|Full Web Bot 2816B|Industry Program 1\.0\.x|ISC Systems iRc Search 2\.1|IUPUI Research Bot v 1\.9a|LARBIN-EXPERIMENTAL \(efp@gmx\.net\)|LetsCrawl\.com/1\.0 +http\://letscrawl\.com/|Lincoln State Web Browser|LWP\:\:Simple/5\.803|Mac Finder 1\.0\.xx|MFC Foundation Class Library 4\.0|Microsoft URL Control - 6\.00\.8xxx|Missauga Locate 1\.0\.0|Missigua Locator 1\.9|Missouri College Browse|Mizzu Labs 2\.2|Mo College 1\.9|Mozilla/2\.0 \(compatible; NEWT ActiveX; Win32\)|Mozilla/3\.0 \(compatible; Indy Library\)|Mozilla/4\.0 \(compatible; Advanced Email Extractor v2\.xx\
@phamquocbuu
phamquocbuu / count.sh
Created August 14, 2018 04:51
Recursively counting files in a Linux directory
find DIR_NAME -type f | wc -l
@phamquocbuu
phamquocbuu / vary.MD
Created August 14, 2018 03:47
How the Vary HTTP Header Can Be Bad - https://www.siteground.com/blog/vary-http-header/

Vary: User-Agent

Let’s take a look how the most commonly used value, User-Agent, works. It tells our Dynamic caching: “Hey, you should store different caches for different OS and browsers”. This is done in order to avoid serving a cached desktop version to a mobile visitor for example. Note, however, that nowadays most of the sites don’t actually serve different HTML for their mobile versions. It’s the responsive CSS that does all the heavy lifting and shows your site in a different way on mobile and on desktop. So, unless you’re using a plugin like WP Touch for example, or you know for sure you have a difference in the HTML output of your site, based on visitors browsers, your site should not be sending the Vary: User-Agent header.

@phamquocbuu
phamquocbuu / crontab
Created August 10, 2018 08:00
add current date time to cron job command
0 * * * * cp /etc/nginx/nginx.conf "/backup/nginx/config/nginx.`date +\%Y-\%m-\%d_\%H-\%M`.conf"
@phamquocbuu
phamquocbuu / BOM.char.php
Created August 3, 2018 07:34
PHP-CSV - add BOM to fix UTF-8 in Excel
<?php
fputs($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
@phamquocbuu
phamquocbuu / stress.php
Last active August 14, 2018 04:46
stress test by PHP ZTS with Thread - https://github.com/Shimmi/docker-php
<?php
class ChildThread extends Thread {
function test() {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "443",
CURLOPT_URL => "https://IP:443/",
@phamquocbuu
phamquocbuu / nginx.conf
Created January 11, 2018 04:32
NGINX Proxy with Geo module
# https://serverfault.com/questions/545441/nginx-geo-location-module-configuration-using-geo-database
# http://nginx.org/en/docs/http/ngx_http_geo_module.html#directives
# https://www.howtoforge.com/nginx-how-to-block-visitors-by-country-with-the-geoip-module-debian-ubuntu
# https://dev.maxmind.com/geoip/legacy/geolite/
geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $backend {
default US;
US US;
CN DE;
@phamquocbuu
phamquocbuu / country-code-3-letters.php
Created January 8, 2018 02:33
Complete List Of Country - uses 3-letter codes
<?php
$code = [
[ 'name' => 'Afghanistan', 'code' => 'AFG'],
[ 'name' => 'Albania', 'code' => 'ALB'],
[ 'name' => 'Algeria', 'code' => 'DZA'],
[ 'name' => 'American Samoa', 'code' => 'AS'],
[ 'name' => 'Andorra', 'code' => 'AND'],
[ 'name' => 'Angola', 'code' => 'AGO'],
[ 'name' => 'Anguilla', 'code' => 'AI'],
[ 'name' => 'Antarctica', 'code' => 'ATA'],