Skip to content

Instantly share code, notes, and snippets.

@YoniTsafir
Created April 3, 2011 19:21
Show Gist options
  • Save YoniTsafir/900694 to your computer and use it in GitHub Desktop.
Save YoniTsafir/900694 to your computer and use it in GitHub Desktop.
Code Sheriff's Code Examples
public interface ConditionTester {
boolean isTrue();
}
public static void delayedAssert(ConditionTester tester,
long timeout,
long pollingInterval)
throws InterruptedException {
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < timeout) {
if (tester.isTrue()) {
return;
}
Thread.sleep(pollingInterval);
}
fail("Timeout passed and condition failed!");
}
def testDevicePrettifierForAllLocalDevices(self):
dev_strings = get_all_device_strings()
for dev_str in dev_strings:
try:
device = Device.from_path(dev_str)
except DeviceAccessPermissionsError:
# Chained: a trick we made to raise nested exceptions in Python 2.x
raise chained(SkipTest("No permissions to file (are you root?)"))
dev_prettifier = DevicePrettifier(device)
print
print dev_str
print dev_prettifier
public class StringSerializer {
private DBSerializer dbDumper;
public StringSerializer(String tableName) throws SQLException {
Connection conn = ConnectionManager.instance().getAvailableConnection();
dbDumper = new DBSerializer(conn, tableName);
}
public void serializeString(String str) throws DumpException {
dbDumper.dump(str);
}
}
public class StringSerializer {
private Serializer dumper;
public StringSerializer(Serializer dumper) {
this.dumper = dumper;
}
public void serializeString(String str) throws DumpException {
dumper.dump(str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment