Skip to content

Instantly share code, notes, and snippets.

☕️
Writing code

Cory Reed swashcap

☕️
Writing code
Block or report user

Report or block swashcap

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View runtime-selector-assertion.md

Tooling idea: collect all the available CSS selectors:

const selectors = new Set<string>(document.styleSheets.reduce<string[]>(
	(acc, { rules }) => [...acc, ...rules.map(({ selectorText }) => selectorText)],
	[]
))

export function assertSelectors(...args: string[]) {
	args.forEach((selector) => {
View relative-require.js
/**
* Update relative `require`s in Node.js to use the minimal number of `../` path
* pieces.
*
* Usage:
*
* ```shell
* node relative-require.js path/to/my/file.js
* ```
*/
View reselect-and-get.js
const assert = require('assert')
const get = require('lodash/fp/get')
const { createSelector } = require('reselect')
const list = get('list')
const getId = createSelector(
list,
get('id')
)
View hapi-listener-assertions.js
const assert = require("assert");
const hapi = require("hapi");
const http = require("http");
const getRootHandler = response => ({
handler() {
return response;
},
method: "GET",
path: "/"
@swashcap
swashcap / startup.sh
Created Mar 9, 2019
Server Startup Time
View startup.sh
#!/bin/bash
set -eo pipefail
#
# Test server startup times using crude scripting
#
# Use:
#
# time CMD="npm start" URL=localhost:3000 ./startup.sh
#
View SketchSystems.spec
Welcome*
Owner
dashboard -> Dashboard
Non-Owner
create -> Create
find -> Search Results
Auth
redirect -> Create
Create
Authorized
@swashcap
swashcap / custom-error-creation.ts
Last active Nov 27, 2018
Exploring custom error creation with TypeScript
View custom-error-creation.ts
import assert from 'assert';
interface CreateErrorOptions {
/** Additional error data */
data?: string;
/** Whether clients should interpret error as fatal */
fatal: boolean;
/** Error's PascalCase name */
name: string;
/** HTTP status code */
View MyComponent.js
// Dynamic state example
import * as React from 'react';
import * as ReactNative from 'react-native';
import connect from 'react-redux'
class MyComponent extends React.Component {
constructor(props) {
// Assign state based on props
// A contrived example:
View measure-letter-spacing.js
// Measure letter spacing on
// https://material-components-web.appspot.com/typography.html
Array.from(document.querySelectorAll('.demo-typography--section > *')).forEach((node) => {
const span = document.createElement('span')
const { fontSize, letterSpacing } = getComputedStyle(node)
const parsedFontSize = parseFloat(fontSize, 10) / 16
const parsedLetterSpacing = parseFloat(letterSpacing, 10) / 16
span.innerHTML = `<span style="background:#efefef;border-radius:2px;display:inline-block;font:12px/15px monospace;letter-spacing:normal;margin:0 0 4px 8px;padding:4px 8px;">
font-size: ${Number.isNaN(parsedFontSize) ? fontSize : `${Math.round(parsedFontSize * 1000) / 1000}rem`}<br />
View resolve-imports.js
/**
* **Warning!** This script modifies files. Use with caution, in a version
* controlled directory, etc.
*
* Replace partially resolved `import` or `require` paths with fully resolved
* paths using Node.js's internal `require` mechanism. Use:
*
* ```shell
* find . -type f -name '*.js' -exec node resolve-imports.js {} \;
* ```
You can’t perform that action at this time.