Skip to content

Instantly share code, notes, and snippets.

@jbr
jbr / main.rs
Last active August 3, 2023 00:12
Limit body size in trillium
use futures_lite::{AsyncRead, AsyncReadExt};
use std::{
io::{Error, ErrorKind, Result},
pin::Pin,
task::{ready, Context, Poll},
};
use trillium::{Conn, Status};
pub struct Limit<T> {
reader: T,
@jbr
jbr / emacs-deno-lsp.md
Created May 2, 2022 19:47
how to use emacs-lsp's deno lsp server instead of ts-ls

How to use emacs-lsp's deno lsp server instead of ts-ls, the typescript language server

It was surprisingly difficult to find this documented exactly anywhere on the internet, so I thought I'd post this somewhere so the next person googling for it has a chance of finding it. The lsp docs just say to "create a dir-local for each of the projects" but provides no guidance on how to do that.

Place a file named .dir-locals.el in your deno project root, containing exactly the following elisp:

((typescript-mode . ((lsp-disabled-clients . (ts-ls)))))
@jbr
jbr / exec-path-from-nu.el
Last active April 10, 2023 17:30
exec shell path from nushell/nu for emacs
(defun set-exec-path-from-nu ()
(interactive)
(let ((path-from-shell (shell-command-to-string
"~/.cargo/bin/nu -i -l -c\
\"source ~/.config/env.nu; \
echo $env.PATH | str join :\"")))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell ":"))))
@jbr
jbr / about.md
Last active December 29, 2021 08:21
hugo shortcode for including source code from a file and optionally a subset of lines

I couldn't find this anywhere on the internet and struggled to figure out how to do this so I'm hoping github's seo is good enough that it helps someone else.

Files must be within the content dir or the project root, and are relative to those places. Symlinks are followed, though.

I'm not sure which order they're checked, but in the following examples, hugo will look in PROJECT_ROOT/content/code-samples/example.rs and PROJECT_ROOT/code-samples/example.rs and use whichever it finds first.

@jbr
jbr / macro-expansion-pin-project-request.rs
Last active July 12, 2020 18:51
macro expansion of adding pin project to Request.req
pub struct Request<State> {
pub(crate) state: State,
pub(crate) req: http::Request,
pub(crate) route_params: Vec<Params>,
}
#[allow(single_use_lifetimes)]
#[allow(clippy::used_underscore_binding)]
const _: () = {
#[allow(dead_code)]
@jbr
jbr / 0001-use-pin_project_lite-to-implement-Read-for-Request.patch
Created July 12, 2020 18:21
patch for Fishrock123/tide/server-state-clone
Subject: [PATCH] use pin_project_lite to implement Read for Request
---
Cargo.toml | 1 +
src/request.rs | 39 +++++++++++++++++++--------------------
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 7efecd2..838c461 100644
--- a/Cargo.toml
@jbr
jbr / cargo.toml
Created April 24, 2020 05:10
surf-tide-proxy-example
[package]
name = "surf-tide-proxy-example"
version = "0.1.0"
authors = ["Jacob Rothstein <hi@jbr.me>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
surf = { git = "https://github.com/http-rs/surf", branch = "master" }
@jbr
jbr / _hacked-up-async-sse-notes.txt
Last active April 15, 2020 22:13
hacked-up async_sse
if nobody is listening to an event stream, it never gets encoded,
since encoding happens on the consumption end of the channel
library users can use StreamExt to subset/filter/transform events
before they're encoded, since user-defined events are on the channel,
not already-encoded text
channel specifics are outside of the purview of this code. as long as
it implements a stream of Events, it can be encoded as an SSE
@jbr
jbr / covid-per-capita.r
Last active March 29, 2020 00:17
covid data per capita
library(choroplethr)
library(tidyverse)
library(choroplethrMaps)
data(county.regions)
data(df_pop_county)
data <-
"https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv" %>%
url() %>%
@jbr
jbr / promiseProxy.js
Last active December 4, 2019 20:48
An attempt at a type-aware promise wrapper
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function existingFunction(promise, property) {
return (...args) => buildProxy(promise[property].apply(promise, args));
}
function buildProxy(promiseOrValue) {
const promise = "then" in promiseOrValue ? promiseOrValue : Promise.resolve(promiseOrValue);
return new Proxy(promise, {
get(target, property) {
if (property in promise)