Skip to content

Instantly share code, notes, and snippets.

@alanzhaonys
alanzhaonys / create-user.sh
Created June 27, 2018 14:27
Create a new user in Linux
#!/bin/bash
# Make sure only root can run this script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root (sudo)" 1>&2
exit 1
fi
if [[ $# -eq 0 ]] ; then
echo Enter a user name
@alanzhaonys
alanzhaonys / batch-cherry-pick.sh
Last active June 29, 2018 21:05
Cherry pick a commit to all other branches in a project, specify --skip-master as 2nd parameter to skip master branch. *** BE CAREFUL: *** this script assumes your branches are clean and there will be no pending merges when it's doing the `git pull` prior to cherry picking. It could fuck up your code, I take no responsibilities.
#!/bin/bash
if [[ $# -eq 0 ]] ; then
echo "Enter a commit id (run \`git log\` to see commit history)"
echo "Example: ./batch-cherry-pick.sh [commit id] --skip-master"
exit
fi
# Commmit id parameter
readonly commit=$1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]
SELECT wpp.post_title, wpp.guid, wpp.post_date,
concat('https://www.mydomain.com', REPLACE( REPLACE( REPLACE( REPLACE( wpo.option_value, '%year%', DATE_FORMAT(wpp.post_date,'%Y') ), '%monthnum%', DATE_FORMAT(wpp.post_date, '%m') ), '%day%', DATE_FORMAT(wpp.post_date, '%d') ), '%postname%', wpp.post_name )) AS permalink
FROM wp_posts wpp
JOIN wp_options wpo
ON wpo.option_name = 'permalink_structure'
WHERE wpp.post_type = 'post'
AND wpp.post_status = 'publish'
ORDER BY wpp.post_date DESC;
@alanzhaonys
alanzhaonys / gist:2bc0192b76c15c1ec721aee2ae5adc0b
Created November 29, 2018 00:36
Maintenance page redirect
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.php$
RewriteCond %{REMOTE_HOST} !^000\.000\.000\.000
RewriteRule $ /maintenance.php [R=302,L]
@alanzhaonys
alanzhaonys / gist:4f59ba9e0237c212f832d6afbd9bfaf7
Created December 5, 2018 16:05
Install NODE on Amazon Linux 2
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
sudo yum -y install nodejs
@alanzhaonys
alanzhaonys / gist:58df5a24249b80020e700bea7a3e6ee9
Created December 7, 2018 15:23
Create new DB, User and Permission
CREATE DATABASE database_name; GRANT ALL ON database_name.* TO 'database_user'@'%' IDENTIFIED BY 'database_password';
" syntax highlighting
syntax on
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=2
" when indenting with '>', use 4 spaces width
set shiftwidth=2
" On pressing tab, insert 4 spaces
set expandtab
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
//////Author Parameters - Show posts associated with certain author.
@alanzhaonys
alanzhaonys / s3-bucket-access-iam-policy.json
Created June 26, 2019 04:10
Allow S3 Bucket Access IAM Policy
{
"Version": "2012-10-17",
"Statement":[{
"Effect": "Allow",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::my_bucket",
"arn:aws:s3:::my_bucket/*"]
}
]
}