Skip to content

Instantly share code, notes, and snippets.

View jeffs's full-sized avatar

Jeff Schwab jeffs

View GitHub Profile

Rusty's API Design Manifesto

The idea

Application Programming Interface (API) design is hard. But it's even harder to change once you get it wrong. So what you should do is to spend the effort to get it right the first time around.

In the Linux Kernel community Rusty Russell came up with a API rating scheme to help us determine if our API is sensible, or not. It's a rating from -10 to 10, where 10 is perfect is -10 is hell. Unfortunately there are too many examples at the wrong end of the scale.

Rusty's original descriptions

@jeffs
jeffs / iterm2.md
Created April 12, 2025 22:55 — forked from squarism/iterm2.md
An iTerm2 Cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@jeffs
jeffs / README.md
Created April 9, 2024 18:28 — forked from nymous/README.md
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

@jeffs
jeffs / fibfib.rs
Last active February 18, 2024 23:57
Recursive Fibonacci sequence
/// Wraps an iterator of type I by creating it on the first call to .next(). Creates the wrapped
/// iterator by calling F.
enum Delay<I: Iterator, F: FnOnce() -> I> {
// New wraps an Option only so that we can take F out of it during the transition from New to
// Old. It feels like this shouldn't be necessary, but we're not allowed to move out of self in
// the body of Iterator::next, which (like any FnMut) merely borrows (rather than owning) self.
// See also StackOverflow:
// <https://stackoverflow.com/questions/36557412/how-can-i-change-enum-variant-while-moving-the-field-to-the-new-variant>
New(Option<F>),
Old(I),
@jeffs
jeffs / main.rs
Last active May 22, 2022 12:05
Rust File Mover Error
use std::{fs, io::Write};
fn main() {
println!("-Enter the account ID you wish to calculate for-");
let mut id = String::new();
std::io::stdin().read_line(&mut id).unwrap();
let id = id.trim();
println!("-Enter dummy data-");
let mut dd = String::new();
items.reduce(update, initialValue)
@jeffs
jeffs / nested-boring-reduce.py
Created April 9, 2021 05:42
Python's reduce function
from functools import reduce
result = reduce(update, items, initial_value)
@jeffs
jeffs / nested-boring-small-function.py
Last active April 9, 2021 06:34
A typical small function
def do_something(items):
result = initial_value
for item in items:
result = update(result, item)
return result
value = do_something(items)
@jeffs
jeffs / improve-support.md
Last active September 29, 2020 18:26
What could we do to improve your experience next time?

Firstly, avoid the need for users to contact support:

  1. Don't make breaking changes. (In the case at hand, the behavior of ⌘K was changed in a surprising and irritating way.)
  2. If you must make breaking changes:
  • Announce them loudly. (You did not.)
  • Provide an opt-out, or at least a carrot that's bigger than the stick. (You did neither.)

Secondly, make the "Contact us" easier to find: Don't make me jump through multiple links and support pages on the off chance that I'll find an existing answer to my question.

@jeffs
jeffs / dart.md
Created August 7, 2020 14:16 — forked from paulmillr/dart.md
Leaked internal google dart email

---------- Forwarded message ----------

From: Mark S. Miller <erights@google.com>
Date: Tue, Nov 16, 2010 at 3:44 PM
Subject: "Future of Javascript" doc from our internal "JavaScript Summit"
last week
To: javascript-standard@google.com