Skip to content

Instantly share code, notes, and snippets.


Andrew Collington amnuts

View GitHub Profile
amnuts / propSearch.js
Created Oct 6, 2020
Helpers to see if object has all props or any of the props
View propSearch.js
const hasAllProps = function(list, within) {
list.forEach(function(e) {
if (!within.hasOwnProperty(e) || within[e] == "") {
return false;
return true;
const hasAnyProps = function(list, within) {
amnuts / ofilter.php
Last active Sep 30, 2020
Filter an array of objects based on property, or multiple property values
View ofilter.php
* Filter an array of objects.
* You can pass in one or more properties on which to filter.
* If the key of an array is an array, then it will filtered down to that
* level of node.
amnuts / phpstorm.bat
Last active Aug 20, 2020
Add context menu to Windows 7 to open file/folder in PhpStorm
View phpstorm.bat
@echo off
SET PhpStormPath=C:\Program Files (x86)\JetBrains\PhpStorm 8.0.2\bin\PhpStorm64.exe
echo Adding file entries
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PhpStorm" /t REG_SZ /v "" /d "Open in PhpStorm" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PhpStorm" /t REG_EXPAND_SZ /v "Icon" /d "%PhpStormPath%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PhpStorm\command" /t REG_SZ /v "" /d "%PhpStormPath% \"%%1\"" /f
echo Adding folder entries
amnuts / osort.php
Last active Jun 8, 2020
Sort array of objects by one or more properties of the object.
View osort.php
* Sort an array of objects.
* Requires PHP 5.3+ to be installed.
* Will use the Intl extension to normalize characters if it's
* available.
amnuts / speechSynthesis.html
Last active Mar 13, 2020
Add a link to read text aloud including the option of swapping to any available voices.
View speechSynthesis.html
<!doctype html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
amnuts / directory-reflection.php
Created Jan 6, 2020
Using Better Reflection to get details on classes in multiple directories
View directory-reflection.php
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflector\ClassReflector;
use Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator;
require __DIR__ . '/vendor/autoload.php';
$refSubscriptions = [];
amnuts / merge_urls.php
Last active Dec 9, 2019
Merge two urls using PHP
View merge_urls.php
* Combine two urls.
* The urls can be either a string or url parts that consist of:
* scheme, host, port, user, pass, path, query, fragment
* If passed in as parts in an array, the query parameter can be either
amnuts / datetime.php
Created Jun 4, 2019
PHP date/time conversion example
View datetime.php
foreach (range(1, 12) as $m) {
$elStart = new \DateTimeImmutable("2019-{$m}-10 23:50:00", new \DateTimeZone('Europe/London'));
$elEnd = $elStart->add(new \DateInterval('PT5H'));
$utcStart = $elStart->setTimezone(new \DateTimeZone('UTC'));
$utcEnd = $elEnd->setTimezone(new \DateTimeZone('UTC'));
printf("E/L: %s / %s, UTC: %s / %s\n",
amnuts / stuff.php
Last active Mar 22, 2019
jotting down functions
View stuff.php
// Return greatest common divider of two numbers
function gcd($a, $b) {
return $b ? gcd($b, $a % $b) : $a;
// Returns the least common multiple of two or more numbers.
function lcm(...$numbers): int
amnuts / timer.php
Last active Oct 26, 2018
Simple PHP timer class
View timer.php
* Utility class to enable very simplistic timing.
* Usage example:
* $t = new Timer();
* // do something here
* echo $t;
You can’t perform that action at this time.