Skip to content

Instantly share code, notes, and snippets.

View antom's full-sized avatar

Andy Thomas antom

View GitHub Profile
@antom
antom / bmp-hex-str-converter.js
Created July 11, 2023 12:08
BMP Hex String Converter
/*
* Source Image: https://pixeljoint.com/pixelart/34353.htm
*
* How to source hexStr data:
* - Download image.
* - Resave as `input.bmp` in suitable bitmap editor (e.g. Aseprite) if necessary.
* - Rename to `input.txt`.
* - Open up & format with `([^ \n]{2})([^ \n]{2})( |\n)` -> `\1 \2 ` replacement regex.
* - Trim off trailing space.
* - Profit?!
@antom
antom / Craft2-S3AssetSourceType-Non-AWS-Compatibility.patch
Last active October 8, 2020 07:39
Craft CMS 2 - S3AssetSourceType: Non-AWS Compatibility
From 2be9bbc6b7996112c56c788a33907871bdc20bb1 Mon Sep 17 00:00:00 2001
From: Andy Thomas <git@andythom.as>
Date: Thu, 8 Oct 2020 08:32:33 +0100
Subject: [PATCH] S3AssetSourceType: Non-AWS Compatibility
- Add overridable default configuration for various S3 Asset Source attributes to allow compatibility with other S3-Compatible services (eg. DigitalOcean Spaces).
- Update/amend S3AssetSourceType to utilise new configuration.
- Amended S3 library class to support parsing of XML responses with a `text/xml` header.
---
src/assetsourcetypes/S3AssetSourceType.php | 72 +++++++++++++++-------
@antom
antom / uk-phone-regex.php
Created July 20, 2018 14:57
PHP to build a UK telephone Regex Pattern from known formats.
<?php
// UK telephone formats (ref: http://www.area-codes.org.uk/formatting.php#programmers)
// prefix:chunks (eg. 434 -> 4444 333 4444) - # = any 0-9 digit
$formats = array(
'1:45',
'1:46',
'11:334',
'1#1:334',
'13873:55',
@antom
antom / padleft.js
Created February 11, 2016 11:25
Javascript Left Padding
var padleft = function(value,padding,chr) {
return (Array(++padding).join(chr || '0') + value).slice(-padding);
};
@antom
antom / quote-array-values.php
Last active March 16, 2020 12:07
A quick method to quote the values of an array using implode/explode
<?php
function quote_array_values($array) {
return explode(',', sprintf(
'"%s"',
implode('","', $array)
));
}
$params = array(
'one',
@antom
antom / check-php-gd.php
Created April 23, 2015 09:57
Quick checking script to see if PHP's GD extension is enabled & what functions are available.
<?php
$gd_functions = array(
'gd_info',
'getimagesize',
'getimagesizefromstring',
'image_type_to_extension',
'image_type_to_mime_type',
'image2wbmp',
'imageaffine',
@antom
antom / reset-theme.php
Last active August 29, 2015 13:56
If you've been editing your WordPress theme in the admin area and you get the dreaded 'white screen of death' after saving, simply upload this to the root folder to select a working theme to reset to. You should then be able to access the admin ok to fix the bug in the offending theme.
<?php
define('SHORTINIT',true);
$wp_dir = getcwd();
// if WordPress isn't in the root (eg. set up for Git), do something like this:
// $wp_dir = getcwd() . '/path/to/wordpress/subdirectory';
require_once($wp_dir . '/wp-load.php');
if (isset($_GET['to'])) {
@antom
antom / str_list_ended.php
Last active June 7, 2024 11:36
Returns a string list with the final instance of $glue found substituted with $last - eg. "a, b, c, d, e" -> "a, b, c, d and e" if glue is ', ' and $last is ' and '.
function str_list_ended($value, $glue = ', ', $last = ' and ') {
return preg_replace(
"/($glue)(?!.+$glue)/",
$last,
(is_array($value) ? implode($glue, $value) : $value)
);
}