Skip to content

Instantly share code, notes, and snippets.

Andrew Collington amnuts

Block or report user

Report or block amnuts

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
amnuts / phpstorm.bat
Last active Jul 19, 2019
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 / 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 / ofilter.php
Last active Jun 1, 2019
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 / 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;
amnuts / osort.php
Last active Jul 24, 2018
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 / phprc
Last active May 10, 2018
Dreamhost PHP 5.6 phprc file
View phprc
date.timezone = "Europe/London"
expose_php = 0
extension =
extension =
extension =
suhosin.executor.include.whitelist = phar
amnuts / limit-textarea.js
Created Sep 18, 2017
Show word or character count on text boxes/areas that have data-max-length="<number>" and data-max-type="(character|word)" attributes.
View limit-textarea.js
<script type="text/javascript">
function wordCount(str, charlist) {
var len = str.length, cl = charlist && charlist.length,
chr = '', tmpStr = '', i = 0, c = '', wC = 0, reg = '', match = false;
var _preg_quote = function(str) {
return (str + '').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!<>\|\:])/g, '\\$1');
var _getWholeChar = function(str, i) {
var code = str.charCodeAt(i);
amnuts / sort.js
Created Jun 14, 2017
Sort js hash, retaining key association
View sort.js
// From:
// The unsorted data
let data = {
a: 'A',
c: 'C',
b: 'B'
// Create it sorted
amnuts / gist:d366e76122f1ad32052d8b82dd2d516c
Created Apr 6, 2017
Convert lots of h264 files to mp4 from command line on rpi
View gist:d366e76122f1ad32052d8b82dd2d516c
# first make sure MP4Box is install
sudo apt-get install gpac
# then run this from the command line
for i in *.h264; do MP4Box -add $i ${i%.*}.mp4; done
You can’t perform that action at this time.