Skip to content

Instantly share code, notes, and snippets.

@alanzhaonys
alanzhaonys / s3-bucket-access-iam-policy.json
Last active April 7, 2020 18:24
Allow S3 Bucket Access IAM Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::www.damin.com/*"
}
@alanzhaonys
alanzhaonys / gist:bed46b6cb70e6edb01e96daa976339fc
Last active July 22, 2020 14:40
WordPress Hardening via .htaccess
# Block the include-only files.
# https://wordpress.org/support/article/hardening-wordpress/#securing-wp-includes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
@alanzhaonys
alanzhaonys / gist:bd6621dcdc110aeaf03b5e89278049e6
Created February 14, 2020 15:12
WordPress Frontend Compression and Caching via .htaccess
# Start compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
@alanzhaonys
alanzhaonys / gist:b69cf996ae6cdbfbd386a745da2b3bd6
Last active October 30, 2020 21:14
WordPress Admin Bar, Dashboard, head and footer Clean Up
<?php
//
//
// Below is the code that cleans up dashboard and admin bar
//
//
//
// Remove admin bar from frontend
@alanzhaonys
alanzhaonys / gist:d42d3925e947fc8f9cfc4cc9c8fd6a44
Last active January 8, 2021 20:53
MySQL remote access on Centos 8 and Httpd
1. Setup user
2. Add binding_address = 0.0.0.0 to my.cnf
3. Open up firewall below
# https://wiki.mikejung.biz/Firewalld
# Allow traffic to MySQL
yum install @mysql
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
@alanzhaonys
alanzhaonys / gist:1f13a45415bb75e1a741f68da0dc4e72
Last active March 5, 2020 17:06
Centos 8 Own Cloud Installation
https://download.owncloud.org/download/repositories/production/owncloud/
CentOS_8 owncloud-files-10.4.0-1
Run the following shell commands as root to trust the repository.
rpm --import https://download.owncloud.org/download/repositories/production/CentOS_8/repodata/repomd.xml.key
Run the following shell commands as root to add the repository and install from there. You either need 'dnf upgrade' or 'dnf install' depending on whether you already have an older version installed or not.
dnf config-manager --add-repo http://download.owncloud.org/download/repositories/production/CentOS_8/ce:stable.repo
dnf clean all
@alanzhaonys
alanzhaonys / gist:19c965a453554eccaa827ec431e9075b
Last active November 30, 2020 14:30
PHP and Salesforce Integration
<?php
$request = [
'ws_key' => 'SMNXAgMDEA6GyPnYmMheW86AMLfKvqFTDGZR3dsTdcp41o',
];
$sfmc_ws = new SFMCWebService($request, true);
/**
* SFMC web services.
# Enable EPEL
yum -y install epel-release
yum install mosquitto
systemctl enable mosquitto
systemctl start mosquitto
# Generate password
mosquitto_passwd -c /etc/mosquitto/passwd sammy

Today I connected my USB host board (see "hardware" section below) to my Wemos 1D device. It receives data from an outdoor "weather station receiver" and prints in to serial console in Arduino IDE.

Hardware:

Arduino libraries:

@alanzhaonys
alanzhaonys / gist:aa749751885e1639c998dffaa5659355
Last active September 8, 2021 15:35
Create a new AWS Account
1. Gmail account
2. Create AWS account
3. Create nac.fpmstaging.com NS records on the subaccount
3. Add NS records to the main account under nac.fpmstaging.com
4. Create a SSL cert for nac.fpmstaging.com
5. Create an IAM role `lambda-execute-role-cloudfront-basic-auth`
AWSLambdaExecute permission
Role need to have TrustedPolicy below(under Trust Relationships tab)