Skip to content

Instantly share code, notes, and snippets.

View mrmascott10's full-sized avatar
🎯
Focusing

Michael Scott mrmascott10

🎯
Focusing
View GitHub Profile
@mrmascott10
mrmascott10 / check_colour.php
Last active December 12, 2022 16:38
Check whether a colour is a valid name or hex code
// ****************************************
// * Check colour
// ****************************************
function validateColour($colour) {
$COLOR_NAMES = ["AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black","BlanchedAlmond","Blue","BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate","Coral","CornflowerBlue","Cornsilk","Crimson","Cyan","DarkBlue","DarkCyan","DarkGoldenRod","DarkGray","DarkGrey","DarkGreen","DarkKhaki","DarkMagenta","DarkOliveGreen","DarkOrange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray","DarkSlateGrey","DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue","DimGray","DimGrey","DodgerBlue","FireBrick","FloralWhite","ForestGreen","Fuchsia","Gainsboro","GhostWhite","Gold","GoldenRod","Gray","Grey","Green","GreenYellow","HoneyDew","HotPink","IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush","LawnGreen","LemonChiffon","LightBlue","LightCoral","LightCyan","LightGoldenRodYellow","LightGray","LightGr
@mrmascott10
mrmascott10 / sort_assoc_array.php
Created June 28, 2022 14:17
Sort an associative array in PHP
<?php
// ? Sort smallest first
usort($isochronesArr, function ($item1, $item2) { return $item2['mins'] <=> $item1['mins']; });
// ? Sort largest first
usort($isochronesArr, function ($item1, $item2) { return $item1['mins'] <=> $item2['mins']; });
?>
@mrmascott10
mrmascott10 / validate_postcode_api.js
Last active June 30, 2022 15:33
Validate a postcode without using a database.
<script>
// ****************************************
// Checks if a postcode is valid
// ****************************************
function postcodeValid(postcode) {
var result;
$.get( "https://api.postcodes.io/postcodes/" + postcode + "/validate", function(data) {
result = data['result'];
});
return result;
@mrmascott10
mrmascott10 / point_in_polygon_circle.js
Created June 28, 2022 14:57
Check for a lat/lng point inside a polygon or circle
<script>
// ****************************************
// Check if a point is within a circle.
// toFindX, toFindY, circleCentreX, circleCentreY, radius
// ****************************************
function pointInCircle(x, y, cx, cy, radius) {
var distancesquared = (x - cx) * (x - cx) + (y - cy) * (y - cy);
return distancesquared <= radius * radius;
}
// ****************************************
@mrmascott10
mrmascott10 / ddm_to_dd_latlng_converter.php
Last active September 22, 2022 16:39
Convert a string of degrees decimal minutes to a usable decimal degrees latitude, longitude
<?php
// Accepts: 12 34.567N, 1 2.345W
// Returns: [12.345, 12.345]
function ddmToDDConvert($original) {
$coords = [];
$original = explode(',', $original);
$dirDict = ['S' => -1,'N' => 1,'W' => -1,'E' => 1];
if (count($original) == 2) {
$ddmLat = explode(' ', trim(ltrim($original[0])));
@mrmascott10
mrmascott10 / validate_waypoint.php
Last active December 18, 2023 12:41
Validate a waypoint whether it's a lat lng or a postcode. postcodeToLatLng() refers to another gist.
<?php
// ****************************************
// * Validate waypoint whether it's latlng or postcode
// ****************************************
function validateWaypoint($waypoint) {
if (strpos($waypoint, ",")) {
// ? Probably lat lng
$latLng = explode(",", $waypoint);
if (count($latLng) == 2) {
if ($latLng[0] >= -90 && $latLng[0] <= 90) {