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
--- | |
METHOD 1 | |
This should roughly sort the items on distance in MySQL, and should work in SQLite. | |
If you need to sort them preciser, you could try using the Pythagorean theorem (a^2 + b^2 = c^2) to get the exact distance. | |
--- | |
SELECT * | |
FROM table | |
ORDER BY ((lat-$user_lat)*(lat-$user_lat)) + ((lng - $user_lng)*(lng - $user_lng)) ASC |
This cheat sheet originated from the forum, credits to Laurent Poulain. We copied it and changed or added a few things.
- Call by value: evaluates the function arguments before calling the function
- Call by name: evaluates the function first, and then evaluates the arguments if need be
def example = 2 // evaluated when called
val example = 2 // evaluated immediately
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
// Returns an array of dates between the two dates | |
function getDates (startDate, endDate) { | |
const dates = [] | |
let currentDate = startDate | |
const addDays = function (days) { | |
const date = new Date(this.valueOf()) | |
date.setDate(date.getDate() + days) | |
return date | |
} | |
while (currentDate <= endDate) { |