Skip to content

Instantly share code, notes, and snippets.

@nhilderink
nhilderink / Explicit wait
Created June 2, 2017 07:15
An explicit wait sample. To be used in selenium tests, instead of implicit waits.
def wait_for_row_in_list_table(self, row_text):
start_time = time.time()
while True:
try:
table = self.browser.find_element_by_id("id_list_table")
rows = table.find_elements_by_tag_name("tr")
self.assertIn(row_text, [row.text for row in rows])
return
except (AssertionError, WebDriverException) as e:
if time.time() - start_time > MAX_WAIT:
@nhilderink
nhilderink / provision-digitalocean.sh
Last active May 14, 2017 06:47 — forked from sheikhwaqas/setup-mysql.sh
Install MySQL Server on Ubuntu (Non-Interactive Installation)
# Vagrant provision script for Digital Ocean
# Creates a basic nginx/uwsgi/django/mysql box
echo "Provisioning from gist"
# Download and Install the Latest Updates for the OS
apt-get update && apt-get upgrade -y
# Set the Server Timezone to Europe/Amsterdam
echo "Europe/Amsterdam" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
def clip(text: str, max_len:'int > 0'=80) -> str:
"""Return text clipped at the last space before or after max_len"""
end = None
if len(text) > max_len:
space_before = text.rfind(' ', 0, max_len)
if space_before >= 0:
end = space_before
else:
space_after = text.rfind(' ', max_len)