Skip to content

Instantly share code, notes, and snippets.

View andywer's full-sized avatar

Andy Wermke andywer

View GitHub Profile
@andywer
andywer / app.ts
Last active February 27, 2019 12:57
Sample usage - Better HAL package for node
import Koa from "koa"
import * as KoaHAL from "$new-hal-koa-package"
import { api, Users } from "./hal"
const app = new Koa()
const koaRouter = KoaHAL.Router(api, router => {
// GET /users
router.get(Users, async ctx => {
const users = await queryAllUsers()
@andywer
andywer / Monorepo Setup.md
Last active April 8, 2022 03:50
Monorepo Setup

Overall Approach

This document is a short description of the monorepo setup that I came up for a few different smaller projects in the last 8 months or so.

Directory structure

/
  services/
 product/
@andywer
andywer / client.ts
Last active November 26, 2018 14:58
Typing REST APIs with TypeScript
import { Responses as PublisherAPIResponses } from "@satoshipay/publisher-service-api"
import axios from "axios"
import { URL } from "url"
import config from "../config"
export async function getPublisherById (id: string) {
const url = new URL(`/${id}`, config.publisherServiceUrl).toString()
return await axios.get(url) as PublisherAPIResponses["GET /*"]
}
@andywer
andywer / minimal.ts
Last active November 19, 2018 09:29
Better node server API - An attempt based on Koa
import { createApp, respond, route } from "koax"
import pkg from "../package.json"
const app = createApp()
app.get("/", async () => {
const body = {
name: pkg.name,
version: pkg.version
}

Keybase proof

I hereby claim:

  • I am andywer on github.
  • I am andywer (https://keybase.io/andywer) on keybase.
  • I have a public key ASAaseoxu8cFB_1LgQKirVmIAnK46TA20OoMraS114BRwAo

To claim this, I am signing this object:

@andywer
andywer / router-1.ts
Last active August 6, 2020 14:57
Koa: Passing data from middleware to route handler
/*
* Description:
*
* There are times when we want to re-use some data created/derived in a middleware later in a route handler.
*
* The default Koa way of doing so would be using `context.state`. Unfortunately `context.state` is hard to type and
* quite implicit, since it's an object shared and potentially mutated by all middlewares and the route handler.
*/
/*
@andywer
andywer / react-debug.js
Last active October 23, 2018 17:30
React Component State Debugger
let lastLoggingTime = Date.now();
function logUpdate (componentName, update, stateBefore, stateAfter, stack) {
const msSinceLastPrint = Date.now() - lastLoggingTime;
console.groupCollapsed(
`%c<${componentName}> setState: %o %c%s`,
"color: #5080ff",
update,
"color: #808080",
@andywer
andywer / typed-emitter.ts
Last active September 26, 2018 17:14
Type-safe EventEmitter
type Arguments<T> = [T] extends [(...args: infer U) => any]
? U
: [T] extends [void] ? [] : [T]
/**
* Type-safe event emitter.
*
* Use it as:
*
* interface MyEvents {
@andywer
andywer / multisig-service-arch.md
Last active September 19, 2018 10:35
Stellar Multisig Coordination Service Architecture Draft

Service federation

  • Each node has a key pair to authenticate itself to its peers
    • Key pair might or might not relate to a Stellar account
  • Each node provides a SSE co-signature request streaming endpoint other peers or wallets may subscribe to
  • When connecting to another peer
    • Subscribe to that peer's stream
    • Post a message to invite the peer to subscribe to the node's stream
  • Each node exposes a list of the peers that it is connected to
  • Each node has a configurable set of trusted peers, will always connect to them and accept them subscribing
@andywer
andywer / multisig-service.md
Last active September 19, 2018 10:45
Stellar Multisig Coordination Service - Rough Draft

Stellar Multisig Coordination Service

Objective

SEP-0007 introduced a standard for payment requests (basically templated transactions) on Stellar. In order to provide a smooth user experience when working with multi-signature accounts, wallets need to be able to send each other realtime payment requests.

That requires a new kind of service in the Stellar eco system: A multi-signature coordination service.