Skip to content

Instantly share code, notes, and snippets.

{
"requires": [
"getmodelnodebyid",
"coalesce"
],
"transform-t": {
"!": {
":": {
"!": {
":": {
@emlynoregan
emlynoregan / SampleTweets.json
Last active September 6, 2015 09:59
Sample Tweets from twitter docs
[
{
"coordinates": null,
"favorited": false,
"truncated": false,
"created_at": "Wed Aug 29 17:12:58 +0000 2012",
"id_str": "240859602684612608",
"entities": {
"urls": [
{
{
"characters": [
{
"fullname": "Ambassador Kosh",
"saying": "Yes"
},
{
"fullname": "Worf"
},
{
{
"characters": [
{
"_type": "section",
"path": "$.items[*]",
"transform": {
"fullname": "#@.name",
"saying": {
"_type": "section",
"path": "@.quote",
{
"cursor": "8b08006b-963a-6909-c132-cc618cd4b352",
"more": true,
"items": [
{
"name": "Ambassador Kosh",
"type": "Vorlonn",
"resources": {
"website": "http://babylon5.wikia.com/wiki/Kosh",
"quote": "Yes"
var fooschema = <some schema>
var footransform = <some transform>
var foo = function(inputmas) {
JsonSchema.validate(inputmas, fooschema)
return JsonTransform.transform(inputmas, footransform)
}
class Greeting(ndb.Model):
...
def _post_put_hook(self, future):
# replace the document for this object in the relevant search index
@classmethod
def _post_delete_hook(cls, key, future):
# delete the document for this object from the relevant search index
class Greeting(ndb.Model):
...
def _post_put_hook(self, future):
# replace the document for this object in the relevant search index
@classmethod
def _post_delete_hook(cls, key, future):
# delete the document for this object from the relevant search index
class Greeting(ndb.Model):
"""Models an individual Guestbook entry with content and date."""
content = ndb.StringProperty()
date = ndb.DateTimeProperty(auto_now_add=True)
@emlynoregan
emlynoregan / gist:9604b963901bfb63a752
Last active August 29, 2015 14:10
Datastore Mapper with Distributed Promises for AppEngine
# This is a generic map function for the datastore.
# Suitable for passing to the PromiseSpace.when() method.
# outerresolve: this function is called when the mapping is complete, with the full result.
# promiseSpace: a promise space, to be used for making promises.
# dsQuery: an ndb datastore query.
# mapF: an optional map function. Takes an object or key (depending on keyOnly) and returns something.
# reduceF: an optional reduce function. Takes a list of results of mapping and a previous return value
# from reduceF, and returns a new value
# keyOnly: determines whether the queries fetch objects or just keys
# pageSize: size of the pages fetched from the query