Skip to content

Instantly share code, notes, and snippets.

View huypn's full-sized avatar
🏠
Working from home

Huy Pham huypn

🏠
Working from home
View GitHub Profile
@huypn
huypn / GeoIP Block NGINX Ubuntu 20.04.md
Created October 27, 2023 07:56 — forked from dunderrrrrr/GeoIP Block NGINX Ubuntu 20.04.md
Allow or block GeoIP in Nginx on Ubuntu 20.04

GeoIP Block NGINX Ubuntu 20.04

Block or filter IPs based on location in Nginx (tested on 1.18.0) on Ubuntu 20.04.

Install Nginx modules

To make use of the geographical filtering, we must first install the Nginx GeoIP module as well as the GeoIP database containing the mappings between visitors’ IP addresses and their respective countries. To do so, let’s execute:

$ sudo apt install libnginx-mod-http-geoip geoip-database
@huypn
huypn / countries.php
Created October 31, 2018 15:40 — forked from josephilipraja/countries.php
List of Countries with Country code & Telephone (Dial) Code as a PHP Array. Bonus: PHP function to list all Countries as HTML Select Tag Options with their 2 character Country code as values
<?php
$countryArray = array(
'AD'=>array('name'=>'ANDORRA','code'=>'376'),
'AE'=>array('name'=>'UNITED ARAB EMIRATES','code'=>'971'),
'AF'=>array('name'=>'AFGHANISTAN','code'=>'93'),
'AG'=>array('name'=>'ANTIGUA AND BARBUDA','code'=>'1268'),
'AI'=>array('name'=>'ANGUILLA','code'=>'1264'),
'AL'=>array('name'=>'ALBANIA','code'=>'355'),
'AM'=>array('name'=>'ARMENIA','code'=>'374'),
'AN'=>array('name'=>'NETHERLANDS ANTILLES','code'=>'599'),
@huypn
huypn / README.md
Created April 5, 2018 18:02 — forked from jonathantneal/README.md
SASS @font-face mixin

Font Face

A mixin for writing @font-face rules in SASS.

Usage

Create a font face rule. Embedded OpenType, WOFF2, WOFF, TrueType, and SVG files are automatically sourced.

@include font-face(Samplino, fonts/Samplino);
@huypn
huypn / settings.php
Created December 12, 2017 19:46 — forked from igorbenic/settings.php
How to Create Dynamic WordPress Email Templates | http://www.ibenic.com/create-dynamic-wordpress-email-templates/
<?php
function ibenic_email_template_settings() {
// Section
add_settings_section(
'email_templates_section',
'Dynamic Email Templates',
'ibenic_email_templates_section',
'email-templates'
);
@huypn
huypn / gist:d86141edf2a5f37344f2deb06747a331
Created December 9, 2017 23:33 — forked from mikejolley/gist:2974310
WooCommerce - Set default state/country for checkout
/**
* Manipulate default state and countries
*
* As always, code goes in your theme functions.php file
*/
add_filter( 'default_checkout_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_state', 'change_default_checkout_state' );
function change_default_checkout_country() {
return 'XX'; // country code
#!/bin/bash
# Find and change text in file with "sed"
# https://unix.stackexchange.com/questions/159367/using-sed-to-find-and-replace
# http://www.thegeekstuff.com/2009/09/unix-sed-tutorial-replace-text-inside-a-file-using-substitute-command/?utm_source=sitekickr&utm_medium=snip_button
DIRS=`ls -l "." | egrep '^d' | awk '{print $9}'`
for DIR in $DIRS
do
FILE=$DIR"/wp-config.php"
sed -i -e "s/define('DB_PASSWORD',.*);/define('DB_PASSWORD', 'root');/g" $FILE
@huypn
huypn / atom-macos-context-menu.md
Created November 16, 2017 21:56 — forked from idleberg/atom-macos-context-menu.md
“Open in Atom” in macOS context-menu

Open in Atom

  • Open Automator
  • Create a new Service
  • Set “Service receives selected” to files or folders in any application
  • Add a Run Shell Script action
  • Set the script action to /usr/local/bin/atom -n $@
  • Set “Pass input” to as arguments
  • Save as Open in Atom
@huypn
huypn / sublime-text-macos-context-menu.md
Created October 30, 2017 20:28 — forked from idleberg/sublime-text-macos-context-menu.md
“Open in Sublime Text” in macOS context-menu

Open in Sublime Text

  • Open Automator
  • Create a new Service
  • Set “Service receives selected” to files or folders in any application
  • Add a Run Shell Script action
  • Set the script action to /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n $@
  • Set “Pass input” to as arguments
  • Save as Open in Sublime Text
@huypn
huypn / backup.php
Created October 28, 2017 07:51 — forked from menzerath/backup.php
PHP: Recursively Backup Files & Folders to ZIP-File
<?php
/*
* PHP: Recursively Backup Files & Folders to ZIP-File
* MIT-License - Copyright (c) 2012-2017 Marvin Menzerath
*/
// Make sure the script can handle large folders/files
ini_set('max_execution_time', 600);
ini_set('memory_limit','1024M');
@huypn
huypn / sendmail_setup.md
Created September 28, 2017 20:37 — forked from kany/sendmail_setup.md
Setup SENDMAIL on Mac OSX Yosemite