Skip to content

Instantly share code, notes, and snippets.

View kpittman-securus's full-sized avatar

kpittman-securus

View GitHub Profile
@kpittman-securus
kpittman-securus / pipe.js
Created May 11, 2021 17:40
Pipe in plain JS
const pipe = (...funcs) => (...args) => funcs.reduce((prev, cur) => cur(prev), ...args);
const add2 = (x) => x+2;
const times5 = (x) => x*5;
const minus8 = (x) => x-8;
const fn = pipe(times5, add2, minus8, times5, minus8);
console.log([1,2,3,4,5].map(fn));
@kpittman-securus
kpittman-securus / openFailedPRs.js
Last active May 11, 2021 17:45
With Jenkins/GitHub integration, open all failed PRs in Jenkins (from the GitHub pull requests page)
let pipe = (...funcs) => (...args) => funcs.reduce((prev, cur) => cur(prev), ...args);
let getAllPrs = () => Array.from(document.querySelectorAll('div[id^=issue]'));
let getPrNumber = (el) => el.querySelector('input[type=checkbox]').value;
let getFailedPrs = () => getAllPrs().filter((el) => el.querySelector('a.color-text-danger'));
let makeJenkinsUrl = (pr) =>
`https://jenkins-example.com/job/PR-${pr}/lastBuild/`;
let open = (url) => window.open(url);
let openPr = pipe(getPrNumber, makeJenkinsUrl, open);
let openFailedPrs = () => getFailedPrs().map(openPr);
@kpittman-securus
kpittman-securus / addSizzle.js
Created May 6, 2021 20:43
Add Sizzle to window (jQuery selector engine)
const sizzleScript = document.createElement('script');
sizzleScript.src = 'https://cdn.jsdelivr.net/npm/sizzle@latest/dist/sizzle.min.js';
document.getElementsByTagName('head')[0].appendChild(sizzleScript);
window.sz = window.Sizzle;
@kpittman-securus
kpittman-securus / cypress.sh
Created April 28, 2021 23:26
Open Cypress without watching for changes
alias cypress="npx cypress open --config watchForFileChanges=false"
@kpittman-securus
kpittman-securus / cleanupPR.js
Last active May 7, 2021 21:20
Mark deleted as viewed, sort all files by number of changes
const container = $('#files');
const files = Array.from($$('.file'));
const getSortText = (el) => parseInt(el.querySelector('.diffstat').innerText);
files.sort((a, b) => {
const aSortText = getSortText(a);
const bSortText = getSortText(b);
if (aSortText > bSortText) return 1;
if (aSortText < bSortText) return -1;
return 0;
});
@kpittman-securus
kpittman-securus / deploy.ts
Created April 6, 2021 15:02
NewRelic deploy via browser JS
step('Trigger NewRelic marker', async (b: Browser) => {
const description = `Flood run started - ${ENV.FLOOD_SEQUENCE_ID}`;
await b.page.evaluate(
(_description, sequenceId) => {
const applicationId = '123';
fetch(`https://api.newrelic.com/v2/applications/${applicationId}/deployments.json`, {
method: 'POST',
body: JSON.stringify({
deployment: {
description: _description,
@kpittman-securus
kpittman-securus / build.sh
Last active April 28, 2021 23:20
Parallel execution with find and xargs
#! /usr/bin/env bash
find ./src/bookmarklets -name "*.js" -print0 | xargs -I FILE -0 -P "$(nproc)" npm run rollup -- --input "FILE" --file "output/FILE"
# EDIT: Per my latest comment - I now prefer this:
for bookmarklet in ./src/bookmarklets/**/*.js
do
npm run rollup -- --input "$bookmarklet" --file "output/$bookmarklet" &
done
wait
const keymap = <T extends unknown, U extends object>(
object: U,
callback: (key: keyof U, index: number) => T
) => (Object.keys(object) as (keyof U)[]).map(callback);