- Michele Titolo @micheletitolo
- Who's built, designed, and spec'd a lot of APIs
- Talk will focus on web APIs, but applies to many programmatic APIs, too
- good: it exists (and bonus points if it's interactive: I/O Docs is one nice example)
| const buffer = require('buffer'); | |
| const crypto = require('crypto'); | |
| // Demo implementation of using `aes-256-gcm` with node.js's `crypto` lib. | |
| const aes256gcm = (key) => { | |
| const ALGO = 'aes-256-gcm'; | |
| // encrypt returns base64-encoded ciphertext | |
| const encrypt = (str) => { | |
| // The `iv` for a given key must be globally unique to prevent |
| #!/bin/sh | |
| # ngrok's web interface is HTML, but configuration is bootstrapped as a JSON | |
| # string. We can hack out the forwarded hostname by extracting the next | |
| # `*.ngrok.io` string from the JSON | |
| # | |
| # Brittle as all get out--YMMV. If you're still reading, usage is: | |
| # | |
| # $ ./ngrok_hostname.sh <proto> <addr> | |
| # |
| import ( | |
| "mime" | |
| "net/http" | |
| "strings" | |
| ) | |
| // Determine whether the request `content-type` includes a | |
| // server-acceptable mime-type | |
| // | |
| // Failure should yield an HTTP 415 (`http.StatusUnsupportedMediaType`) |
| // Now available in package form at https://github.com/rjz/githubhook | |
| package handler | |
| // https://developer.github.com/webhooks/ | |
| import ( | |
| "crypto/hmac" | |
| "crypto/sha1" | |
| "encoding/hex" | |
| "errors" |
| /** `x/crypto` if running in `deno` */ | |
| import { createHmac } from 'node:crypto' | |
| /** A signing secret */ | |
| const HMAC_SECRET = '<YOUR SIGNING SECRET HERE>' | |
| /** Length of a hexidecimal HMAC digest */ | |
| const HMAC_LENGTH = 64 | |
| function hmac(message: string): string { |
| /** | |
| * Represents an error when an unreachable variant is encountered at runtime | |
| */ | |
| export class ExhaustiveCheckError<T> extends TypeError { | |
| public instance: T; | |
| public readonly isUnexpected = true; | |
| constructor(msg: string, instance: T) { | |
| super(msg); |
| // Depends on `through` | |
| // | |
| // $ npm install through | |
| // | |
| // Usage: | |
| // | |
| // $ echo 'hello' | node stdin-and-fs-stream.js | |
| // $ echo 'hello' > tmp && node stdin-and-fs-stream.js tmp | |
| // | |
| var fs = require('fs'), |
| // Example of mocking out global `fetch` | |
| // | |
| // Spec works using Jasmine (via Karma) and _either_ tsc or babel. | |
| // | |
| // $ npm install --save-dev fetch-mock whatwg-fetch | |
| // | |
| // If using `tsc`, grab the type definitions as well: | |
| // | |
| // $ typings --save --global dt~fetch-mock dt~whatwg-fetch |
| # -*- mode: ruby -*- | |
| # vi: set ft=ruby : | |
| # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
| VAGRANTFILE_API_VERSION = "2" | |
| Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
| # All Vagrant configuration is done here. The most common configuration | |
| # options are documented and commented below. For a complete reference, | |
| # please see the online documentation at vagrantup.com. |