This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_setting(source, setting, unquote=True): | |
re_setting = r'^\s*' + re.escape(setting) + r'\s*=\s*(.+)$' | |
m = re.search(re_setting, source, re.M) | |
if not m: | |
return None | |
value = m.group(1).strip() | |
if unquote: | |
if value.startswith("'") and value.endswith("'") or \ | |
value.startswith('"') and value.endswith('"'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE | |
def local2(command, print_command=False): | |
"Run a command, returning the exit code, output, and stderr." | |
p = Popen(command, stdout=PIPE, stderr=PIPE) | |
if print_command: print " ".join(command) | |
output, errput = p.communicate() | |
return p.returncode, output, errput |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def local2(command, print_command=False): | |
"Run a command, returning the exit code, output, and stderr." | |
from subprocess import Popen, PIPE | |
p = Popen(command, stdout=PIPE, stderr=PIPE) | |
if print_command: print " ".join(command) | |
output, errput = p.communicate() | |
return p.returncode, output, errput | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_warning(msg): | |
print fabric.colors.red("WARNING: ") + msg | |
def print_error(msg): | |
print fabric.colors.red("ERROR: ") + msg | |
def print_label(msg): | |
print fabric.colors.blue("==> ", bold=True) + msg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from django.contrib.auth.admin import UserAdmin | |
from django.contrib.auth.forms import UserCreationForm, UserChangeForm | |
from django.contrib.auth.models import Group, User | |
# Override username field require email address | |
class UserCreationForm2(UserCreationForm): | |
email = forms.CharField(max_length=75, required=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib | |
import urllib | |
class WebServer(object): | |
def __init__(self, host): | |
self.host = host | |
def _make_request(self, method, url, data, headers): | |
conn = httplib.HTTPConnection(self.host) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.ConcurrentLinkedQueue; | |
import java.util.concurrent.atomic.AtomicReference; | |
public class PairedList<T> { | |
private ConcurrentLinkedQueue<T> list1; | |
private ConcurrentLinkedQueue<T> list2; | |
private AtomicReference<ConcurrentLinkedQueue<T>> activeList; | |
public PairedList() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RetryCounter { | |
private final int maxAttempts; | |
private int attempts; | |
private boolean successful; | |
public RetryCounter(final int maxAttempts) { | |
this.maxAttempts = maxAttempts; | |
this.attempts = 0; | |
this.successful = false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows an operation to be retried up to a maximum number of tries. | |
*/ | |
public class RetryCounter { | |
/** The maximum number of retries. */ | |
private final int maxAttempts; | |
/** The number of attempts so far. */ | |
private int attempts; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A Counter can issue sequential ids, and return the largest id issued so far. | |
*/ | |
public class Counter { | |
private long nextValue = 0; | |
/** | |
* @return the next value from this counter. | |
*/ | |
public long nextValue() { |