Skip to content

Instantly share code, notes, and snippets.

View zephraph's full-sized avatar

Justin Bennett zephraph

View GitHub Profile
@zephraph
zephraph / rust-types.ts
Created January 24, 2024 02:48
Rust Inspired Monads for TypeScript
const Never = undefined as never;
export class Result<T extends "ok" | "error", D, E extends Error> {
private constructor(
public readonly type: T,
public readonly data: T extends "ok" ? D : never = Never,
public readonly error: T extends "error" ? E : never = Never
) {}
static ok<T>(value: T): Result<"ok", T, never> {
@zephraph
zephraph / export.js
Last active August 11, 2021 04:02
Exporting indexdb files from riverside.fm
// This script is adapted from david fahlander's post: https://dfahlander.medium.com/export-indexeddb-from-a-web-app-using-devtools-62c55a8996a1
// You should be able to drop this in the console on a riverside.fm page once you're logged in.
// Find the indexdb table name that you want to import by 2. Include dexie-export-import into the page.
const dbName = 'export-db'
const loadScript = src =>
new Promise(resolve => {
let script = document.createElement('script')
script.src = src;
@zephraph
zephraph / implicit_return_component.jsx
Last active January 29, 2020 16:47
Example of component with implicit return
// Don't allow this
export const ArrowComponent = () => (
<div>
<h1>My special implicit arrow function</h1>
</div>
)
// This is okay
export const SimpleComponent = () => <h1>This is fine</h1>
@zephraph
zephraph / webpack-config-timing.md
Last active January 17, 2020 17:32
Timing tester
repeat
5

Baseline

yarn webpack
@zephraph
zephraph / npm-canary.md
Last active September 29, 2023 01:19 — forked from schmich/npm-prerelease.md
Publish a canary package on NPM
  • Update package.json by running yarn version --prerelease --preid=canary
  • Run npm publish --tag canary to publish the package under the canary tag
  • Run yarn add @artsy/reaction@canary to install canary package

Running npm dist-tag ls can be helpful to see what tagged packages are available

@zephraph
zephraph / github-event-router.ts
Created October 25, 2019 03:43
A ziet now router for github webhooks
import { NowRequest, NowResponse } from "@now/node";
import { http, https } from "follow-redirects";
import { URL } from "url";
export = (request: NowRequest, response: NowResponse) => {
console.log(request.headers);
const event = request.headers["x-github-event"];
if (!event) return response.status(404).end();
const url = new URL(`https://${request.headers.host}/${request.url}`);
@zephraph
zephraph / color-test.js
Created July 3, 2019 17:50
Test color algorithms
// uses mocha
const { rgb } = require("wcag-contrast");
const fromHex = require("@fantasy-color/from-hex").default;
const fs = require("fs");
const assert = require("assert");
const parsedColors = fs
.readFileSync(__dirname + "/../parsed-colors.txt")
.toString()
.split("\n")
@zephraph
zephraph / parse-colors.js
Last active July 3, 2019 17:22
Parsed GitHub label colors
const fs = require("fs");
const fromRGB = require("@fantasy-color/from-rgb").default;
const hex = color => color.toString(16).padStart(2, "0");
const rgbToHex = rgb => {
const { red, green, blue } = fromRGB(rgb);
return `#${hex(red)}${hex(green)}${hex(blue)}`;
};
const colors = fs
@zephraph
zephraph / fetch-colors.js
Last active July 3, 2019 17:31
Github label color scrape
// Uses wdio to run
const fs = require("fs");
const colors = fs
.readFileSync("./colors.txt")
.toString()
.split("\n");
const pages = colors.map(color => `https://github.com/zephraph/test/labels/preview/TEXT?color=${color.slice(1)}`);
@zephraph
zephraph / colors.txt
Created July 3, 2019 03:32
Color test range
#000000
#000f17
#001e1c
#002b00
#0037ca
#004473
#005160
#005e53
#006b3d
#007800