Skip to content

Instantly share code, notes, and snippets.

View erichiggins's full-sized avatar

Eric Higgins erichiggins

View GitHub Profile
@erichiggins
erichiggins / ndb_json.py
Last active May 23, 2021 00:27
JSON serializer/deserializer adapted for use with Google App Engine's NDB Datastore API. This script can handle Model, Expando, PolyModel, Query, QueryIterator, Key, datetime, struct_time, and complex types.
#!/usr/bin/env python
"""
JSON encoder/decoder adapted for use with Google App Engine NDB.
Usage:
import ndb_json
# Serialize an ndb.Query into an array of JSON objects.
query = models.MyModel.query()
@erichiggins
erichiggins / appstats_serializer.py
Last active December 25, 2015 10:18
Protobuf to Python dictionary serializer for Google App Engine AppStats module.I wanted to be able to send my AppStats profile data off to a logging service (like Loggly) so that I could monitor it over time. This module serializes the data so that it can be converted to JSON and sent off to a log service by a cron job.
#!/usr/bin/env python
"""
AppStats serializer module which converts App Engine profile data from Protocol Buffers into JSON.
Usage:
import appstats_serializer
# List all AppStats summaries:
appstats_dicts = appstats_serializer.appstats_to_dict(summaries_only=True)
@erichiggins
erichiggins / optroutes.mixin.js
Last active December 14, 2015 19:59
Backbone.Router mixin to bind optional route mappings. This would be useful for user-only or admin-only routes that would 404 otherwise.
/**
* Usage:
* var MyRouter = Backbone.Router.extend(_.extend({}, OptionalRouteMixin, {
* userRoutes: {
* '/profile': 'profile'
* },
* initialize: function(options) {
* this._bindOptRoutes(this.userRoutes);
* }
* }));
@erichiggins
erichiggins / lastsync.mixin.js
Created March 8, 2013 02:39
Backbone mixin that maintains a timestamp for the last successful "sync" event. This can be used on both Models and Collections.
// Last Sync timestamp mixin. Works for Models and Collections.
var LastSync = {
// Update lastSync with current timestamp.
_timestampSync: function() {
this.lastSync = new Date();
},
// Note: Call LastSync.initialize.apply(this) from the Model/Collection .initialize.
initialize: function() {
// Setup lastSync to timestamp sync events.
this.lastSync = null;