Skip to content

Instantly share code, notes, and snippets.

Avatar
🕚
I don't have time to hurry!

I. Gaffling gaffling

🕚
I don't have time to hurry!
View GitHub Profile
@gaffling
gaffling / wallpaper.php
Created April 25, 2022 10:27
[Download 100 Wallpapers] from taskade.com #php #function #wallpaper
View wallpaper.php
/* -------------------------------------------------------------------- */
/* [Download 100 Wallpapers] from taskade.com #php #function #wallpaper */
/* -------------------------------------------------------------------- */
if ( !is_dir( 'wallpaper' ) ) {
mkdir( 'wallpaper' );
}
@gaffling
gaffling / Brightness.php
Created August 2, 2021 11:28
[Brightness] Change the brightness of a color by a percentage (0.3 = 30% lighter / -0.4 = 40% darker) #php #function #brightness
View Brightness.php
/* -------------------------------------------------------------------------------------------------------------------------------- */
/* [Brightness] Change the brightness of a color by a percentage (0.3 = 30% lighter / -0.4 = 40% darker) #php #function #brightness */
/* -------------------------------------------------------------------------------------------------------------------------------- */
function adjustBrightness($hexCode, $adjustPercent) {
$hexCode = ltrim($hexCode, '#');
if (strlen($hexCode) == 3) $hexCode = $hexCode[0].$hexCode[0].$hexCode[1].$hexCode[1].$hexCode[2].$hexCode[2];
$hexCode = array_map('hexdec', str_split($hexCode, 2));
foreach ($hexCode as & $color) {
$adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
@gaffling
gaffling / isBot.php
Created July 23, 2021 12:36
[is it a Bot] Check if a user_agent is a Bot #php #function #bot
View isBot.php
/* ---------------------------------------------------------------- */
/* [is it a Bot] Check if a user_agent is a Bot #php #function #bot */
/* ---------------------------------------------------------------- */
function isBot($user_agent='') {
if (empty($user_agent)) $user_agent = $_SERVER['HTTP_USER_AGENT'];
$bot_regex_pattern = "(googlebot\/|Googlebot\-Mobile|Googlebot\-Image|Google favicon|Mediapartners\-Google|bingbot|slurp|java|wget|curl|Commons\-HttpClient|Python\-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST\-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub\.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum\.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips\-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sit
@gaffling
gaffling / contrast.php
Last active August 4, 2021 15:20
[Contrast Color] Decide font colour in white or black depending on the background colour #php #function #contrastcolor
View contrast.php
/* ---------------------------------------------------------------------------------------------------------------------- */
/* [Contrast Color] Decide contrast colour in white or black depending on the background colour #php #function #contrastcolor */
/* ---------------------------------------------------------------------------------------------------------------------- */
function contrast($color, $lightColor='#FFFFFF', $darkColor='#000000') {
/**
* This is useful for ensuring that a color is readable against a background,
* which is also useful for accessibility compliance.
*/
// REMOVE # IF THERE IS ONE
@gaffling
gaffling / slugify.php
Created May 17, 2021 09:39
[slugify] make slug from e.g. title string #php #function #slug
View slugify.php
<?php
/* --------------------------------------------------------------- */
/* [slugify] make slug from e.g. title string #php #function #slug */
/* --------------------------------------------------------------- */
function slugify($string=null) {
$LIST = [
' ' => '-',
@gaffling
gaffling / print_var_name.php
Created May 17, 2021 07:24
[Print var name] Function that print the varname #function #debug #varname
View print_var_name.php
<?php
/* -------------------------------------------------------------------------- */
/* [Print var name] Function that print the varname #function #debug #varname */
/* -------------------------------------------------------------------------- */
/**
* USE: print_var_name($var)
* PRINT: var
* @see https://stackoverflow.com/a/36921487
@gaffling
gaffling / truncate.php
Created May 4, 2021 15:22
[Truncate] Function that truncate a string and don't break words #php #function #truncate
View truncate.php
<?php
/* ----------------------------------------------------------------------------------------- */
/* [Truncate] Function that truncate a string and don't break words #php #function #truncate */
/* ----------------------------------------------------------------------------------------- */
function truncate($string, $max_length, $breakWords=false, $append='&hellip;') {
$strLength = mb_strlen($string);
// IF IT'S NOT TO LONG RETURN IT AS IT IS
if ($strLength <= $max_length) return $string;
@gaffling
gaffling / checkMime.php
Created April 3, 2021 12:32
[Check Mime Type] Check if URl is a given MimeType #php #function #mime
View checkMime.php
/* ----------------------------------------------------------------------- */
/* [Check Mime Type] Check if URl is a given MimeType #php #function #mime */
/* ----------------------------------------------------------------------- */
function checkMime($url, $mime='application/pdf') {
// MP3 = 'audio/mpeg' - PDF = 'application/pdf'
if (!function_exists('curl_init')) die('ERROR - Please install CURL on your PHP!');
$a = parse_url($url);
if (checkdnsrr(str_replace('www.','',$a['host']),'A') or checkdnsrr(str_replace('www.','',$a['host']))) {
$ch = @curl_init();
@gaffling
gaffling / doSMTPValidation.php
Created April 3, 2021 12:19
[Mail Validation] Use SMTP to validate eMail Address #php #function #mailcheck
View doSMTPValidation.php
/* ------------------------------------------------------------------------------ */
/* [Mail Validation] Use SMTP to validate eMail Address #php #function #mailcheck */
/* ------------------------------------------------------------------------------ */
function doSMTPValidation($email, $probe_address='', $debug=false) {
$output = '';
if (!$probe_address) $probe_address = $_SERVER['SERVER_ADMIN'];
if (preg_match('/^([a-zA-Z0-9\._\+-]+)\@((\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,7}|[0-9]{1,3})(\]?))$/', $email, $matches)) {
$user = $matches[1];
@gaffling
gaffling / getLatLong.php
Created April 3, 2021 11:56
[getLatLong] Get lat and long coordinatesby address from Google Maps #php #function #geo
View getLatLong.php
/* ---------------------------------------------------------------------------------------- */
/* [getLatLong] Get lat and long coordinatesby address from Google Maps #php #function #geo */
/* ---------------------------------------------------------------------------------------- */
function getLatLong($address){
if (!is_string($address)) die('ERROR - Address must be a string!');
$url = sprintf('https://www.google.com/maps/place/%s', rawurlencode($address));
$result = file_get_contents($url);
preg_match('!center=(-?\d+\.\d+)%2C(-?\d+\.\d+)&amp;zoom=!U', $result, $match);
$_coords['lat'] = $match[1];