Skip to content

Instantly share code, notes, and snippets.

@casschin
casschin / gist:1990245
Created March 7, 2012 01:16
Python webdriver api quick sheet
### 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:
@casschin
casschin / mozillabased.py
Created May 24, 2013 23:20
Abridged version of Mozilla based page tests
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from selenium.webdriver.common.by import By
from pages.desktop.base import Base
class MozillaBasedPage(Base):

Keybase proof

I hereby claim:

  • I am casschin on github.
  • I am cass (https://keybase.io/cass) on keybase.
  • I have a public key whose fingerprint is BD4F C251 781F 90F5 9630 0489 36F5 8E7E EE99 9AF5

To claim this, I am signing this object:

@casschin
casschin / example.js
Created October 21, 2018 21:26
Simple async/await example
function logFirst() {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(console.log("first")), 300);
});
}
function logSecond() {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(console.log("second")), 100);
});
}
@casschin
casschin / oneHundredPercent.js
Last active March 1, 2019 16:18
Sum percentages to 100%
// Stolen from: https://revs.runtime-revolution.com/getting-100-with-rounded-percentages-273ffa70252b
export const processDatasetWithAdjustedPercentages = dataset => {
// get the total count to caluclate the actual percentage
const totalCount = dataset.reduce((acc, data) => acc + data.value, 0);
// map the dataset and add properties for the percentage values we'll need
const datasetWithPercentages = dataset.map(data => {
const rawPercentage = (data.value / totalCount) * 100; // ex: 43.234235235
const floorPercentage = Math.floor(rawPercentage); // ex: 43
@casschin
casschin / reorderList.ts
Created December 5, 2019 02:43
reordering function
// function that will allow you to move an item within a list and will reposition the other items accordingly
type ListItem = {
label: string;
pos: number;
}
const list = [
{
label: "a",
@casschin
casschin / poll.js
Created November 19, 2020 04:28
polling function with the ability to cancel
function poll({ fn, validate, interval = 1000, maxAttempts = 100 }) {
let attempts = 0;
let stop = false;
async function execute(resolve, reject) {
const res = await fn();
attempts += 1;
if (validate(res)) {
resolve(res);
} else if (maxAttempts === attempts) {
return reject("Hit max poll attempts");