Skip to content

Instantly share code, notes, and snippets.

View kgundula's full-sized avatar

Khuthadzo Gundula kgundula

View GitHub Profile
@kgundula
kgundula / boundbox
Last active September 22, 2016 15:43
Calculate distance between two sets lat/lon coordinates and Calculate destination lat/lon given a starting point lat/lon cordinates, bearing, and distance, and Calculate the bounding box
// Calculating the bounding box
function boundbox ($lat, $lon, $distance, $units="km") {
return array ( "N" => getDestinationCoordinates ($lat,$lon, 0,$distance,$units),
"E" => getDestinationCoordinates ($lat,$lon, 90,$distance,$units),
"S" => getDestinationCoordinates ($lat,$lon, 180,$distance,$units),
"W" => getDestinationCoordinates ($lat,$lon, 270,$distance,$units));
}
@kgundula
kgundula / MSSQL equivalent MySQL query with limit clause
Last active January 4, 2016 06:09
MSSQL equivalent MySQL query with limit clause
SELECT * FROM
(
SELECT TOP 30 *, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS rnum
FROM table1
) a
WHERE rnum > 10
@kgundula
kgundula / Menu Tree Builder
Created November 13, 2013 09:31
Menu Tree Builder from an sql resultset.
/*
* This function can be use to build a menu tree.
*/
function buildMenuTree($menus, $parentId = 0) {
$branch = array();
foreach ($menus as $menu) {
if ($menu['parent_id'] == $parentId) {
$children = $this->buildMenuTree($menus, $menu['id']);
if ($children) {
$menu['child'] = $children;