Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Snoyman snoyberg

View GitHub Profile
@snoyberg
snoyberg / check-status.hs
Created May 27, 2020
Check HTTP status codes
View check-status.hs
#!/usr/bin/env stack
-- stack --resolver lts-15.10 script
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
import RIO
import Network.HTTP.Simple
import qualified RIO.Text as T
main :: IO ()
main = runSimpleApp $ do
@snoyberg
snoyberg / Main.hs
Created Apr 1, 2020
Complete snapshot layer
View Main.hs
#!/usr/bin/env stack
-- stack --resolver foo.yaml script
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
import Pantry
import RIO
import Path
import Path.IO
import Data.Yaml (encodeFile)
@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
You can’t perform that action at this time.