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 my-great-type-test.ts
interface GreatClientConfig {
url: string
}
interface GreatClientResponse {
data: {
datetime: string
isGreat: boolean
}
}
@swashcap
swashcap / logger-in-closure.ts
Last active Sep 4, 2019
Passing around stuff: what's nicest?
View logger-in-closure.ts
import http from 'http'
import { print } from 'util'
type Logger = (...args: Parameters<typeof print>) => void
const logMe = (logger: Logger) => {
const getMaybeSomeData = () => {
logger('get maybe some data')
return Math.random() > .5 ? 'something' : undefined
@swashcap
swashcap / wp-remove-submenu.md
Created May 6, 2014
Easily remove the “Themes” and “Editor” submenus from the WordPress admin area.
View wp-remove-submenu.md

According to a WordPress.org support thread, it’s very easy to remove the Themes and Editor sub-pages entirely, making it (nearly) impossible to change themes. Drop this in your functions.php file:

/**
 * Remove the 'Themes' submenu page.
 *
 * @link http://codex.wordpress.org/Function_Reference/remove_submenu_page
 *
 * @return void
 */
View xml-to-yaml.js
/**
* Transform RSS-style XML with geolocation data to YAML
*
* {@link https://yaml.org}
*
* ```
* mkdir -p data
* yarn add hard-rejection cheerio he fast-xml-parser js-yaml
* # ...
* node xml-to-yaml.js
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
You can’t perform that action at this time.