Skip to content

Instantly share code, notes, and snippets.

View swashcap's full-sized avatar
Writing code

Cory Reed swashcap

Writing code
View GitHub Profile
@swashcap
swashcap / demo.svg
Last active July 22, 2021 22:21
A demo SVG for experimenting with the <object> element
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
var assert = require('assert').strict
// Accects `obj`, ideally a JSON-parsed data structure returned from a RESTful
// API
function countReferences (obj) {
if (obj === null || typeof obj !== 'object') {
return [
obj,
function () {}
]
interface GreatClientConfig {
url: string
}
interface GreatClientResponse {
data: {
datetime: string
isGreat: boolean
}
}
@swashcap
swashcap / logger-in-closure.ts
Last active September 4, 2019 00:19
Passing around stuff: what's nicest?
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
/**
* 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

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) => {
/**
* 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
* ```
*/
const assert = require('assert')
const get = require('lodash/fp/get')
const { createSelector } = require('reselect')
const list = get('list')
const getId = createSelector(
list,
get('id')
)
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 March 9, 2019 22:07
Server Startup Time
#!/bin/bash
set -eo pipefail
#
# Test server startup times using crude scripting
#
# Use:
#
# time CMD="npm start" URL=localhost:3000 ./startup.sh
#