Skip to content

Instantly share code, notes, and snippets.

View quadrismegistus's full-sized avatar

Dr. Ryan Heuser quadrismegistus

View GitHub Profile
@koji-kojiro
koji-kojiro / import_from_gist.py
Created December 24, 2016 15:47
[Python] import from Gist
#!/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)
@statickidz
statickidz / nearby-coordinates.sql
Last active January 31, 2024 20:31
Ordering with SQL by nearest latitude & longitude coordinates (MySQL & SQLite)
---
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
@thruflo
thruflo / LocationMixin.py
Created December 9, 2011 15:07
Example `LocationMixin` class that can be used to provide geolocation to any `SQLModel` class.
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
@wsc
wsc / gist:1083459
Created July 14, 2011 21:13
Occupation list
Accountant
Auditor
Actor
Actuary
Adhesive Bonding Machine Operator
Tender
Administrative Law Judge
Administrative Services Manager
Adult Basic and Secondary Education and Literacy Teacher
Instructor