Skip to content

Instantly share code, notes, and snippets.

Travis Smith wpsmith

Block or report user

Report or block wpsmith

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wpsmith
wpsmith / sanitize_phone.php
Created Jun 5, 2014
PHP: Sanitize & Format US Phone Numbers
View sanitize_phone.php
<?php
function sanitize_phone( $phone, $international = false ) {
$format = "/(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/";
$alt_format = '/^(\+\s*)?((0{0,2}1{1,3}[^\d]+)?\(?\s*([2-9][0-9]{2})\s*[^\d]?\s*([2-9][0-9]{2})\s*[^\d]?\s*([\d]{4})){1}(\s*([[:alpha:]#][^\d]*\d.*))?$/';
// Trim & Clean extension
$phone = trim( $phone );
$phone = preg_replace( '/\s+(#|x|ext(ension)?)\.?:?\s*(\d+)/', ' ext \3', $phone );
@wpsmith
wpsmith / browser-language-codes.js
Created Nov 22, 2013
JS: Object of Browser Language Codes
View browser-language-codes.js
// <![CDATA[
var langCodes = {
"af": "Afrikaans",
"sq": "Albanian",
"ar": "Arabic (Standard)",
"ar-dz": "Arabic (Algeria)",
"ar-bh": "Arabic (Bahrain)",
"ar-eg": "Arabic (Egypt)",
"ar-iq": "Arabic (Iraq)",
"ar-jo": "Arabic (Jordan)",
@wpsmith
wpsmith / Set-SQLAutoGrouth.ps1
Created May 19, 2015
PowerShell: Set AutoGrowth for SQL Server cycling through the individual filegroups as well as excluding system databases.
View Set-SQLAutoGrouth.ps1
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
$server = New-Object ("Microsoft.SqlServer.Management.Smo.Server") "localhost"
$databases = $server.Databases;
foreach ($db in $databases ) {
#Set Log File growth
if ($db.Status -eq 'Normal' -and -$db.IsSystemObject -eq $false) {
$l = $db.LogFiles[0]
$l.GrowthType = "KB"
$l.Growth = "51200"
$l.Alter();
@wpsmith
wpsmith / Enable-BlobCache.ps1
Created Jan 29, 2015
PowerShell: Enable Blob Cache for SharePoint
View Enable-BlobCache.ps1
<#
.SYNOPSIS
Enables and configures the SharePoint BLOB Cache.
.LINK
http://blog.kuppens-switsers.net/sharepoint/enabling-blob-cache-sharepoint-using-powershell/
.DESCRIPTION
Enables and configures the SharePoint BLOB Cache.
@wpsmith
wpsmith / 01-setup-aws-server.sh
Last active Dec 10, 2019
Bash Shell: Sets up an AWS Linux 2 Server for WordPress using NGINX.
View 01-setup-aws-server.sh
#!/bin/bash
##############################################################
# Set Your System and Wordpress Config Preferences
##############################################################
export SYSTEM_USER=nginx # User PHP-FPM runs under
export SYSTEM_GROUP=www # User PHP-FPM runs under
##########################
View bucket_policy.json
{
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket_name_here/*"
View New-SPApplicationPool.ps1
asnp *SharePoint* -ErrorAction SilentlyContinue
// URL of the Web App to change the Application Pool of.
$WebAppURL = "http://WebApp"
// name of the name Application Pool that will be created.
$NewAppPoolName = "NewAppPool"
//the user account that the Application Pool will run under the context of.
$NewAppPoolUserName = "contoso\apppool"
View installgo-aws.sh
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
sudo yum update -y
sudo yum install git curl make bison gcc glibc-devel -y
# Install GVM
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
source /home/ec2-user/.gvm/scripts/gvm
# Add to ~/.bash_profile
echo 'source /home/ec2-user/.gvm/scripts/gvm' >>~/.bash_profile
View gist:371367e512d2dac8671d6391320cb178
JnS printStringName
Halt
Print, HEX 2 /Address of string
PrintString, LoadI myName /Start of subroutine
Skipcond 800 /If AC is greater than 0 then skip next instruction
JumpI Print /Jump to the address stored in Print
Output
Clear
@wpsmith
wpsmith / mu-admin-user.php
Created Sep 8, 2019
PHP: Create/Add admin user
View mu-admin-user.php
<?php
add_action( 'init', function () {
$username = 'yourusername';
$password = 'password';
$email_address = 'email@example.com';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
You can’t perform that action at this time.