Skip to content

Instantly share code, notes, and snippets.

@medwards
medwards / .bash_aliases
Last active May 12, 2022 22:14
Things to do at setup
clean_pyc() {
find . -name \*.pyc -delete
find . -name __pycache__ -exec rm -rf "{}" \; 2> /dev/null
}
on_write() {
while inotifywait --exclude .git -qre modify .
do
#eval "$@"
eval "${@/&&/&& ogg123 --quiet /usr/share/sounds/freedesktop/stereo/bell.oga &&}"
[00:17.00]I'm sorry,
[00:19.00]but I don't want to be an emperor,
[00:21.00]that's not my business.
[00:23.00]We have developed speed but we have shut ourselves in.
[00:27.00]Machinery that gives abundance has left us in want.
[00:30.00]Our knowledge has made us cynical, our cleverness hard and unkind.
[00:34.00]We think too much
[00:35.00]and feel too little.
[00:37.00]More than machinery
[00:38.00]we need humanity.
from selenium import webdriver
from time import sleep
foo = webdriver.Firefox()
foo.get('https://rawgithub.com/medwards/salad/master/salad/tests/html/browser/element_waiter.html')
sleep(20)
element = foo.find_element_by_id('appear')
print "Element returned had attribute myattr with value %s when it should be %s" % (element.get_attribute('myattr'), 'you')
foo.quit()
<html>
<body id="test">
<div id="element" style="display: none">foobar</div>
<a href="#" onclick="triggerMe(); return false;">reveal</a>
<a href="#" onclick="triggerMeToo(); return false;">wipe</a>
<script type="text/javascript">
function triggerMe() {
document.getElementById("element").style.display = 'block';
}
@medwards
medwards / enricher.py
Created January 24, 2013 17:42
Trying to extract a dependency
def add_foos(stuff):
for thing in stuff:
thing['foo'] = float(thing['id']) * 2.0
return stuff
class ConnectorThing(object):
result_enricher = add_foos
def get_results(self):
# do something
bar = [{'id': 1}, {'id': 2}, {'id': 3}]
@medwards
medwards / repro.py
Created January 16, 2013 14:46
Uses is_displayed_bug.html
from selenium import webdriver
from time import sleep
foo = webdriver.Firefox()
foo.get('file:///tmp/is_displayed_bug.html')
sleep(5)
element = foo.find_element_by_id('loading_status')
print "Element returned was %s with visibility equal to %s" % (element.text,
element.is_displayed())
foo.quit()
@medwards
medwards / is_displayed_bug.html
Created January 16, 2013 14:35
Selenium is_displayed defect reproduction: Launch the browser and page, after two seconds the 'Loading' message should be replaced by a 'Ready!' message, then: browser.find_element_by_id('loading_status').is_displayed()
<html>
<body>
<div id="ready_status" style="display: none">
Ready!
</div>
<div id="loading_status" style="overflow: hidden">
Loading....
</div>
<div id="something" style="display: none"></div>
<script type="text/javascript">
@medwards
medwards / gist:4155969
Created November 27, 2012 18:10
Tests pass. But ick.
diff --git a/tests/async_finder.py b/tests/async_finder.py
index f26dc1a..7bf7265 100644
--- a/tests/async_finder.py
+++ b/tests/async_finder.py
@@ -3,7 +3,7 @@
# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-
+from time import sleep
@medwards
medwards / test.py
Created October 26, 2012 09:52
Doesn't produce output :(
import subprocess
def print_output(command):
try:
subprocess.check_output(command, shell=0)
except subprocess.CalledProcessError as e:
print e.output
print_output(['echo', 'bleh'])
@medwards
medwards / test_blueprint.py
Created September 21, 2012 08:48
nosetests skeleton
# ? from ourapp.app import app
import unittest
from nose.tools import assert_equals
class BlueprintTestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass