Skip to content

Instantly share code, notes, and snippets.

View pamelafox's full-sized avatar

Pamela Fox pamelafox

View GitHub Profile
@pamelafox
pamelafox / jsonexport.js
Created June 27, 2011 23:58
JSON Export Apps Script
// Exports current sheet as JSON and displays in message box.
function exportJSON() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var rowsData = getRowsData(sheet);
ss.msgBox(Utilities.jsonStringify(rowsData));
}
// getRowsData iterates row by row in the input range and returns an array of objects.
// Each object contains all the data for a given row, indexed by its normalized column name.
@pamelafox
pamelafox / usermodel.py
Created July 6, 2011 21:08
SimpleGeo Timezone Calculation on Python App Engine
class User(db.Model):
location = db.StringProperty()
timezone = db.StringProperty(default='America/Los_Angeles')
# Do this once per user
def calculate_timezone(self):
from simplegeo import Client
client = Client('oauth key', 'oauth secret SHH')
response = client.context.get_context_by_address(self.location)
for feature in response['features']:
@pamelafox
pamelafox / deferred.py
Created July 28, 2011 21:13
Deferred handler for Flask
"""
deferred.py
Primary App Engine app handler
"""
import sys, os
package_dir = "packages"
@pamelafox
pamelafox / models.py
Created August 2, 2011 04:58
Using SendGrid Incoming API with Python Flask
# Setup datastore model for storing mail
class ParsedMail(db.Model):
from_address = db.StringProperty()
to_address = db.StringProperty()
text = db.TextProperty()
subject = db.StringProperty()
@pamelafox
pamelafox / gist:1144441
Created August 14, 2011 00:41
Loading fonts CSS
var fontNum = 0;
var maxCharacters = 1730;
var cssBaseUrl = 'http://fonts.googleapis.com/css?family=';
function addCss() {
var cssUrl = cssBaseUrl;
while ((cssUrl.length + allFontNames[fontNum].length) < maxCharacters && (fontNum < (allFontNames.length-1))) {
// dont load khmer, no point
if (fonts[allFontNames[fontNum]].subsets[0] != 'khmer') {
cssUrl += escape(allFontNames[fontNum]) + '|';
@pamelafox
pamelafox / models.py
Created August 24, 2011 23:54
App Engine Photo Upload (with BlobStore)
from __future__ import with_statement
from google.appengine.ext import db, blobstore
from google.appengine.api import memcache, files, images
class Photo(db.Model):
created = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
blob_key = blobstore.BlobReferenceProperty()
url = db.StringProperty()
thumbnail_url = db.StringProperty()
@pamelafox
pamelafox / views.py
Created September 5, 2011 21:26
CORS on Python/Flask
from flask import request, make_response,
def any_response(data):
ALLOWED = ['http://localhost:8888']
response = make_response(data)
origin = request.headers['Origin']
if origin in ALLOWED:
response.headers['Access-Control-Allow-Origin'] = origin
return response
@pamelafox
pamelafox / index_renderer.py
Created September 7, 2011 18:48
Jinja2 Rendering Templates
from jinja2 import Environment, FileSystemLoader
if __name__ == "__main__":
env = Environment(loader=FileSystemLoader('application/templates/'))
template = env.get_template('phonegap/index.html')
print template.render()
@pamelafox
pamelafox / email_logger.py
Created September 15, 2011 17:52
Email Logging for App Engine
#!/usr/bin/env python
#
# based on XMPPLoggingHandler, Copyright 2011 Calvin Rien,
# based on ExceptionRecordHandler, Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@pamelafox
pamelafox / Makefile
Created September 28, 2011 18:04
My phonegap/web/gae makefile
# Javascript/CSS Compressor Makefile - By Benjamin "balupton" Lupton (MIT Licenced)
MAKEFLAGS = --no-print-directory --always-make
MAKE = make $(MAKEFLAGS)
BUILDDIR = ./.build
CLOSUREURL = http://closure-compiler.googlecode.com/files/compiler-latest.zip
CLOSUREDIR = $(BUILDDIR)/closure
CLOSUREFILE = $(CLOSUREDIR)/compiler.jar