Skip to content

Instantly share code, notes, and snippets.

View Fristi's full-sized avatar

Mark Fristi

View GitHub Profile
@nh2
nh2 / time-natural.hs
Created March 1, 2014 01:33
Natural time in Haskell: `2 hours + 4 seconds`
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving #-}
newtype TimeUnit = TimeUnit Integer -- how many microseconds
deriving (Eq, Show, Num)
instance Num (TimeUnit -> TimeUnit) where
fromInteger n = \(TimeUnit scale) -> TimeUnit (n * scale)
-- a + b = ... -- task for you
import Data.Char
strong = and . sequence conditions
where conditions = [ (>14) . length
, any isUpper
, any isLower
, any isDigit
]
{-
@tpolecat
tpolecat / gist:5672105
Last active December 17, 2015 21:08
making scala stm look like haskell stm
package util
import scalaz.effect.IO
import scalaz._
import Scalaz._
import scala.concurrent.stm.{ retry => stmRetry, _ }
object X {
type STM[+A] = ReaderT[IO, InTxn, A]
@kings13y
kings13y / MinimalSoapServer.scala
Created February 2, 2011 21:53
Minimal Soap Server using Scala and JDK6 annotations
import javax.jws.WebService
import javax.jws.soap.SOAPBinding
import javax.jws.soap.SOAPBinding.Style
import javax.xml.ws.Endpoint
@WebService(targetNamespace="org.scalabound.test", name="org.scalabound.test", portName="test", serviceName="WSTest")
private class MinimalSoapServer {
@SOAPBinding(style = Style.RPC)
def test(value : String) = "Hi " + value
def treeDoc(t: Tree): Doc = t match {
case PackageDef(mods, pid, xs) => mods <> "package" <+> pid <+> xs.inBracesBlock
case Import(expr, selectors) => "import" <+> expr <> dot <> selectors
case NamedImport(name) => name
case TypeIdent(pre, name) => (pre :+ name).joinDotted
case TermIdent(pre, name) => (pre :+ name).joinDotted
case ClassDef(mods, keyword, name, tparams, vparamss, impl) => linebreak <> mods <> keyword <+> name <> tparams <> tight(vparamss) <> doTemplate(line <> "extends", impl)
case TypeParam(mods, name, tparams, constraints) => mods <> name <> tparams <> constraints
case ValueParam(mods, name, tpt, defaultValue) => mods <> name <> tpt <> opt(space <> assign, defaultValue)
case x: Name => x.value
@philcleveland
philcleveland / GetEventStoreEventDispatcher.cs
Last active June 8, 2016 23:04
Event dispatcher which receives events from the GetEventStore after they are saved. It takes the saved events and publishes them to the passed in Event Bus. This ensures that events are not published until they are saved in the GetEventStore. Big thanks to Andrii for all the reviews and coding help to get this thing working.
public class GetEventStoreEventDispatcher
{
private const int RECONNECT_TIMEOUT_MILLISEC = 5000;
private const int THREAD_KILL_TIMEOUT_MILLISEC = 5000;
private const int READ_PAGE_SIZE = 500;
private const int LIVE_QUEUE_SIZE_LIMIT = 10000;
private readonly IEventBus _eventBus;
private readonly EventStoreConnection _store;
package akka.kafka.scaladsl
import java.util.concurrent.TimeUnit
import java.util.{Properties, UUID}
import akka.actor.ActorSystem
import akka.kafka.{ConsumerSettings, ProducerSettings}
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Sink
import akka.testkit.TestKit
package cats.bench
import cats.data.Xor
import cats.instances.either._
import cats.syntax.all._
import org.openjdk.jmh.annotations.{ Benchmark, Scope, State }
@State(Scope.Benchmark)
class EitherBench {
val ea: Either[String, Int] = Right(1)
@octonato
octonato / type-classs-derivation.scala
Created June 11, 2015 16:34
Writer/Reader (Shapeless workshop ScalaDays 2015)
/*
* Copyright (c) 2015 Miles Sabin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@lihaoyi
lihaoyi / play.scala
Last active April 18, 2017 08:18
play.scala
/**
* Single-file play framework application! Make sure everything
* works, as this is the test case that un-earthed #371
*/
load.ivy("com.typesafe.play" %% "play" % "2.5.0")
load.ivy("com.typesafe.play" %% "play-netty-server" % "2.5.0")
load.ivy("org.scalaj" %% "scalaj-http" % "2.2.1")
@