Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Binding. Lifting. Zipping.

Daniel Stankevich danstn

🚀
Binding. Lifting. Zipping.
View GitHub Profile
View servant-custom-monad-basic-auth.hs
newtype PrivateData = PrivateData { ssshhh :: Text }
deriving (Eq, Show, Generic)
newtype PublicData = PublicData { somedata :: Text }
deriving (Eq, Show, Generic)
instance ToJSON PrivateData
instance ToJSON PublicData
type PublicAPI = Get '[JSON] [PublicData]
@danstn
danstn / home-ca.sh
Created Apr 25, 2017
Home Certificate Authority
View home-ca.sh
#!/usr/bin/bash
set -e
echo -n "Enter server name (i.e. nginx-server): "
read server
echo "===> [INFO] Generating certs for: $server"
echo "===> [Step 1] Generating Certificate Request (CSR)..."
@danstn
danstn / reasonable.hs
Created Mar 29, 2016 — forked from aaronlevin/reasonable.hs
Reasonably Priced Monads in Haskell
View reasonable.hs
-- | simple/basic Scala -> Haskell translation of Runar's presentation
-- | (https://dl.dropboxusercontent.com/u/4588997/ReasonablyPriced.pdf)
-- | trying to use minimal extensions and magic.
-- | (earlier I had a version using MultiParamTypeClasses for Runar's
-- | Inject class, but scraped it opting for simplicity)
-- | my question: what do we lose by moving towards simplicity?
-- | Future work: use DataKinds, TypeOperators, and potentially TypeFamilies
-- | to maintain and automate the folding of types in Coproduct.
{-# LANGUAGE Rank2Types, DeriveFunctor #-}
@danstn
danstn / gist:c9725862f5ec0cb69063
Created Mar 29, 2016 — forked from runarorama/gist:a8fab38e473fafa0921d
Compositional application architecture with reasonably priced monads
View gist:c9725862f5ec0cb69063
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]
@danstn
danstn / free-monad-example.hs
Last active Jan 4, 2017
An example of using Free Monads for writing custom AST/DSL and its interpreters.
View free-monad-example.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveFunctor #-}
import Prelude
import Data.String
import Control.Monad.Free
type Program a r = Free (AST a) r
data AST a next =
@danstn
danstn / watch.hs
Last active Aug 29, 2015
Very simple Haskell watcher
View watch.hs
#!/usr/bin/env runhaskell
{-# LANGUAGE OverloadedStrings #-}
import Turtle
main :: IO ()
main = do
stdout (runWatch $ findSrc)
@danstn
danstn / chjava
Last active Aug 29, 2015
chjava bash function
View chjava
function chjava() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $@`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
@danstn
danstn / opt_type.scala
Last active Aug 29, 2015
My Opt type implementation
View opt_type.scala
sealed trait Opt[+A] {
def flatMap[T](f: A => Opt[T]): Opt[T] =
fold[Opt[T]](Nothing)(f)
def map[T](f: A => T): Opt[T] =
fold[Opt[T]](Nothing)(a => Something(f(a)))
def fold[B](g: => B)(f: A => B): B =
this match {
case Something(a) => f(a)
View eq_indices.rb
# An equilibrium index of a sequence is an index into the sequence
# such that the sum of elements at lower indices is equal to the
# sum of elements at higher indices.
def eq_indices(arr)
left, right = 0, arr.inject(0, :+)
result = []
arr.each_with_index do |el, i|
right -= el
result << i if right == left
You can’t perform that action at this time.