Skip to content

Instantly share code, notes, and snippets.

View trotzig's full-sized avatar

Henric Trotzig trotzig

View GitHub Profile
@trotzig
trotzig / makeRequest.js
Created January 26, 2018 12:52
JWT creation for happo.io
import request from 'request-promise-native';
import jwt from 'jsonwebtoken';
export default function makeRequest(requestAttributes, { apiKey, apiSecret }) {
const signed = jwt.sign({ key: apiKey }, apiSecret, { header: { kid: apiKey } });
return request(
Object.assign({
auth: {
bearer: signed,
},
import Button from './';
export const primary = () =>
<Button primary>Submit</Button>;
export const secondary = () =>
<Button secondary>Cancel</Button>;
export const disabled = () =>
<Button disabled>Send</Button>;
@trotzig
trotzig / happo-ci.bash
Created October 6, 2017 18:59
An example script for running happo in CI
#!/usr/local/bin/dock bash
# Generates and uploads Happo diffs for the differences between the previous
# and current commit.
set -euo pipefail
PREVIOUS_SHA="$(git rev-parse ${1-HEAD^})"
CURRENT_SHA="$(git rev-parse ${1-HEAD})"
echo "Previous SHA: ${PREVIOUS_SHA}"
echo "Current SHA: ${CURRENT_SHA}"
@trotzig
trotzig / happo_api_endpoints.md
Last active September 28, 2017 16:03
Summary of a discussion Gabe and I've had around happo

Report format:

[{
  component: 'Button', // The name of the component
  variant: 'default', // e.g. 'blue', 'with overflow', 'large', 'without user profile'
  target: 'android', // the combination of platform and viewport. For web, this will be 'firefox-mobile', 'firefox-desktop', 'chrome-desktop', etc. 
  width: 88, // the width of the image, not the viewport
  height: 30, // the height of the image, not the viewport
@trotzig
trotzig / report-format.md
Last active September 14, 2017 08:04
Ideas for a report format for happo

Ideas for a report format for happo

After running happo, a snapshot report file is either created or updated. In it, all tests you have specified are listed, with urls to the screenshots. Here's an example format:

{
   // snapshot-report.json
   '<component-name>': {
     '<variant>': {
 '': 'https://url/to/screenshot',
@trotzig
trotzig / find-dead-js-modules.sh
Last active June 4, 2017 11:00
This script will find javascript modules that aren't currently used in your application.
#!/bin/bash
# Make the script fail on the first error encountered.
set -euo pipefail
# Create a temp folder that we can use to store files in.
if [ "$(uname -s)" = "Darwin" ]; then
tmp_dir=$(mktemp -d -t find-dead-modules.XXXXXXXX)
else
tmp_dir=$(mktemp -d --tmpdir find-dead-modules.XXXXXXXX)
@trotzig
trotzig / proptypes.diff
Created May 18, 2017 12:02
Attempts at fixing custom proptypes
diff --git a/packages/brigade-core/src/test/types/BrigadePropTypes_spec.js b/packages/brigade-core/src/test/types/BrigadePropTypes_spec.js
index 06a395a..26d3749 100644
--- a/packages/brigade-core/src/test/types/BrigadePropTypes_spec.js
+++ b/packages/brigade-core/src/test/types/BrigadePropTypes_spec.js
@@ -7,30 +7,34 @@ import BrigadePropTypes from '../../types/BrigadePropTypes';
function typeCheckFail(declaration, value, message) {
const props = { testProp: value };
- const error = declaration(
- props,
if [ ! -f .ORIGINAL_MAC_ADDRESS ]; then
ifconfig en0 | grep ether | cut -d' ' -f2 > .ORIGINAL_MAC_ADDRESS
echo "Backup of original MAC address saved in .ORIGINAL_MAC_ADDRESS"
fi
if [[ -z "$1" ]]; then
echo "Usage: ./new-mac-address.sh [generate|reset]"
exit 0
fi
import { addEventListener, removeEventListener } from 'consolidated-events';
import React, { PureComponent } from 'react';
/**
* HoC that injects a `contextWidth` prop to the component, equal to the
* available width in the current context
*
* @param {Object} Component
* @return {Object} a wrapped Component
*/
const REGEX_CONST_LET_VAR = /\A(const|let|var)\s+([\s\S]+?)\s*=\s*(w+?)(('|")([^\('|")]+)('|"));?\s*\Z/