Skip to content

Instantly share code, notes, and snippets.

View scottrippey's full-sized avatar

Scott Rippey scottrippey

View GitHub Profile
async function main() {
// Do the thing:
console.log(`
This script copies settings and sign-in creds from prod to dev.
It should prompt you for your system creds (twice), to access the prod creds.
`);
await copyPassword('credentials', 'InVision Studio', 'InVision Studio (Dev)');
await copyAppDataFolder('InVision Studio', 'InVision Studio (Dev)');
function calculatePerpendicularIntersect(centerPosition, startPosition, endPosition) {
const { x: cX, y: cY } = centerPosition;
const { x: sX, y: sY } = startPosition;
const { x: eX, y: eY } = endPosition;
const slopeStart = (cX - sX) / (cY - sY);
const slopePerp = 1 / slopeStart;
const intersectX = (slopeStart * sX - slopePerp * eX + eY - sY) / (slopeStart - slopePerp);
/**
* Waits for an array of promises to finish, and returns an array of the results.
*
* If one or more Promises are rejected, throws a RejectionCollection.
*
* This is very similar to `Promise.all`, except it throws ALL errors, instead of just the FIRST error.
*
* @param {Array<Promise<T>>} promises
* @throws {RejectionCollection}
* @return {Promise<Array<T>>}
@scottrippey
scottrippey / template-helpers example.js
Last active February 13, 2019 10:49
ES6 Template Helpers
import { unindent, repeat, truthy } from "template-helpers";
function createMessage(user, notifications) {
return unindent(truthy`
Hello, ${ user.name }!
${(notifications.length > 0) && truthy`
You have ${ notifications.length } new notification${ (notifications.length > 1) && "s" }.
${repeat(notifications, notification => truthy`
* ${ notification.title } ${ notification.important && "!" }
`)}
@scottrippey
scottrippey / page objects syntax.js
Last active November 25, 2015 17:38
Here are theoretical examples of how "page objects" would work. Looking for an expressive syntax that maximizes the test-writing experience.
describe("page objects", function() {
var loginPage = pageObjects.loginPage;
it("here's what we've got now; page commands and element commands", function() {
return browser
.loginPage_email_setValue("a@b.c")
.loginPage_password_setValue("pass")
.loginPage_loginButton_click()
.loginPage_errorMessage_getText().should.become("Oops, some error")
;
@scottrippey
scottrippey / commands\pages\profile.js
Last active November 9, 2015 19:51
addElementCommands ideas
browser.addElementCommands({
// There are multiple ways to define an element.
// Just a selector:
"profile_Table_": "#table",
// The selector is a function:
"profile_Table_": function getSelector(rowAndColumn){
return "//a[" + rowAndColumn.row + "] span[" + rowAndColumn.column + "]";
},
"profile_Table_": function(rowAndColumn) {
@scottrippey
scottrippey / jasmine-these-2 usage examples.js
Last active August 29, 2015 14:16
Jasmine test cases - "these" - version 2 (supporting message templates)
describe("typeof", function() {
// You can pass in an object of test cases:
these("should output {1} when the input is ", {
"any number": [ 0, "number" ],
"NaN": [ NaN, "number" ],
"undefined": [ undefined, "undefined" ],
"null": [ null, "object" ],
"a Date": [ new Date(), "object" ],
"anon object": [ {}, "object" ],
"anon function": [ function(){}, "object" ],
@scottrippey
scottrippey / jasmine-these usage example.js
Last active August 29, 2015 14:16
Jasmine test cases - "these"
describe("typeof", function() {
these("expects ", {
"0 to output number": [ 0, "number" ],
"NaN to output number": [ NaN, "number" ],
"undefined to output undefined": [ undefined, "undefined" ],
"null to output object": [ null, "object" ],
"Date to output object": [ new Date(), "object" ],
"{} to output object": [ {}, "object" ],
"anon function to output object": [ function(){}, "object" ],
}, function(input, expectedOutput) {
@scottrippey
scottrippey / Readme.md
Created January 30, 2014 21:51
Comparing initConfig versus mergeConfig

For this example, we're building several packages: core-js, core-css, extras-js, and extras-css.

Using grunt.initConfig, you'll see that our packages are completely intermingled. In order, you'll see core-css, core-js, extras-js, extras-css, options, core-js, extras-js, options, core-css, core-js, extras-css, and extras-js.

Using grunt.mergeConfig, the resulting config object is identical. However, each package comprises its own code block, and are completely modular from other packages. In order, you'll see options, core-js, core-css, extras-js, and extras-css.

Any project that builds more than 1 simple package will greatly benefit from this organizational pattern.
For example, Bootstrap's Gruntfile builds 4 separate packages (bootstrap.js, bootstrap.css, bootstrap-theme.css, docs), jQuery UI builds 3 packages (jquery-ui.js, jquery-ui-i18n.js, jquery-ui.css), and practically every significant project builds multiple packages.

@scottrippey
scottrippey / FixedHeader.js
Created August 24, 2012 17:43
Code Review of FixedHeader.js
Uverse.widgets.FixedHeader = new Class({
Implements: [ Options ]
, el: null
, sectionsNavigationSelector: '.sections-navigation'
, _fixedZIndex: 15
, _sectionsNavigation: null
, _regularBodyPaddingTop: null
, _regularMastheadMarginTop: null
, _onScrollHandler: function() {
var bodyPaddingTop;