Skip to content

Instantly share code, notes, and snippets.

@blankhart
blankhart / nested_iterators.rs
Created August 31, 2021 12:07
Abstracting over iterators
#![feature(box_syntax)]
fn go(outer: impl Iterator<Item = impl Iterator<Item = usize>>) {
print!("[ ");
for inner in outer {
print!("[");
for x in inner {
print!(" {} ", x)
}
@blankhart
blankhart / redirect_if_unauthorized.rs
Last active July 3, 2020 12:41
actix-web scope wrapper
// These type signatures do not quite work.
fn redirect_if_unauthorized<T, R>(
req: actix_web::dev::ServiceRequest,
srv: &mut T::Service,
) -> impl future::Future<Output = Result<actix_web::dev::ServiceResponse, Error>> + Clone
where
T: actix_service::ServiceFactory<
Config = (),
Request = actix_web::dev::ServiceRequest,
Response = actix_web::dev::ServiceResponse,
@blankhart
blankhart / actix-oauth2-compat.rs
Last active June 23, 2020 02:14
actix-web oauth2 client
// Create an HTTP client for consumption by oauth2 from the actix-web HTTP client.
// This is used when exchanging an authorization code for an access token.
use actix_web::client;
use oauth2::{HttpRequest, HttpResponse};
use std::str::FromStr;
use ::http::header::HeaderName;
use ::http::{HeaderMap, HeaderValue, StatusCode};
@blankhart
blankhart / sinuous-map-mini-mod.js
Last active April 19, 2020 03:14
DOM node list diff and patch
/* Adapted from snabbdom/updateChildren - The MIT License - Simon Friis Vindum */
import { api } from 'sinuous';
export function map(items, expr) {
const { subscribe, root, cleanup } = api;
let parent = document.createDocumentFragment();
const beforeNode = parent.appendChild(document.createTextNode(''));
const afterNode = parent.appendChild(document.createTextNode(''));
{-# LANGUAGE DeriveFunctor #-}
module Main where
type Algebra f a = f a -> a
type Coalgebra f a = a -> f a
newtype Fix f = In { out :: f (Fix f) }