Skip to content

Instantly share code, notes, and snippets.

Michael Snoyman snoyberg

Block or report user

Report or block snoyberg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@snoyberg
snoyberg / Main.hs
Created Apr 8, 2019
Help debugging the pantry lock bug
View Main.hs
import RIO
import Pantry
import Path
data App = App SimpleApp PantryConfig
instance HasPantryConfig App where
pantryConfigL = lens (\(App _ pc) -> pc) undefined
instance HasLogFunc App where
logFuncL = (lens (\(App sa _) -> sa) undefined).logFuncL
View uses-rio.hs
#!/usr/bin/env stack
-- stack --resolver lts-12.21 script
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
import Control.Monad (replicateM)
import System.Random
import RIO
@snoyberg
snoyberg / no-wrap.rs
Created Jan 21, 2019
NoWrap data type in Rust
View no-wrap.rs
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
pub struct NoWrap<T>(T);
impl std::ops::Add for NoWrap<u8> {
type Output = Option<Self>;
fn add(self, rhs: Self) -> Self::Output {
self.0.checked_add(rhs.0).map(|x| NoWrap(x))
}
}
@snoyberg
snoyberg / init-arrays.rs
Created Nov 27, 2018
Safely initialize fix length arrays in Rust (WIP!)
View init-arrays.rs
#[derive(Debug)]
struct Foo(usize);
impl Drop for Foo {
fn drop(&mut self) {
println!("Dropping: {}", self.0);
}
}
enum MakeArray<T> {
View haskell-reference.hs
#!/usr/bin/env stack
-- stack --resolver lts-12.18 script
import Control.Concurrent (threadDelay)
import Control.Concurrent.Async (replicateConcurrently_)
import Control.Monad (unless)
import Data.IORef
import System.Random (randomIO)
main :: IO ()
main = do
@snoyberg
snoyberg / friendly-message.txt
Created Nov 21, 2018
Friendly message I just received
View friendly-message.txt
Delivered-To: michael@snoyman.com
Received: by 2002:a1c:4301:0:0:0:0:0 with SMTP id q1-v6csp1506707wma;
Tue, 20 Nov 2018 23:25:41 -0800 (PST)
X-Google-Smtp-Source: AJdET5f1C8DMF9m1XRMoX9S1t46F+PobSy/H5EoANnh63qdnxnwjxYEen1PcquvM6EumRechISPJ
X-Received: by 2002:ac8:7416:: with SMTP id p22mr4770530qtq.318.1542785141599;
Tue, 20 Nov 2018 23:25:41 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1542785141; cv=none;
d=google.com; s=arc-20160816;
b=VhI63HEQnO94PvvqvLMYwbJ6WFtWacc0kmRuEiBnHtHm3v8CQlylR/oZ8k/qwM99Hs
IaZfxNJ+nTaLYmTvtQQpb0mGOtYfekQV2Tu37M01sH6pT6hMOAMe45K1QtzvxAvVxJE1
@snoyberg
snoyberg / README.md
Last active Aug 27, 2018
Miniature Haskell interactive environment for my kids to play around with
View LabeledContainers.hs
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module LabeledContainers
( Map
, HashMap
, Set
, Hashable
@snoyberg
snoyberg / .gitignore
Last active Aug 1, 2018
Streaming UTF-8 decoding using valid_up_to
View .gitignore
valid_up_to
valid_up_to.exe
View bootstrap.css
@import url("https://fonts.googleapis.com/css?family=Lato:400,700,400italic");
/*!
* bootswatch v3.3.7
* Homepage: http://bootswatch.com
* Copyright 2012-2016 Thomas Park
* Licensed under MIT
* Based on Bootstrap
*/
/*!
* Bootstrap v3.3.7 (http://getbootstrap.com)
You can’t perform that action at this time.