Skip to content

Instantly share code, notes, and snippets.

View fizruk's full-sized avatar
♾️

Nikolai Kudasov fizruk

♾️
View GitHub Profile
@fizruk
fizruk / Simulation.hs
Created November 3, 2013 14:44
Step-by-step simulation with Gloss and IterT.
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Monad
import Control.Monad.State
import Control.Monad.Trans.Iter
import Control.Lens
import Data.Set (Set)
import qualified Data.Set as Set
@fizruk
fizruk / test.hs
Last active December 28, 2015 04:19 — forked from bgamari/TH.hs
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
module Main where
import Control.Monad
import Control.Monad.Free
import Control.Monad.Free.TH
data Lang next
@fizruk
fizruk / bundles.vim
Created December 24, 2013 20:11
Bundles I use
" General bundles
NeoBundle 'Shougo/vimproc', {
\ 'build' : {
\ 'windows' : 'make -f make_mingw32.mak',
\ 'cygwin' : 'make -f make_cygwin.mak',
\ 'mac' : 'make -f make_mac.mak',
\ 'unix' : 'make -f make_unix.mak',
\ },
\ }
NeoBundle 'Shougo/unite.vim'
@fizruk
fizruk / docker-push.sh
Created November 10, 2015 17:12
Push to Docker from Circle CI
#!/bin/sh
set -x
CIRCLE_TAG=`git name-rev --tags --name-only $(git rev-parse HEAD)`
docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
if [ "$CIRCLE_TAG" -ne "undefined" ]; then
docker tag user/repo user/repo:$CIRCLE_TAG
@fizruk
fizruk / PDividing.hs
Last active January 29, 2016 02:20
Generic mappend for product-like types using Profunctor analogue of both Decidable and Applicative.
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module PDividing where
import Data.Foldable
import Data.Monoid
import Data.Profunctor
@fizruk
fizruk / DecidingL1.hs
Created January 29, 2016 11:10
Generic foldMap using Decidable1
class Contravariant1 p where
contramap1 :: (a -> b) -> p b x -> p a x
class Contravariant1 p => Divisible1 p where
conquer1 :: p a x
divide1 :: (a -> (b, c)) -> p b x -> p c x -> p a x
class Divisible1 p => Decidable1 p where
lose1 :: (a -> Void) -> p a x
choose1 :: (a -> Either b c) -> p b x -> p c x -> p a x
@fizruk
fizruk / DecidingR1.hs
Last active January 30, 2016 15:01
Generic foldMap through Decidable.
class (Generic1 t, GDecidingR1 q (Rep1 t)) => DecidingR1 q t where
decidingR1 :: Decidable (f b) => p q -> (forall g. q g => f b (g a)) -> f b a -> f b (t a)
instance (Generic1 t, GDecidingR1 q (Rep1 t)) => DecidingR1 q t where
decidingR1 p f r = contramap from1 $ gdecidingR1 p f r
class GDecidingR1 q t where
gdecidingR1 :: Decidable (f b) => p q -> (forall g. q g => f b (g a)) -> f b a -> f b (t a)
class Unit1 a
instance Unit1 a
gfoldMap :: (Deciding1 Unit1 f, Monoid m) => (a -> m) -> f a -> m
gfoldMap = flip . getOp $ deciding1 (Proxy :: Proxy Unit1) (Op mempty) (Op (flip id))
@fizruk
fizruk / tmap.hs
Last active February 2, 2016 23:39
TMap, Every and nice type level things, helpful for servant, hspec, etc.
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE PolyKinds #-}
@fizruk
fizruk / GitHubGistAPI.hs
Created February 4, 2016 23:30
GitHub API v3 — Gists (partial)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module GitHub where
import Control.Lens
import Data.Aeson
import Data.Aeson.Types (camelTo)