Skip to content

Instantly share code, notes, and snippets.

@wpsmith
wpsmith / browser-language-codes.js
Last active March 19, 2024 06:50
JS: Object of Browser Language Codes
// <![CDATA[
var langCodes = {
"af": "Afrikaans",
"sq": "Albanian",
"an": "Aragonese",
"ar": "Arabic (Standard)",
"ar-dz": "Arabic (Algeria)",
"ar-bh": "Arabic (Bahrain)",
"ar-eg": "Arabic (Egypt)",
"ar-iq": "Arabic (Iraq)",
@wpsmith
wpsmith / Microsoft.PowerShell_profile.ps1
Created July 15, 2015 13:17
PowerShell: Profile to always launch PS as Administrator, set Aliases (ex. Notepad++), Import SharePoint Online, Azure AD, and Azure Services.
# Check if Running as Admin
$IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (-not $IsAdmin)
{
if ($MyInvocation.ScriptName -ne "")
{
try
{
Write-Host "Relanuching Script as Admin"
@wpsmith
wpsmith / adobe-licenses.vbs
Last active January 18, 2024 03:45
VBS: Get All Adobe License Keys
'Modified by Travis Smith (wpsmith.net) to fetch all Adobe licenses.
'Written by Ryan Williams (ryan@ryadical.com), I am not a programmer so please excuse the messy code
'Now to give credit where credit is due:
'Cipher code converted from Sam Gleske's javascript found at: http://www.pages.drexel.edu/~sag47/adobe/
'His code was Converted from the source for "Enchanted Keyfinder"
'original algorithm by Dave Hope (http://www.davehope.co.uk)
'To run this program make sure that sqlite3.exe is in the same folder as this vbs file.
'SQLITE3 source and binaries can be found at www.sqlite.org
@wpsmith
wpsmith / sanitize_phone.php
Created June 5, 2014 17:00
PHP: Sanitize & Format US Phone Numbers
<?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 / Get-AvailableExceptionsList.ps1
Created April 16, 2015 14:09
PowerShell: Retrieves all available Exceptions to construct ErrorRecord objects.
<#
.Synopsis
Retrieves all available Exceptions to construct ErrorRecord objects.
.Description
Retrieves all available Exceptions in the current session to construct ErrorRecord objects.
.Example
$availableExceptions = Get-AvailableExceptionsList
@wpsmith
wpsmith / New-ErrorRecord.ps1
Created April 16, 2015 14:16
PowerShell: Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
<#
.Synopsis
Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
.Description
Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
.Parameter Exception
The Exception that will be associated with the ErrorRecord.
@wpsmith
wpsmith / Repair-SPDistributedCache.ps1
Last active May 17, 2023 08:53
PowerShell: Repair SharePoint Distributed Cache Service Instance
<#
.Synopsis
Repairs the Distributed Cache on a Server.
.Description
Repairs the Distributed Cache on a Server by removing the current Distributed Cache Service instance.
.Parameter Server ("ServerName")
The Server running Distributed Cache Service
Type: String
@wpsmith
wpsmith / WPS_Extend_Plugin.php
Last active May 1, 2023 18:24
PHP: WPS_Extend_Plugin Class designed to declare a plugin dependency and used for extending a plugin.
<?php
/**
* Contains WPS_Extend_Plugin class. and wps_extend_plugins function.
*
* @package WPS_Core
* @author Travis Smith <t@wpsmith.net>
* @copyright 2015 WP Smith, Travis Smith
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @version 1.0.0
* @since File available since Release 1.0.0
@wpsmith
wpsmith / uninstall-terms-taxonomy-1.php
Last active April 21, 2023 13:15
PHP: How to delete terms and taxonomies in uninstall.php
<?php
/** Delete All the Taxonomies */
foreach ( array( 'my_first_custom_tax', 'my_second_custom_tax', 'my_third_custom_tax', ) as $taxonomy ) {
// Prepare & excecute SQL, Delete Terms
$wpdb->get_results( $wpdb->prepare( "DELETE t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('%s')", $taxonomy ) );
// Delete Taxonomy
$wpdb->delete( $wpdb->term_taxonomy, array( 'taxonomy' => $taxonomy ), array( '%s' ) );
}
@wpsmith
wpsmith / gist:6067068
Created July 23, 2013 23:39
RegEx: Notepad++ Append & Prepend to each line
Press CTRL-H to bring up the Find/Replace Dialog. Choose the "Regular expressions" checkbox near the bottom of the dialog.
To add "test" to the beginning of each line, type "^" in the "Find what" field, and "test" in the "Replace with" field. Then hit "Replace All".
To add "test" to the end of each line, type "$" in the "Find what" field, and "test" in the "Replace with" field. Then hit "Replace All".