Skip to content

Instantly share code, notes, and snippets.

@n4to4
n4to4 / scrape.cabal
Created August 8, 2018 10:07
scrape.hs
name: scrape
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/githubuser/scrape#readme
license: BSD3
license-file: LICENSE
author: Author name here
maintainer: example@example.com
copyright: 2018 Author name here
@n4to4
n4to4 / Lens.hs
Created May 28, 2018 02:55
Lens tutorial
{-# LANGUAGE OverloadedStrings #-}
-- https://medium.com/urbint-engineering/haskell-lens-operator-onboarding-a235481e8fac
module Main where
import Control.Lens
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.HashMap.Strict as HM
{-# LANGUAGE DeriveFunctor #-}
module Main where
import Control.Monad
import Control.Monad.Trans.Class
import Control.Monad.Trans.Free
import Data.Sequence
data ThreadF next = Fork next next
| Yield next
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Applicative
import Control.Lens hiding (op)
import Control.Monad
import Control.Monad.State
import Data.Char
import System.IO
import System.Random
{-# LANGUAGE RankNTypes #-}
module Main where
import Control.Monad.State
import System.Random
type GenAction m = forall a. (Random a) => m a
type GenActionR m = forall a. (Random a) => (a, a) -> m a
data Player = Player
@n4to4
n4to4 / fizzbuzz.hs
Created May 13, 2018 02:36
fizzbuzz.hs
module Main where
import Data.Foldable (asum)
import Data.Maybe (fromMaybe)
toMaybe :: Bool -> a -> Maybe a
toMaybe False _ = Nothing
toMaybe _ value = Just value
fizzbuzz :: Integer -> String
@n4to4
n4to4 / LoadTest.scala
Last active May 24, 2018 09:36
http4s question
package sandbox.load
import io.gatling.core.Predef._
import io.gatling.core.scenario.Simulation
import io.gatling.http.Predef._
import scala.concurrent.duration._
class LoadTest extends Simulation {
val httpConf = http.baseURL("http://127.0.0.1:8000")
val json = scala.io.Source.fromFile("/path/to/request.json").mkString
import cats.implicits._
import cats.effect.IO
import doobie._
import doobie.implicits._
import fs2.Stream
object Main extends App {
case class RedisClient()
val xa = Transactor.fromDriverManager[IO](
import shapeless._
trait AllSingletons[A, C <: Coproduct] {
def values: List[A]
}
object AllSingletons {
implicit def cnilSingletons[A]: AllSingletons[A, CNil] =
new AllSingletons[A, CNil] {
def values = Nil
object Main extends App {
import cats.effect.IO
import fs2.{Stream, Scheduler}
import fs2.async.signalOf
import fs2.async.mutable.Signal
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
def stopAfter[A](f: FiniteDuration): Stream[IO, A] => Stream[IO, A] = in => {
def close(s: Signal[IO, Boolean]): Stream[IO, Unit] =