Skip to content

Instantly share code, notes, and snippets.

View philmander's full-sized avatar

Phil Mander philmander

View GitHub Profile
@philmander
philmander / disable-line.js
Last active November 14, 2022 15:41
ESLint Cheatsheet
parseInt(10); // eslint-disable-line rule-name
@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 / 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) {
import { createRouter } from 'router';
const router = createRouter([
{
path: '/foo:/
view: <MyComponent />
enter: ({ foo }) => store.loadVenue(foo);
},
paths: [ '/foo:/', 'bar:/' ],
view: <SomethingElse />
@philmander
philmander / inverted-intro-1-1.js
Last active January 19, 2016 14:32
First inverted intro with no dependency injection
// movies/movie-lister.js
define(["movies/json-movie-finder"], function(MovieFinder) {
var MovieLister = function() {
//hard coded dependency
this.movieFinder = new MovieFinder();
};
MovieLister.prototype.showMovies = function(query) {
// Mixed.js
define(function() {
var Mixed = function(a, b) {
this.a = a;
this.b = b;
};
Mixed.prototype.getA = function() {
return this.a;
};
Mixed.prototype.getB = function() {
//app-config.js
define(function() {
return {
protos: {
movieLister: {
module: "movies/movie-lister",
args: [
"*movieFinder"
]
mixin: {
@philmander
philmander / inverted-interface-1.js
Last active December 11, 2015 00:09
Demonstrates using an interface in the app config
//app-config.js
define(function() {
return {
protos: {
movieLister: {
module: "movies/movie-lister",
args: [
//injects a json movie finder which must implement the movieFinder interface
"*jsonMovieFinder [movieFinder]"
]