Skip to content

Instantly share code, notes, and snippets.

View johnabela's full-sized avatar
🏠
Working from home

John Abela johnabela

🏠
Working from home
View GitHub Profile
@johnabela
johnabela / [PHP] howManyDaysBetweenTwoDays()
Last active August 29, 2015 14:09
How many days between two unix time stamps
//
//
///////////////////////////////////////////////////////////////////////
// howManyDaysBetweenTwoDays()
//
// - Description:
// How many days between two unix time stamps
// 86400 is derived from:
// 60 (seconds) multiplied by 60 (minutes) multiplied by 24 (hours)
//
@johnabela
johnabela / [PHP] intToOrdinal()
Last active August 29, 2015 14:09
Add Ordinal Text (st/nd/th) To Integer
//
//
///////////////////////////////////////////////////////////////////////
// intToOrdinal()
//
// - Description:
// Add Ordinal Text To Integer
//
// - Usage:
// $str_return = intToOrdinal($number);
@johnabela
johnabela / [PHP] bitly_MakeShortLink()
Last active September 8, 2015 09:55
Use the bit.ly api to generate short URL
$Today = gregoriantojd(date('n'),date('j'),date('Y'));
$Month = jdmonthname($Today,4);
$Date = jdtojewish($Today);
list($notused, $Day, $Year) = explode('/',$Date);
echo "$Month $Day, $Year";
@johnabela
johnabela / [PHP] Are All Characters Identical?
Last active February 22, 2017 18:33
[PHP] Are All Characters Identical?
$word = 'dddddd';
if (empty(str_replace(mb_substr(trim($word),-1),'',trim($word)))) {
die('all the characters are identical');
}
@johnabela
johnabela / htaccess domain.tld{dash}usersname
Created February 25, 2017 01:57
htaccess to allow domain.tld/usersname
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(register|contact|signin|policies) [NC]
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ /profile.php?id=$1 [L,QSA]
@johnabela
johnabela / Power of (U)GUID Lengths
Created March 11, 2017 16:19
Visual insight into a basic a-z0-9 'power of' string lengths.
If you use your own (U)(G)UID generator for unique identifiers, say UserGUID or WidgetGUID or whatnot, there is very little chance you are ever going to need to use something like `md5(time())` or `bin2hex(random_bytes(5))` or whatever.
Using just a very basic (and all lowercase) `a-z` & `0-9` combination will result in a 36 character string.
abcdefghijklmnopqrstuvwxyz0123456789 = 36 characters
If we take those 36 characters to the `power of` we get the follow possible unique vales:
[1] = 36
[2] = 1,296
@johnabela
johnabela / [PHP] Get Domain From Email Address (multiple @ symbol support)
Created March 13, 2017 22:55
A more proper way to get the domain.tld from an email address in php
// too many php developers use the example on the php `strstr` page:
// http://php.net/manual/en/function.strstr.php
// Yet, amazingly, the following is a valid email address:
// foo@bar@domain.tld
// If you use the example on the strstr page you end up with:
// @bar@domain.tld -- which is of course not what you want.
// So what is a fast and extremely low memory method to return
// just the domain.tld when? The following seems to be the best.
$email = 'foo@bar@domain.tld';
@johnabela
johnabela / [PHP] Validate (intl) Email Address
Last active September 12, 2017 07:46
Sometimes simple is the best
/*
We live in a world where internationalization is becoming more and more important for website developers to be conscience of.
RTF standards are a mess, we can all agree on that.
Attempting to validate email addresses, based on RTF standards, is simply impossible if you want to accept non utf-8 formatted email addresses.
Never trust the browser to properly handle utf-8 parsing.
Never trust php to properly handle utf-8 parsing, it is usually worse than the big three browsers.
@johnabela
johnabela / [PHP] pls_GetStreamPath()
Created December 3, 2017 02:27
Acquire the stream path of a .pls file
//
//
///////////////////////////////////////////////////////////////////////
// pls_GetStreamPath()
//
// - Description:
// Acquire the stream path of a .pls file
//
// - Usage:
// $streamPath = pls_GetStreamPath($uri);