Skip to content

Instantly share code, notes, and snippets.

View v0d1ch's full-sized avatar
:octocat:
compiling...

Sasha Bogicevic v0d1ch

:octocat:
compiling...
View GitHub Profile
@v0d1ch
v0d1ch / yesod_streaming.txt
Last active January 25, 2018 11:52
yesod streaming
body <- getRequest
lift $ runConduitRes $ (consumeBody body) =$ sinkFile directory
where
consumeBody :: MonadIO m => YesodRequest -> ConduitM i ByteString m ()
consumeBody body = do
chunk <- liftIO $ NW.requestBody $ reqWaiRequest body
if (chunk == BS.empty)
then return ()
else do
yield chunk
@v0d1ch
v0d1ch / ses.hs
Last active March 6, 2018 23:32
aws ses list identities
module Helper.Aws
(listAllEmails
) where
import Control.Lens ((&), (.~))
import Control.Monad.Trans.AWS (Error, runAWST, trying, _Error)
import Data.ByteString (ByteString)
import Network.AWS (Region (NorthVirginia), newEnv, runResourceT, send, within)
import Network.AWS.Auth (AccessKey (..), Credentials (FromKeys), SecretKey (..))
import Network.AWS.SES (IdentityType (..))
# Basic commands
:Git [args] # does what you'd expect
all of your `~/.gitconfig` aliases are available.
:Git! [args] # same as before, dumping output to a tmp file
Moving inside a repo.
@v0d1ch
v0d1ch / cps.hs
Last active January 21, 2019 21:36
CPS haskell
cpsTail :: [a] -> o -> ([a] -> o) -> o
cpsTail [] d = \f -> d
cpsTail (a:as) d = \f -> f as
cpsLoop :: (forall o. [a] -> o -> ([a] -> o) -> o) -> [a] -> [a]
cpsLoop f l = f l l id
safeTail :: [a] -> Maybe [a]
@v0d1ch
v0d1ch / store.hs
Last active February 5, 2019 14:47 — forked from dminuoso/store.hs
data Store s a = Store (s -> a) s
instance Comonad (Store s) where
extract :: Store s a -> a
extract (Store f s) = f s
-- "replacing all values with containers, and then consuming those containers again"
extend :: Store s a -> (Store s a -> b) -> Store s b
extend s f = fmap f $ duplicate s
-- verbose: Store (\x -> f' $ Store f x) s
@v0d1ch
v0d1ch / Vec3.hs
Last active February 21, 2019 21:16
data Vec3 a = Vec3 a a a deriving (Eq, Show)
instance Functor Vec3 where
fmap f (Vec3 a b c) = Vec3 (f a) (f b) (f c)
instance Applicative Vec3 where
pure a = Vec3 a a a
(Vec3 f f' f'') <*> (Vec3 a b c) = Vec3 (f a) (f' b) (f'' c)
instance Foldable Vec3 where
@v0d1ch
v0d1ch / lenses.hs
Created February 22, 2019 11:36 — forked from dminuoso/lenses.hs
traverseX :: forall f. Functor f = (a -> f a) -> Vec3 a -> f (Vec3 a)
traverseX f (Vec3 x y z) = (\h -> Vec3 h) <$> f x
traverseY :: forall f. Functor f = (a -> f a) -> Vec3 a -> f (Vec3 a)
traverseY f (Vec3 x y z) = (\h -> Vec3 h) <$> f x
traverseZ :: forall f. Functor f = (a -> f a) -> Vec3 a -> f (Vec3 a)
traverseZ f (Vec3 x y z) = (\h -> Vec3 h) <$> f x
type Lens s a = forall f. Funtor f => (a -> f a) -> s -> f s
@v0d1ch
v0d1ch / shell.nix
Created August 23, 2020 21:31
Nix shell with pinned unstable channel and hoogle
{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc883", withHoogle ? true }:
let
inherit (nixpkgs) pkgs;
pinnedUnstable =
pkgs.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs-channels";
rev = "c59ea8b8a0e7f927e7291c14ea6cd1bd3a16ff38";
sha256 = "1ak7jqx94fjhc68xh1lh35kh3w3ndbadprrb762qgvcfb8351x8v";
};
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
@v0d1ch
v0d1ch / Test.hs
Created July 20, 2021 08:32
Plutus contract (payout not working)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}