Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

John Abela johnabela

🏠
Working from home
Block or report user

Report or block johnabela

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
@johnabela
johnabela / [php] Today Minus 1 Week
Created Apr 21, 2019
A nice php one-liner to return a formated date of whatever today is, minus one week.
View [php] Today Minus 1 Week
$TodayMinusOneWeek = (new DateTime())->modify('-1 week')->format('Y-m-d');
View key.asc
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: https://keybase.io/abela
Version: Keybase Go 2.6.2 (windows)
xsFNBFutaj0BEADZzFhdstGCNE4AlWgIC7sP0sSVCpRP7O4quiaVxUcXqLaeEBnA
opr1icEJPExoUVjfZ7VatOCWgtHqhi+Szi2byM4giRBdaXGWD+wRgNIJHUpn/xaK
v4UTr+YUMZSVkibGXLU403YYV75ExzsDQEKUAkoQw3hbEsHb/XZ1HcnILwAubxG3
wkwwP6LjNPdlK6EXUD+Fr/jyyrNHZTr8qrQz1qw2gsQGD/TZ+vNUaeNpoO3+jPbK
0eh5eJFAm8lQp3vfoW5Jy2zvCNOUKKwGzalGiB3ZQkc0NtcO3vBUiz/YQUmPg6uz
+6bUNuMpkiHiEsugEFBmFjDUf1Cvy8bR8EKBEAI14yQ+oRb/lJ+p4KAQLHUTGAiT
View [php] array_RequiredKeys()
/**
* Check to see if an array is suppose to have specific keys.
* This does not check to see if the keys have any values, it
* only checks to see if the keys exists.
*
* @usage
* $array = ['key' => 'meh', 'secret' => 'why'];
* $requiredKeys = ['key', 'secret'];
* array_RequiredKeys($requiredKeys, $array);
*
View keybase.md

Keybase proof

I hereby claim:

  • I am johnabela on github.
  • I am abela (https://keybase.io/abela) on keybase.
  • I have a public key ASC5tKhN0gyNG-sHKE77ylFQuh1APL_ZoGZ0SCUbw4ecCgo

To claim this, I am signing this object:

@johnabela
johnabela / [php] get domain name
Last active Jun 28, 2018
get domain name (without tld) from uri
View [php] get domain name
$url = (substr($url, 0, 4) != 'http') ? 'http://'.$url : $url;
$url = preg_replace('~\.(com|info|net|io|us|org|me|co\.uk|ca|mobi)\b~i','',parse_url($url)['host']);
$url = substr($url,strrpos($url,'.')+1);
// examples:
// 'server.google.co.uk/abela'; // returns: google
// 'https://www.facebook.com/abela/'; // returns: facebook
@johnabela
johnabela / [PHP] pls_GetStreamPath()
Created Dec 3, 2017
Acquire the stream path of a .pls file
View [PHP] pls_GetStreamPath()
//
//
///////////////////////////////////////////////////////////////////////
// pls_GetStreamPath()
//
// - Description:
// Acquire the stream path of a .pls file
//
// - Usage:
// $streamPath = pls_GetStreamPath($uri);
@johnabela
johnabela / [PHP] Validate (intl) Email Address
Last active Sep 12, 2017
Sometimes simple is the best
View [PHP] Validate (intl) Email Address
/*
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] Get Domain From Email Address (multiple @ symbol support)
Created Mar 13, 2017
A more proper way to get the domain.tld from an email address in php
View [PHP] Get Domain From Email Address (multiple @ symbol support)
// 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 / Power of (U)GUID Lengths
Created Mar 11, 2017
Visual insight into a basic a-z0-9 'power of' string lengths.
View Power of (U)GUID 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 / htaccess domain.tld{dash}usersname
Created Feb 25, 2017
htaccess to allow domain.tld/usersname
View htaccess domain.tld{dash}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]
You can’t perform that action at this time.