Skip to content

Instantly share code, notes, and snippets.

View mitchellrj's full-sized avatar

Richard Mitchell mitchellrj

View GitHub Profile
HOMEBREW_VERSION: 0.9
HEAD: 55d79f45121f2739b7df7125be8a27eacc28d292
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit sandybridge
OS X: 10.7.4
Kernel Architecture: x86_64
Xcode: 4.3.2
GCC-4.0: N/A
GCC-4.2: N/A
@mitchellrj
mitchellrj / normalized_cmp.py
Created May 26, 2012 09:08
Normalized cmp for sorting lists of strings with accents
import unicodedata
def normalized_cmp(x, y):
if isinstance(x, unicode) and isinstance(y, unicode):
normalized_x = ([c for c in unicodedata.normalize('NFKD', x) if not unicodedata.combining(c)] + [''])[0]
normalized_y = ([c for c in unicodedata.normalize('NFKD', y) if not unicodedata.combining(c)] + [''])[0]
return cmp(normalized_x, normalized_y)
@mitchellrj
mitchellrj / brew --config.log
Created May 22, 2012 15:28
coreutils upgrade failure
HOMEBREW_VERSION: 0.9
HEAD: 9d50a0ca0448c14bbdaa8f027b08b2cde6d90f08
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit sandybridge
OS X: 10.7.4
Kernel Architecture: x86_64
Xcode: 4.3.2
GCC-4.0: N/A
GCC-4.2: N/A
@mitchellrj
mitchellrj / brew --config.log
Created May 22, 2012 15:11
Brew ffmpeg upgrade failure
HOMEBREW_VERSION: 0.9
HEAD: 9d50a0ca0448c14bbdaa8f027b08b2cde6d90f08
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit sandybridge
OS X: 10.7.4
Kernel Architecture: x86_64
Xcode: 4.3.2
GCC-4.0: N/A
GCC-4.2: N/A
@mitchellrj
mitchellrj / echoserver_example.py
Created April 23, 2012 14:55
WebSocket response object for WebOb with echoserver example
class EchoWebSocketResponse(BaseWebSocketResponse):
def after_open(self):
self.receive_until_closed()
def handle_text(self, text):
self.send_text(text)
def handle_request(self, request):
@mitchellrj
mitchellrj / configure.zcml
Created April 10, 2012 10:27
Make Plone object undeletable but still work with iterate / stagingbehavior
<configure xmlns="http://namespaces.zope.org/zope">
<subscriber
for=".interfaces.IMyType
OFS.interfaces.IObjectWillBeRemovedEvent"
handler=".events.event_handler"
/>
</configure>
@mitchellrj
mitchellrj / clear_davlocks.py
Created April 4, 2012 14:22
Clear WebDAV locks
def unlockAllObjects(app, path):
lockedobjs = findLockedObjects(app, path)
for (o, p, i) in lockedobjs:
errs = False
for l in [li['token'] for li in i]:
try:
o.wl_delLock(l)
except:
errs = True
if errs:
@mitchellrj
mitchellrj / clear_comments.py
Created March 16, 2012 18:25
Clear all plone.app.discussion comments
catalog_interfaces = ('plone.app.discussion.interfaces.IComment',)
pc = context.portal_catalog
comment_brains = pc(object_provides=tuple(catalog_interfaces))
for b in comment_brains:
comment = b.getObject()
comment_id = comment.comment_id
conversation = comment.aq_parent
@mitchellrj
mitchellrj / plone-2.1.1.cfg
Created March 9, 2012 15:10
Example buildout for Plone 2.1.1
[buildout]
extends = versions.cfg
parts =
plone
zope2
productdistros
instance
live-client
omelette
@mitchellrj
mitchellrj / strftime_1900.py
Created March 8, 2012 12:42
Python datetime.strftime < 1900 workaround
import datetime
import re
import warnings
def strftime(dt, fmt):
if dt.year < 1900:
# create a copy of this datetime, just in case, then set the year to
# something acceptable, then replace that year in the resulting string
tmp_dt = datetime.datetime(datetime.MAXYEAR, dt.month, dt.day,
dt.hour, dt.minute,