Skip to content

Instantly share code, notes, and snippets.

View andrewxhill's full-sized avatar

Andrew W. Hill andrewxhill

View GitHub Profile
@andrewxhill
andrewxhill / gist:1041841
Created June 23, 2011 03:18
Python Commplish User Profile API Example
import md5
import urllib
import urllib2
#the API Secret for your Project
secret = '9393c2df-e1c8-457c-adc1-a5b75210d52f'
#the User email address you querying (all lowercase)
email = 'andrewxhill@gmail.com'
@andrewxhill
andrewxhill / gist:1041850
Created June 23, 2011 03:28
Commplish Badge Awarding API
import md5
import urllib
import urllib2
#the API Secret for your Project
secret = '9393c2df-e1c8-457c-adc1-a5b75210d52f'
#the User email address you querying (all lowercase)
email = 'andrewxhill@gmail.com'
@andrewxhill
andrewxhill / gist:1048066
Created June 26, 2011 22:38
Commplish Bitcoin Awarding API
import md5
import urllib
import urllib2
#the API Secret for your Project
secret = '9393c2df-e1c8-457c-adc1-a5b75210d52f'
#the User email address you querying (all lowercase)
email = 'andrewxhill@gmail.com'
#you have this
class Note(db.Model):
""" user note on a cell """
cell = db.ReferenceProperty(Cell)
#Instead, do this,
class Note(db.Model):
""" user note on a cell """
#parent = Cell #this is done on creation
cell = db.ReferenceProperty(collection='notes', Cell)
"""
Another thought
The use of indexes can be super useful as it avoids serialization of all the data
by doing key only queries. Then, using the key returned to pull the parent which
would be the full set of data. So, something like this
"""
class CellIndex(db.Model):
#parent = Cell
GIT
remote: git://github.com/ferblape/sequel-rails.git
revision: a283527d53895d6189f879bd96d2500b609b82e7
specs:
sequel-rails (0.1.7)
actionpack (~> 3.0.0.rc)
activesupport (~> 3.0.0.rc)
railties (~> 3.0.0.rc)
sequel (~> 3.13)
SELECT
SUM(ST_Value(rast, 1, x, y)), count(*), SUM(ST_Value(rast, 1, x, y))/count(*)
FROM carbon_query_test_s CROSS JOIN
generate_series(1,10) As x CROSS JOIN generate_series(1,10) As y
WHERE rid in ( SELECT rid FROM carbon_query_test_s WHERE ST_Intersects(rast, ST_GeomFromText('MULTIPOLYGON(((18.511962890625 5.386335689520536,14.864501953125 2.141834969768584,18.775634765625 0.0769042737833478,22.510986328125 -0.5383221578577078,26.114501953125 0.8239462091017685,26.553955078125 3.3269862108134998,22.423095703125 6.085935520826564,18.511962890625 5.386335689520536)))',4326)) )
AND
ST_Intersects(
ST_Translate (ST_MakeEnvelope(
ST_UpperLeftX(rast), ST_UpperLeftY(rast),
ST_UpperLeftX(rast) + ST_ScaleX(rast),
SELECT SUM(ST_Value(rast, 1, x, y)), COUNT(*)
FROM carbon_query_test_s CROSS JOIN
generate_series(1,10) As x CROSS JOIN generate_series(1,10) As y
WHERE rid in ( SELECT rid FROM carbon_query_test_s WHERE ST_Intersects(rast, ST_GeomFromText('MULTIPOLYGON(((18.511962890625 5.386335689520536,14.864501953125 2.141834969768584,18.775634765625 0.0769042737833478,22.510986328125 -0.5383221578577078,26.114501953125 0.8239462091017685,26.553955078125 3.3269862108134998,22.423095703125 6.085935520826564,18.511962890625 5.386335689520536)))',4326)) )
AND
ST_Intersects(
ST_Translate (ST_MakeEnvelope(
ST_UpperLeftX(rast), ST_UpperLeftY(rast),
ST_UpperLeftX(rast) + ST_ScaleX(rast),
ST_UpperLeftY(rast) + ST_ScaleY(rast), 4326
SELECT rid,
encode(
ST_AsPng(
ST_Resample(
ST_ClipEx(
rast,
ST_World2RasterCoordX(
rast,
foo.upper_left),
ST_World2RasterCoordY(
@andrewxhill
andrewxhill / ST_ClipEx.sql
Created December 8, 2011 17:19
ST_ClipEx a working variation of ST_Clip for raster
CREATE OR REPLACE FUNCTION ST_ClipEx(rast raster, x int, y int, width int, height int)
RETURNS raster AS
$$
DECLARE
newrast raster := ST_MakeEmptyRaster(width, height, ST_UpperLeftX(rast), ST_UpperLeftY(rast),
ST_ScaleX(rast), ST_ScaleY(rast), ST_SkewX(rast), ST_SkewY(rast), ST_SRID(rast));
numband int := ST_Numbands(rast);
band int;
cx int;
cy int;