I hereby claim:
- I am mitchellrj on github.
- I am mitchell (https://keybase.io/mitchell) on keybase.
- I have a public key whose fingerprint is 7F06 1B87 5590 ED92 5FE4 DCD3 27AA 9799 D267 327E
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
>>> class MetaMeta(object): | |
... def __init__(self): | |
... print ('metameta') | |
... | |
>>> class Meta(MetaMeta): | |
... def __init__(self): | |
... print ('meta1') | |
... | |
>>> class Meta2(MetaMeta): | |
... def __init__(self): |
from tastypie.resources import ModelResource as BaseModelResource | |
class ReadOnlyFieldsAfterAddMeta(BaseModelResource.__metaclass__): | |
def __new__(cls, name, bases, attrs): | |
new_class = super(ReadOnlyFieldsAfterAddMeta, cls).__new__(cls, name, bases, attrs) | |
read_only_fields_after_add = getattr(new_class._meta, 'read_only_after_add', ()) | |
for field_name in read_only_fields_after_add: |
#!/bin/bash | |
# | |
# Usage: watch-and-revert.sh filename | |
# | |
BACKUP="$(dirname $1)/.backup-$(basename $1)" | |
function cleanup { | |
rm $BACKUP | |
} | |
trap cleanup EXIT | |
cat $1 > $BACKUP |
#! /usr/bin/env python | |
# | |
# Copyright 2011 Richard Mitchell | |
# | |
# 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 | |
# |
def constrained_insert(list_, item, before=None, after=None, strict=True): | |
""" Given a list and an item to be inserted into that list, attempts | |
to insert the item into the list in such a way that it is before | |
any items listed in the 'before' argument and after any of those | |
listed in the 'after' argument. If this is not possible, raises | |
a RuntimeError. | |
If any of the values in before or after do not appear in the | |
list, ValueError will be raised, unless 'strict' is set to | |
False. |
#!/bin/bash | |
wp_dir=$1 | |
backup_dir=$2 | |
latest_version=`echo -e "HEAD /latest.tar.gz HTTP/1.1\nHost: wordpress.org\n\n" | \ | |
nc -i 1 wordpress.org 80 | \ | |
grep 'Content-Disposition:' | \ | |
sed 's:.*filename=[A-Za-z-]*\([0-9\.]*\)\.tar\.gz.*:\1:'` | |
current_version=`grep '$wp_version = ' ${wp_dir}/wp-includes/version.php | \ | |
sed "s:.*['\"]\([0-9\.]*\)['\"].*:\1:"` |
#@memoize | |
def get_wf_transitions_for(workflow, from_state, to_state): | |
exit_state_maps = {} | |
for state in workflow.states.objectValues(): | |
for t in state.getTransitions(): | |
exit_state_maps.setdefault(t, []) | |
exit_state_maps[t].append(state.getId()) | |
transition_maps = {} | |
for transition in workflow.transitions.objectValues(): |
from copy import deepcopy | |
def two_way_list_diff(left, right): | |
""" Compares two lists, returns a tuple of two lists detailing | |
which items have been added to the second list and removed | |
from the first list. | |
Example | |
------- |
def wrap_text(text, limit): | |
#s = map(str.split, text.split('\n')) | |
#i = 0 | |
#for n in range(len(s)): | |
# while i < len(s[n]) - 1: | |
# if (len(s[n][i]) + len(s[n][i+1])) <= limit: | |
# s[n][i] += ' ' + s[n][i+1] | |
# s[n] = s[n][:i+1] + s[n][i+2:] | |
# elif len(s[n][i+1]) > limit: | |
# i += 1 |