Skip to content

Instantly share code, notes, and snippets.

View whardier's full-sized avatar
🧨
Code...

Shane R. Spencer whardier

🧨
Code...
View GitHub Profile
@whardier
whardier / hosts
Created August 10, 2013 02:57
This is how I speed up access to SSL services, by using NGINX as a local proxy and using ssl session reuse.. then booting my API urls down to HTTP
127.0.2.1 proxy.need4moredev.api.oneall.com
spencersr@buckaroobanzai:~$ python test1.py
1
1.5
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
import sys
import pprint
import base64
import urllib
import json
@whardier
whardier / ihateandrew.py
Created July 24, 2013 23:30
This takes any PIL compatible image and converts it to an HTML Table (in full RGB). Next revision should reduce down colors and use styles.
#!/usr/bin/env python
import sys
import struct
import itertools
from PIL import Image
im = Image.open(sys.argv[1])
tornado.escape.native_str(
base64.urlsafe_b64encode(
tornado.escape.utf8(
tornado.escape.native_str(
'http://someyummy.url/cupcake'
)
)
)
)
spencersr@buckaroobanzai:~/Projects/AllYourDatabase/Example$ find -L Location -print0 | xargs -0 ls -idH | sort -k 2 | sed 's|Location/Continent/North America/Country/United States of America/State/|.../|' | grep "Alaska" | sort -k 2
985554 .../Alaska
985556 .../Alaska/County
985557 .../Alaska/County/Anchorage Municipality
985558 .../Alaska/County/Anchorage Municipality/Community
985561 .../Alaska/County/Anchorage Municipality/Community/Anchorage
985701 .../Alaska/County/Anchorage Municipality/Community/Anchorage/Neighborhood
985623 .../Alaska/County/Anchorage Municipality/Community/Anchorage/Neighborhood/Campbell
985821 .../Alaska/County/Anchorage Municipality/Community/Anchorage/Neighborhood/Campbell/Postal Code
985721 .../Alaska/County/Anchorage Municipality/Community/Anchorage/Neighborhood/Campbell/Postal Code/99518
MongoDB shell version: 2.4.3
connecting to: test
Initial Document
{
"_id": ObjectId(
"51a64dafc29659cc0732ec75")
}
Adding in a post
Modified Document
{
> db.places.aggregate({ '$match': { 'dns': /^anchorage.alaska/ }}, {'$group' : { _id: {dns: '$dns', importance: "$importance", level: "$level"}, geohashes: { $addToSet: '$geohash' }}}, {'$sort': { "_id.level": -1, "_id.importance": -1} })
{
"result" : [
{
"_id" : {
"dns" : [
"anchorage.anchorage.alaska",
"anchorage.alaska",
"anchorage.anchorage.ak",
"anchorage.ak"
@whardier
whardier / gist:5471903
Created April 27, 2013 04:43
Abusing geohashes to present both radius and specific point by adding a single slash
# below be a geohash
>>> geohash.encode(64, -141, precision=8)
'bg7sp6yg'
# Below be radians
>>> geohash.decode_exactly(geohash.encode(64, -141, precision=8))[-1]
0.000171661376953125
>>> geohash.decode_exactly(geohash.encode(64, -141, precision=7))[-1]
0.0006866455078125
>>> geohash.decode_exactly(geohash.encode(64, -141, precision=6))[-1]
class BaseHandler(tornado.web.RequestHandler):
# ...
@tornado.gen.coroutine
def verify_place_something(self):
motor_db = self.settings['motor_db']
cursor = motor_db.places.find(