Skip to content

Instantly share code, notes, and snippets.

View theodorejb's full-sized avatar

Theodore Brown theodorejb

View GitHub Profile
@theodorejb
theodorejb / deploy.ps1
Created January 1, 2023 16:04
A zero-downtime IIS site deploy script
param(
[string] $server
)
$ErrorActionPreference = "Stop"
$sitePathArr = Invoke-Command -ComputerName $server -ScriptBlock {
(Get-Website mySite).PhysicalPath.Split("\")
}
$currentPath = $sitePathArr[0..($sitePathArr.count - 2)] -join "\"
@theodorejb
theodorejb / attribute_syntax_discussion.md
Last active August 14, 2020 20:34
Attribute syntax discussion

Discussion

Is the lack of an ending symbol inconsistent?

It is true that statements and declarations in PHP generally have an ending symbol. However, attributes are not a standalone statement or declaration, but rather modifiers on a declaration. They do not stand alone, but are always followed by a declaration with which the metadata is associated. This is similar to the public and static keywords that modify a method, or a type declaration that modifies a

@theodorejb
theodorejb / results.txt
Created October 8, 2019 03:12
Analysis of backtick usage in top PHP packages
Analysis of https://gist.github.com/nikic/7b0afaf4d8b1a1087cdb61cd1e776594
18 namespaces with backtick uses
22 packages with backtick uses
Total uses in top 2K packages: 72
19 projects have 5 or fewer usages
14 projects only have 1 or 2 usages
array (
'james-heinrich/getid3' => 14,
@theodorejb
theodorejb / convert_array_access_braces.php
Last active March 27, 2024 18:22
Migrate deprecated curly brace array access syntax to bracket syntax. Requires PHP 7.4.
<?php
error_reporting(E_ALL);
$opts = getopt('f:d:rb:', ['ext:', 'php:', 'diff::']);
if ((int)isset($opts['d']) + (int)isset($opts['f']) !== 1) {
$self = basename(__FILE__);
echo <<<EOF
Usage:
php $self -f<php_script> [-b] [--php <path_to_php>] [ --diff [<file>]]
@theodorejb
theodorejb / parse-log.php
Last active July 5, 2019 01:03
Analysis of curly brace array syntax usage in top PHP packages
<?php
// parse the output of https://gist.github.com/nikic/b5f811e0423bf051f4492cd6e0c0273e
$contents = file('alternative_array_syntax_usage.txt');
$match = '/home/nikic/package-analysis/sources/';
$matchLen = strlen($match);
$parseErrorMatch = 'Parse error:';
$parseErrorLen = strlen($parseErrorMatch);
@theodorejb
theodorejb / fnNaturalSort.sql
Last active September 25, 2023 02:04
SQL Server natural sort function
-- =================================================
-- Author: Theodore Brown
-- Create date: 2016-12-02
-- Description: Sort alphanumeric strings naturally!
-- =================================================
CREATE FUNCTION [dbo].[fnNaturalSort]
(
@string nvarchar(255)
)
RETURNS nvarchar(264)