Skip to content

Instantly share code, notes, and snippets.

View philmander's full-sized avatar

Phil Mander philmander

View GitHub Profile
@philmander
philmander / custom-given.js
Last active November 12, 2019 10:27
Bat talk snippets
Given('I do a custom login', function(credentials) {
const { username, password } = credentials;
const agent = this.currentAgent;
await agent
.post(this.replaceVars(`${base}/api/login`));
.send({
username,
password,
});
const { getRandomWord } = require('word-maker');
const getFizzBuzz = n => `${n % 3 === 0 ? 'Fizz' : ''}${n % 5 === 0 ? 'Buzz' : ''}`;
async function getResults() {
const promises = Array(100).fill().map(async (v, i) => {
i++;
try {
return `${i}: ${getFizzBuzz(i) || await getRandomWord({ withErrors: true })}`;
} catch (err) {
@philmander
philmander / disable-line.js
Last active November 14, 2022 15:41
ESLint Cheatsheet
parseInt(10); // eslint-disable-line rule-name
import { createRouter } from 'router';
const router = createRouter([
{
path: '/foo:/
view: <MyComponent />
enter: ({ foo }) => store.loadVenue(foo);
},
paths: [ '/foo:/', 'bar:/' ],
view: <SomethingElse />
@philmander
philmander / server-stream.js
Created December 31, 2017 00:52
Send to server stream for Browser Bunyan
const userAgent = typeof window !== 'undefined' ? window.navigator.userAgent : 'no-window';
const isBot = /bot|crawler|spider|crawling/i.test(userAgent);
export class ServerLogStream {
constructor(opts = {}) {
const {
writeCondition = ServerLogStream.defaultWriteCondition,
} = opts;
@philmander
philmander / nav.jsx
Last active August 1, 2020 15:49
Simple Preact Unit Testing with Jest (with shallow rendering)
import { h, Component } from 'preact';
import { Link } from 'preact-router/match';
class Nav extends Component {
constructor() {
super();
this.state.title = 'Navigation'
}
@philmander
philmander / casperjs-website-resolution-tester.js
Created October 4, 2015 16:30
CasperJS Website Resolution Tester
var casper = require('casper').create({
verbose: true,
logLevel: 'info'
});
var page = require('webpage').create();
var utils = require('utils');
//args
var base = casper.cli.get('out');
var width = parseInt(casper.cli.get("width"));
@philmander
philmander / reduce-array-to-html.js
Last active August 29, 2015 14:12
Object array to html string with Array.reduce()
var items = [{
html: '<p>One</p>'
}, {
html: '<p>Two</p>'
}, {
html: '<p>Three</p>'
}];
var html = items.reduce(function(html, item) {
html.push(item.html);
@philmander
philmander / gulpdir
Created July 3, 2014 13:36
Litlle function for concatenating file names in gulp
//little util to do tidier directory concatenation
function dir() {
var args = Array.prototype.slice.call(arguments);
var prefix = "";
if(args[0] === "!") {
prefix = args[0];
args.shift();
}
return prefix + args.join("/");
}
@philmander
philmander / casper.test.assertMicrodata.js
Last active August 29, 2015 13:58
Assert Microdata test util for Casper JS. Requires https://gist.github.com/philmander/10012466
/**
* Asserts a microdata item value matches the given expected value in the remote DOM environment
* Depends on the casper.fetchMicrodata method
*
* @param itemType {String} The item type of the item scopes to look for properties in
* @param property {String} The name of the property the compare the expected value against
* @param expectedItemValue {String} The expected value of the item property
* @param message {String} The assertion message
* @param itemTypeIndex {Number} A specific index of an item scope to use. If omitted or null, will look for matches in
* all item scopes