Skip to content

Instantly share code, notes, and snippets.

View aramonc's full-sized avatar

Adrian Cardenas aramonc

  • HelloFresh
  • Valencia, ES
  • 01:41 (UTC +02:00)
  • X @aramonc
View GitHub Profile
@aramonc
aramonc / Readability.php
Last active August 29, 2015 14:01
How bad is it to have code like this for readability & maintainability
<?php
if($paramFetcher['owner'] != null && ($owner = $userMgr->getById($paramFetcher['owner']))) {
$org->setOwner($owner);
}
?>
vs.
<?php
if($paramFetcher['owner'] != null) {
@aramonc
aramonc / bearing.sql
Last active March 13, 2024 11:23
MySQL function to calculate the bearing between two points
DELIMITER $$
CREATE FUNCTION `bearing` (lat1 DECIMAL(8,6), lng1 DECIMAL(9,6), lat2 DECIMAL(8,6), lng2 DECIMAL(9,6)) RETURNS DECIMAL(9,6)
BEGIN
DECLARE dLng DECIMAL(30,15);
DECLARE y DECIMAL(30,15);
DECLARE x DECIMAL(30,15);
DECLARE bearing DECIMAL(30,15);
SET dLng = RADIANS( lng2 ) - RADIANS( lng1 );
@aramonc
aramonc / distance.sql
Last active May 1, 2021 08:55
MySQL function to calculate the distance between two coordinates using the Haversine formula. Leaving it here for future reference.
DELIMITER $$
CREATE FUNCTION `haversine` (lat1 DECIMAL(8,6), lng1 DECIMAL(8,6), lat2 DECIMAL(8,6), lng2 DECIMAL(8,6)) RETURNS DECIMAL(8,6)
BEGIN
DECLARE R INT;
DECLARE dLat DECIMAL(30,15);
DECLARE dLng DECIMAL(30,15);
DECLARE a1 DECIMAL(30,15);
DECLARE a2 DECIMAL(30,15);
DECLARE a DECIMAL(30,15);
DECLARE c DECIMAL(30,15);