Skip to content

Instantly share code, notes, and snippets.

@n4to4
n4to4 / vimrc
Last active November 21, 2017 09:35
gvimrc
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
call plug#begin('~/.vim/plugged')
Plug 'w0rp/ale'
Plug 'vim-airline/vim-airline'
Plug 'eagletmt/ghcmod-vim'
Plug 'Shougo/vimproc'
call plug#end()
object Main extends App {
import com.google.protobuf.util.JsonFormat
import example.user.User
val user = User(id = 1, name = "foo")
println(user)
val userJson = JsonFormat.printer.print(User.toJavaProto(user))
println(userJson)
object Main extends App {
sealed trait VState
final abstract class Idle extends VState
final abstract class Half extends VState
final abstract class Ready extends VState
type Drink = String
sealed trait Coin
case object FiftyCents extends Coin
@n4to4
n4to4 / Main.hs
Last active October 3, 2017 05:57
Main.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as T
import Text.Megaparsec
import Text.Megaparsec.Text.Lazy
import qualified Text.Megaparsec.Lexer as L
import Text.RawString.QQ
object Main extends App {
case class Food(ingredients: Seq[String])
class Chef[Pizza <: Chef.Pizza](ingredients: Seq[String] = Seq()) {
import Chef.Pizza._
def addCheese(cheeseType: String): Chef[Pizza with Cheese] = new Chef(ingredients :+ cheeseType)
def addTopping(toppingType: String): Chef[Pizza with Topping] = new Chef(ingredients :+ toppingType)
{-# LANGUAGE OverloadedStrings, RankNTypes, FlexibleContexts #-}
module Main where
import Lucid
import Data.Text
import Network.Wai
import Network.Wai.Handler.Warp
import Network.HTTP.Types
main :: IO ()
{-# LANGUAGE RankNTypes #-}
module Main where
import Data.Functor.Const
import Data.Functor.Identity
type SimpleLens s a = forall f. Functor f => (a -> f a) -> s -> f s
data Person = Person {
@n4to4
n4to4 / PartialUnification.scala
Created June 26, 2017 03:17
PartialUnification.scala
// scalacOptions += "-Ypartial-unification"
object Foo {
trait KVS[F[_], K, V] {
def put(k: K, v: V): F[Unit]
def get(k: K): F[Option[V]]
}
trait Repository[F[_], Id, A] {
def query(id: Id): F[Option[A]]
import cats._, cats.data._, cats.implicits._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{Await, duration}
object Main extends App {
implicit class Ops[In](in: In) {
def |>[Out](f: In => Out): Out = f(in)
}
@n4to4
n4to4 / coyo.scala
Created June 21, 2017 09:09
coyoneda example
// https://gist.github.com/tpolecat/567e45710553d1b13fda1a4354ed8c18
import cats._, cats.implicits._
import cats.free.Coyoneda
object Main extends App {
val c = Coyoneda.lift(Set(1, 2, 3)).fproduct(n => "x" * n)
assert {
c.fi.map(c.k) == Set((1, "x"), (2, "xx"), (3, "xxx"))