Skip to content

Instantly share code, notes, and snippets.

View reedobrien's full-sized avatar

Reed O'Brien reedobrien

View GitHub Profile
@reedobrien
reedobrien / traversal.py
Created February 1, 2011 20:13
Tres Traversal placeholder example
"""
On 01/30/2011 09:04 AM, Wade Leftwich wrote:
If you want to stick with Traversal, don't forget that you have
request.subpath available to you. For the path "/blog/archive/
2011/01/29/my-post-about-pyramid", you could have an Archive context
whose default (unnamed) view would be called with a request that
included request.subpath = ['2011', '01', '29', 'my-post-about-
pyramid'].
Other traversal-based strategies:
"""
https://bitbucket.org/ianb/webob/changeset/6b1f2d09fee7#chg-webob/request.py_newline489
self.body_file_raw appears to re-escape characters on each POST
property access
whereas self.body_file does not. I think the latter is the correct
behavior.
I tried to make some failing test for you, but I was struggling
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(flymake-errline ((((class color)) (:underline "OrangeRed"))))
'(flymake-warnline ((((class color)) (:underline "yellow"))))
)
@reedobrien
reedobrien / pyramid_jsonp_renderer.py
Created March 21, 2011 12:44
A jsonp renderer for pyramid
## from http://pastie.org/1695550
def JsonPRendererFactory(info):
"""A special renderer which returns JSONP data.
Be careful to only return data that can be dumped to JSON. In particular
unicode strings may not work.
"""
def render(value, system):
request=system.get("request")
class Category(ContextBySpec):
__name__= None
__collection__ = __parent__ = 'categories'
def __init__(self, request, path_segments=None, **kwd):
super(ContextBySpec, self).__init__(self, request, **kwd)
for k,v in kwd.items():
setattr(self, k, v)
if not path_segments:
path_segments = request.path_info.split('/')
self.__name__ = path_segments.pop(0)
from colander import Email
from colander import Schema
from colander import SchemaNode
from colander import Sequence
from colander import SequenceSchema
from colander import String
from colander import Tuple
from colander import null
from limone_zodb import content_schema
@reedobrien
reedobrien / reset.sh
Created September 7, 2011 01:09
fix "Waiting for other installations to complete." on OSX 10.6 10.7
## fix "Waiting for other installations to complete." on OSX 10.6 10.7
## sometimes a failed installation leaves us unable to
## perform an installation. The following fixes it for me
sudo rm /private/var/db/mds/system/mds.install.lock
sudo reboot
@reedobrien
reedobrien / gist:1238716
Created September 23, 2011 23:31
defor richtext with char count
<textarea id="${field.oid}" class="richtext"
name="${field.name}">${cstruct}</textarea>
<script language="javascript"
type="text/javascript">
deform.addCallback(
'${field.oid}',
function(oid) {
tinyMCE.init({
mode : 'exact',
elements: oid,
def is_really_image(node, value):
request = get_current_request()
tmpstore = MongoTmpStore(request)
image_uid = value['uid']
fp = tmpstore[image_uid]['fp']
fp.seek(0)
try:
Image.open(fp)
except IOError:
raise colander.Invalid(
@reedobrien
reedobrien / gist:1434990
Created December 5, 2011 19:44
image validator
def is_really_image(node, value):
request = get_current_request()
tmpstore = MongoTmpStore(request)
image_uid = value['uid']
fp = tmpstore[image_uid]['fp']
fp.seek(0)
try:
Image.open(fp)
except IOError:
raise colander.Invalid(