-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare to auto-deploy minified userscripts to gists
- Loading branch information
1 parent
5c86213
commit ad2587e
Showing
16 changed files
with
760 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ nerdwallet/* | |
wikipedia/*.css | ||
dist/ | ||
coverage/ | ||
deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// ==UserScript== | ||
// @name Get Test Execution Times | ||
// @namespace http://tampermonkey.net/ | ||
// @version 0.1 | ||
// @description Make a table of test execution times | ||
// @author Josh Parker | ||
// @match https://bitbucket-pipelines.prod.public.atl-paas.net/Pipelines/home | ||
// @icon https://www.google.com/s2/favicons?sz=64&domain=bitbucket.org | ||
// @grant none | ||
// ==/UserScript== | ||
|
||
(function testExecutionTimes() { | ||
const parser = new DOMParser(); | ||
|
||
const nextSelector = 'button[aria-label=Next]'; | ||
|
||
const pages = [document]; | ||
let { href } = window.location; | ||
|
||
const getNext = function getNext(next) { | ||
return new Promise((resolve, reject) => { | ||
if (!next || next.disabled) { | ||
resolve(); | ||
} | ||
|
||
const match = href.match(/(.*)\/(\d+)$/); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
const [_, url, page] = match; | ||
href = `${url}${Number(page) + 1}`; | ||
fetch(href) | ||
.then((r) => r.text()) | ||
.then((text) => parser.parseFromString(text, 'text/html')) | ||
.then((dom) => { | ||
pages.push(dom); | ||
resolve(dom.querySelector(nextSelector)); | ||
}) | ||
.catch(() => reject()); | ||
}) | ||
.then((n) => n && getNext(n)); | ||
}; | ||
|
||
getNext(document.querySelector(nextSelector)); | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const { Octokit } = require('@octokit/core'); | ||
const { createActionAuth } = require('@octokit/auth-action'); | ||
const globber = require('glob'); | ||
const { readFile } = require('fs'); | ||
|
||
const pattern = './@(dist)/**/*.@(user|meta).js'; | ||
|
||
const glob = (globPattern) => (new Promise((r) => { globber(globPattern, (_, s) => r(s)); })); | ||
|
||
const octokit = new Octokit({ | ||
authStrategy: createActionAuth, | ||
}); | ||
|
||
glob(pattern) | ||
.then((files) => { | ||
const upload = function upload(i = 0) { | ||
if (i < files.length) { | ||
const file = files[i]; | ||
readFile(file, (err, contentBuffer) => { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
const content = contentBuffer.toString(); | ||
const gistId = content.match(/downloadURL.*joshparkerj\/([^/]*)/)[1]; | ||
const description = content.match(/description\s+(.*)/)[1]; | ||
const filename = file.includes('meta') ? content.match(/updateURL.*raw\/[^/]+\/([^/]*)/)[1] : content.match(/downloadURL.*raw\/[^/]+\/([^/]*)/)[1]; | ||
|
||
console.log(content); | ||
console.log(gistId); | ||
console.log(description); | ||
console.log(filename); | ||
octokit.request(`PATCH /gists/${gistId}`, { | ||
gist_id: gistId, | ||
description, | ||
files: { | ||
[filename]: { | ||
filename, | ||
content, | ||
}, | ||
}, | ||
}) | ||
.then(() => { | ||
upload(i + 1); | ||
}); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
upload(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* eslint-disable no-param-reassign */ | ||
const challenge = { | ||
init: (elevators, floors) => { | ||
const elevatorQueue = []; | ||
|
||
const setIndicator = { | ||
up: (e) => { e.goingUpIndicator(true); e.goingDownIndicator(false); }, | ||
down: (e) => { e.goingUpIndicator(false); e.goingDownIndicator(true); }, | ||
}; | ||
|
||
const floorButton = (floorNum) => { | ||
const floor = floors.find(({ level }) => level === floorNum); | ||
const { buttonStates: { up, down } } = floor; | ||
if (up.length) { | ||
return 'up'; | ||
} | ||
|
||
if (down.length) { | ||
return 'down'; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
const go = (elevator, n) => { | ||
const currentFloor = elevator.currentFloor(); | ||
const button = floorButton(n); | ||
if (button) setIndicator[button](elevator); | ||
else if (n < currentFloor) setIndicator.down(elevator); | ||
else if (n > currentFloor) setIndicator.up(elevator); | ||
|
||
elevator.goToFloor(n); | ||
|
||
elevator.destinationQueue = [...(new Set(elevator.destinationQueue))] | ||
.sort((a, b) => (elevator.goingUpIndicator() ? a - b : b - a)); | ||
|
||
elevator.checkDestinationQueue(); | ||
}; | ||
|
||
const isFull = (e) => Math.round(e.maxPassengerCount() * (1 - e.loadFactor())) <= 1; | ||
|
||
const handleFull = (e) => { | ||
if (isFull(e)) { | ||
e.destinationQueue = []; | ||
console.log(e.getPressedFloors()); | ||
e.getPressedFloors().forEach((n) => go(e, n)); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
const serve = (elevator, dir, comp, sorter) => { | ||
const filteredFloors = floors | ||
.filter(({ level }) => ( | ||
comp(level, elevator.currentFloor()) | ||
&& (floorButton(level) === dir))) | ||
.sort(sorter); | ||
|
||
if (filteredFloors.length) { | ||
filteredFloors.forEach(({ level }) => go(elevator, level)); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
const nextPickup = (e) => { | ||
const floorNum = e.currentFloor(); | ||
const dist = (n) => Math.abs(floorNum - n); | ||
const filteredFloors = floors | ||
.filter(({ level }) => floorButton(level)) | ||
.sort(({ level: a }, { level: b }) => dist(a) - dist(b)); | ||
|
||
if (filteredFloors.length === 0) { | ||
return () => false; | ||
} | ||
|
||
const { level } = filteredFloors[0]; | ||
const button = floorButton(level); | ||
|
||
if (level > floorNum) { | ||
return (elevator) => serve( | ||
elevator, | ||
button, | ||
(l, f) => l >= f, | ||
({ level: a }, { level: b }) => (button === 'up' ? a - b : b - a), | ||
); | ||
} | ||
|
||
return (elevator) => serve( | ||
elevator, | ||
button, | ||
(l, f) => l <= f, | ||
({ level: a }, { level: b }) => (button === 'up' ? a - b : b - a), | ||
); | ||
}; | ||
|
||
if (elevators.length > 1) { | ||
elevators.forEach((elevator, i) => { | ||
const maxFloor = Math.max(...floors.map(({ level }) => level)); | ||
elevator.goToFloor(Math.round(maxFloor * (i / (elevators.length - 1)))); | ||
}); | ||
} | ||
|
||
elevators.forEach((elevator) => { | ||
elevator.on('idle', () => { | ||
if (!nextPickup(elevator)(elevator)) { | ||
elevatorQueue.push(elevator); | ||
} | ||
}); | ||
|
||
elevator.on('floor_button_pressed', (floorNum) => { | ||
if (!handleFull(elevator)) { | ||
go(elevator, floorNum); | ||
} | ||
}); | ||
|
||
elevator.on('passing_floor', (floorNum, dir) => { | ||
if ( | ||
(!handleFull(elevator)) | ||
&& (floors.find(({ level }) => level === floorNum).buttonStates[dir].length) | ||
) { | ||
go(elevator, floorNum); | ||
} | ||
}); | ||
|
||
elevator.on('stopped_at_floor', () => { | ||
handleFull(elevator); | ||
}); | ||
}); | ||
|
||
const handleButtonPressed = (n) => { | ||
if (elevatorQueue.length > 0) { | ||
go(elevatorQueue.shift(), n); | ||
} | ||
}; | ||
|
||
floors.forEach((floor) => { | ||
floor.on('up_button_pressed', () => handleButtonPressed(floor.floorNum())); | ||
floor.on('down_button_pressed', () => handleButtonPressed(floor.floorNum())); | ||
}); | ||
}, | ||
update: () => { }, | ||
}; | ||
|
||
module.exports = challenge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable max-len */ | ||
/* eslint-disable prefer-rest-params */ | ||
const func = function func() { | ||
const callback = arguments[arguments.length - 1]; | ||
fetch('/api/v1/view?viewType=PRINCIPAL') | ||
.then((r) => r.json()) | ||
.then(({ | ||
user: { | ||
person: { | ||
givenName, familyName, homeAddress, mobilePhone, birthDate, | ||
}, | ||
}, | ||
}) => { | ||
const givenNameMatch = givenName === arguments[0]; | ||
const familyNameMatch = familyName === arguments[1]; | ||
const addressLine1Match = homeAddress?.streetAddressLine1 === arguments[2]; | ||
const addressLine2Match = homeAddress?.streetAddressLine2 === arguments[3]; | ||
const cityMatch = homeAddress?.citySuburb === arguments[4]; | ||
const stateMatch = homeAddress?.stateProvinceRegion === arguments[5]; | ||
const phoneMatch = mobilePhone.value.replace(/\D+/g, '') === arguments[6]; | ||
const zipMatch = homeAddress.postalCode.startsWith(arguments[7]); | ||
const birthDateMatch = birthDate === arguments[8]; | ||
callback( | ||
givenNameMatch && familyNameMatch && addressLine1Match && addressLine2Match && cityMatch && stateMatch && phoneMatch && zipMatch && birthDateMatch, | ||
); | ||
}) | ||
.catch((err) => { console.error(err); callback(null); }); | ||
}; | ||
|
||
module.exports = func; |
Oops, something went wrong.