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
Accountant | |
Auditor | |
Actor | |
Actuary | |
Adhesive Bonding Machine Operator | |
Tender | |
Administrative Law Judge | |
Administrative Services Manager | |
Adult Basic and Secondary Education and Literacy Teacher | |
Instructor |
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
max_radius_of_earth = 6500 * 1000 # metres | |
max_sqrt_distance = math.sqrt(max_radius_of_earth * 0.95) | |
min_sqrt_distance = math.sqrt(100) | |
class LocationMixin(object): | |
"""Provides ``self.latitude`` and ``self.longitude`` attributes and a | |
``self.update_location()`` method which updates ``self.location``, | |
which is stored as a geography type in latlng projection. | |
You can keep self.location uptodate automatically by binding to |
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 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
import ast | |
import inspect | |
import os | |
def get_short_lambda_source(lambda_func): | |
"""Return the source of a (short) lambda function. | |
If it's impossible to obtain, returns None. | |
""" | |
try: |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
def load_gist(gist_id): | |
"""translate Gist ID to URL""" | |
from json import load | |
from urllib import urlopen | |
gist_api = urlopen("https://api.github.com/gists/" + gist_id) |