Skip to content

Instantly share code, notes, and snippets.

View erichiggins's full-sized avatar

Eric Higgins erichiggins

View GitHub Profile
@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;
@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 / 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 / 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 / jsbin.bahijuve.css
Created March 16, 2014 18:19
Quick trajectory chart using D3.js. http://jsbin.com/bahijuve/
.line {
fill: none;
stroke: lightblue;
stroke-width: 1.5px;
stroke-linecap: butt;
shape-rendering: geometricPrecision ;
}
.axis--x text {
}
@erichiggins
erichiggins / jsbin.bavel.css
Last active August 29, 2015 13:57
Simple box-and-whisker graph created from Magnetospeed data (in JSON format) using D3.js. http://jsbin.com/bavel/2/ based on http://bl.ocks.org/mbostock/4061502
.box {
font: 10px sans-serif;
}
.box line,
.box rect,
.box circle {
fill: #fff;
stroke: #000;
stroke-width: 1.5px;
@erichiggins
erichiggins / gae_ndb_revisions
Last active August 29, 2015 14:00
GAE NDB Revisions: Create automatic versions of your datastore models, allowing you to undo changes!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Create automatic versions of your App Engine Datastore Models, allowing you to undo changes!
Usage:
import gae_ndb_revisions
# Add two properties to your Model(s).
@erichiggins
erichiggins / search_models.py
Created April 29, 2014 19:26
GAE Search-augmented NDB Models: Keep a searchable index up-to-date with the latest information in your datastore Models.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Search-augmented NDB Models for Google App Engine.
Usage:
import search_models
# Define an index for the document type.
@erichiggins
erichiggins / bootstrap.py
Last active January 2, 2017 00:36
Adding Google App Engine SDK to Python virtualenv
#!/usr/bin/env python
"""
Setup a virtualenv with the Google App Engine SDK.
References:
http://virtualenv.readthedocs.org/en/latest/virtualenv.html#creating-your-own-bootstrap-scripts
http://mindtrove.info/virtualenv-bootstrapping/
"""
import hashlib
import os
@erichiggins
erichiggins / docker_passthru.bash.inc
Last active December 4, 2015 03:31
Enables command deligation to Docker images for a specific repo or directory.
# https://gist.github.com/erichiggins/a8bcd07295597d91dea7/
# version: 0.1.0
# author: Eric Higgins <erichiggins@gmail.com>
#
# Installation:
#
# 1) Copy this file into your repo's directory.
# cp docker_passthru.bash.inc ~/src/myrepo/
# 2) Add the following to your ~/.bash_profile to include this script.
# source ~/src/myrepo/docker_passthru.bash.inc