Skip to content

Instantly share code, notes, and snippets.

View mentat's full-sized avatar

Jesse Lovelace mentat

  • Austin, TX
View GitHub Profile
@mentat
mentat / jobs.py
Created October 27, 2011 22:47
Mapreduce job for blob migration
def migrate_blobstore(entity):
" Migrate entities with blob fields from another app. "
import urllib, mimetypes
from google.appengine.api import files
modified = False
fields = entity.get_blob_fields()
logging.debug("Fields are: %s" % fields)
for field in fields:
@mentat
mentat / views.py
Created October 27, 2011 22:50
Some helpful handlers for downloading blobs.
class BlobMigrationHandler(YourCustomHandler):
" List out the blob keys so we can migrate them. "
def get(self):
CHUNK = 300
cursor = self.request.GET.get('cursor')
q = blobstore.BlobInfo.all()
@mentat
mentat / json.py
Created November 2, 2011 17:18
Serialize GQL to json
# Copyright 2008 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
#
# Unless required by applicable law or agreed to in writing, software
@mentat
mentat / generate_protorpc.py
Created November 10, 2011 16:04
Generate Protocol Buffer definition file from Python ProtoRPC Module
"""
Thanks to [email protected] (Rafe Kaplan) for this tip.
Create a .proto file from a module containing ProtoRPC Message
classes.
"""
import logging
from protorpc import descriptor
from protorpc import generate
@mentat
mentat / jqui.html
Created November 18, 2011 19:30
Jquery UI Skel
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/redmond/jquery-ui.css" rel="stylesheet" type="text/css"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Testy</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
@mentat
mentat / search_testbed.diff
Created December 20, 2011 22:32
Patch testbed to include search service stub
--- /google_appengine.old/google/appengine/ext/testbed/__init__.py 2011-12-12 13:12:00.000000000 -0600
+++ /google_appengine.new/google/appengine/ext/testbed/__init__.py 2011-12-20 16:25:45.000000000 -0600
@@ -125,6 +125,8 @@
from google.appengine.api.memcache import memcache_stub
from google.appengine.api.taskqueue import taskqueue_stub
from google.appengine.api.xmpp import xmpp_service_stub
+from google.appengine.api.search import simple_search_stub
+
try:
from google.appengine.datastore import datastore_sqlite_stub
@mentat
mentat / patch.diff
Created December 21, 2011 17:09
Add pre/post create hooks to NDB
diff --exclude='*.pyc' -Naur ndb.old/key.py ndb/key.py
--- ndb.old/key.py 2011-12-20 10:27:11.000000000 -0600
+++ ndb/key.py 2011-12-21 11:23:49.000000000 -0600
@@ -514,6 +514,8 @@
if not cls._is_default_hook(model.Model._default_post_get_hook,
post_hook):
fut.add_immediate_callback(post_hook, self, fut)
+ internal_post_hook = model.Model._post_get_hook_internal
+ fut.add_immediate_callback(internal_post_hook, self, fut)
return fut
@mentat
mentat / bug.diff
Created December 23, 2011 01:29
Failing polymodel test
--- ndb.old/polymodel_test.py 2011-12-20 10:27:11.000000000 -0600
+++ ndb/polymodel_test.py 2011-12-22 19:26:29.000000000 -0600
@@ -7,6 +7,7 @@
import unittest
from google.appengine.api import namespace_manager
+from google.appengine.api import datastore_types
from . import polymodel
from . import model
@mentat
mentat / loaded.diff
Created March 2, 2012 22:30
Add _is_loaded to NDB
diff -Naur -x '*.pyc' ndb.old/model.py ndb/model.py
--- ndb.old/model.py 2012-03-02 16:04:15.000000000 -0600
+++ ndb/model.py 2012-03-02 16:11:18.000000000 -0600
@@ -2525,6 +2525,7 @@
app is not None or namespace is not None):
self._key = Key(self._get_kind(), id,
parent=parent, app=app, namespace=namespace)
+ self._is_loaded = False
self._values = {}
self._set_attributes(kwds)
@mentat
mentat / microformats.py
Created March 11, 2012 23:12 — forked from k0001/microformats.py
Python microformats parser that supports hCard, hCalendar, hResume and rel-tag and provides an extensible model for other microformats.
# -*- coding: utf-8 -*-
#!/usr/bin/env python
"""
Model for microformat properties and parsers. A microformat parser can
parse an HTML element into a dictionary of properties, whose keys are
strings and whose values are strings or other dictionary of properties.
As an example, the main program of this script parses an hResume from
given URL.