Skip to content

Instantly share code, notes, and snippets.

@ajaypayne
ajaypayne / quick postcode
Created February 20, 2024 15:04
validates format for non-bfpo postcodes
^(gir 0aa|[a-z](\d[a-z]?|[a-hj-z]\d{1,2})\s\d[a-z]{2})$
@ajaypayne
ajaypayne / dateMe
Created March 12, 2019 16:04
Add time and date to top corner of a terminal
while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &
for (var a = 0; a < 1000; a++) {
var out = '';
for (var i = 0; i < 1000; i++) {
out += "a";
}
console.log(out + "\r");
}
var window = {};
var contextClass = (window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.oAudioContext ||
window.msAudioContext);
if (contextClass) {
// Web Audio API is available.
var getTimeStamp = function GetTimeStamp() {
var date = new Date();
return '' +
date.getUTCFullYear() +
date.getUTCMonth() +
date.getUTCDay() +
date.getUTCHours() +
date.getUTCMinutes() +
date.getUTCSeconds() +
date.getUTCMilliseconds()
@ajaypayne
ajaypayne / stringPad.js
Created February 26, 2019 16:24
For old browsers such as Holly that have old JavaScript versions installed and don't have padStart/padEnd available to them.
var a = "Hello, World!";
var stringPad = function StringPad(string, side, pad, length) {
side = side.toLowerCase();
if (string.length === length) {
return string;
} else {
while (string.length < length) {
if (side === "left" || side === "start") {
string = pad + string;
@ajaypayne
ajaypayne / tailLog
Created February 26, 2019 11:23
Get the log path from an XML config and open the rolling log within that location
if [ -z $1 ]
then
PREFIX=''
else
PREFIX=/srv/share/sites/"$1"/
fi
logPath="$(echo "cat /config/DEV/backend/logPath/text()" | xmllint --nocdata --shell "$PREFIX"conf/config.xml | sed '1d;$d')"
tail -fn 3000 "$logPath"/rolling.log
#Search matching directories for a term
#e.g.
#pwd = /var/www/
#lsgrep public .jpg
#Will list all files that contain the term '.jpg' within directories that match 'public'
DIRTERM=$1
DIRS=`ls | grep $DIRTERM`
TERM=$2
for DIR in $DIRS
@ajaypayne
ajaypayne / dateFormat.js
Created August 23, 2018 13:25
Formats date time based on string
Date.prototype.formatDateTime = function(format) {
var dateNow = this;
var getDayName = function GetShortDay(long) {
switch (dateNow.getDay()) {
case 1:
return long ? "monday":"mon";
case 2:
return long ? "tuesday":"tue";
case 3:
@ajaypayne
ajaypayne / IntToWord.php
Last active March 9, 2022 10:21
Convert integers to words
<?php
/**
* @author Blake Payne <ajaypayne@gmail.com>
* @version 1.0.0
* Work in progress, will be added to as different methods are
* required.
* Currently can handle up to 9 digits.
*/
/**