-
Open a browser
# start an instance of firefox with selenium-webdriver driver = Selenium::WebDriver.for :firefox # :chrome -> chrome # :ie -> iexplore
- Go to a specified URL
def elem2dict(node): | |
""" | |
Convert an lxml.etree node tree into a dict. | |
""" | |
d = {} | |
for e in node.iterchildren(): | |
key = e.tag.split('}')[1] if '}' in e.tag else e.tag | |
value = e.text if e.text else elem2dict(e) | |
d[key] = value | |
return d |
/** | |
* This is from community accepted conventions and feel free to judge upon them. | |
* | |
* Upon Method Invocation chaining, one can prefer the 'fooIndent' method over 'fooNotIndent' | |
* (as well as barIndent over barNotIndent), | |
* Not only it improves readibility upon reading (by gradually grasping the functionality) but also it does not consume | |
* the whole screen (thus not making you scroll). | |
* | |
* The use of '.' upon invocation is debatable. | |
* Some argue that the leading '.' should be removed [2] |
#!/usr/bin/env python | |
""" | |
Copyright 2011 Domen Kozar. All rights reserved. | |
Redistribution and use in source and binary forms, with or without modification, are | |
permitted provided that the following conditions are met: | |
1. Redistributions of source code must retain the above copyright notice, this list of | |
conditions and the following disclaimer. |
### Locating UI elements ### | |
# By ID | |
<div id="coolestWidgetEvah">...</div> | |
element = driver.find_element_by_id("coolestWidgetEvah") | |
or | |
from selenium.webdriver.common.by import By | |
element = driver.find_element(by=By.ID, value="coolestWidgetEvah") | |
# By class name: |
/** | |
* Home mande method to do array_diff ~10x faster that PHP built-in. | |
* | |
* @param The array to compare from | |
* @param An array to compare against | |
* | |
* @return an array containing all the entries from array1 that are not present in array2. | |
*/ | |
function nuno_array_diff($array1, $array2) { | |
$diff = array(); |
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
#!/usr/bin/env python3 | |
"""A simple python script template. | |
""" | |
import os | |
import sys | |
import argparse |
A warning occurred (42 apples) | |
An error occurred |
// Based on shapeless 1.2.2 | |
import shapeless._, HList._ | |
trait RecIso[T, R] { | |
def iso(t: T) : R | |
} | |
trait RecId[T] extends RecIso[T, T] { | |
def iso(t: T) : T = t | |
} |