This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) { | |
var R = 6371; // Radius of the earth in km | |
var dLat = deg2rad(lat2-lat1); // deg2rad below | |
var dLon = deg2rad(lon2-lon1); | |
var a = | |
Math.sin(dLat/2) * Math.sin(dLat/2) + | |
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * | |
Math.sin(dLon/2) * Math.sin(dLon/2) | |
; | |
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Disclaimer: This is not the most modern method of doing this. | |
function ordinal($num) { | |
$test = abs($num) % 10; | |
$suffix = ((abs($num) %100 < 21 && abs($num) %100 > 4) ? 'th' | |
: (($test < 4) ? ($test < 3) ? ($test < 2) ? ($test < 1) | |
? 'th' : 'st' : 'nd' : 'rd' : 'th')); | |
return $num.$suffix; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('log_errors', TRUE); // Error logging | |
ini_set('error_log', 'your/path/to/errors.log'); // Logging file | |
ini_set('log_errors_max_len', 1024); // Logging file size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Database extends PDO { | |
// These variable should be in a separate file outside of your root directory | |
private $host = '127.0.0.1'; | |
private $db = 'database_name'; | |
private $user = 'anything_but_root'; | |
private $pass = 'anything_but_password'; | |
private $charset = 'utf8mb4'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function in($data) { | |
$data = strip_tags($data); | |
$data = stripslashes($data); | |
return trim($data); | |
} | |
function out($data) { | |
return htmlentities($data, ENT_QUOTES, 'UTF-8'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// var_Dump and Die | |
function dnd($data) { | |
echo '<pre>'; | |
var_dump($data); | |
echo '</pre>'; | |
die(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set ('Europe/Amsterdam'); | |
function greeting() { | |
$day = date("l"); | |
$hour = date("H"); | |
if($hour < "12") { | |
$time = " morning "; | |
} elseif ($hour >= "12" && $hour < "18") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function form_token() { | |
$token = bin2hex(random_bytes(33)); | |
return $token; | |
} // Usage | |
// $form_token = form_token(); | |
// echo "$form_token"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function check_for_non_alpha_numeric($str) { | |
$reg = '/[^[:alnum:]$]/'; | |
preg_match_all($reg, $str, $matches, PREG_SET_ORDER, 0); | |
if($matches) { | |
print "<hr>oops, try again.<pre>"; | |
var_dump($matches); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fibonacci($n) { | |
$current = 1; | |
$previous = 0; | |
for ($i = 0; $i < $n; $i++) { | |
yield $current; | |
$temporary = $current; | |
$current = $previous + $current; | |
$previous = $temporary; |
OlderNewer