Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Ferris jferris

  • thoughtbot, inc.
  • Cambridge, MA
View GitHub Profile
@jferris
jferris / BufferedCommitter.scala
Created Mar 1, 2019
Buffered commit to Kafka
View BufferedCommitter.scala
import cats.effect.{ContextShift, IO}
import cats.effect.concurrent.Ref
import cats.implicits._
import fs2.{Chunk, Pipe, Stream}
class BufferedCommitter(
config: Config,
consumer: Consumer,
pipe: Pipe[IO, Record, Unit])(implicit cs: ContextShift[IO]) {
def run: IO[Unit] =
@jferris
jferris / EitherT.scala
Created Nov 30, 2017
EitherT, partially applied
View EitherT.scala
import cats.{Applicative, Functor}
import cats.data.EitherT
import scala.language.higherKinds
object EitherTF {
def apply[F[_], A]: EitherTPartiallyApplied[F, A] =
new EitherTPartiallyApplied[F, A]
}
@jferris
jferris / Demo.scala
Created Nov 16, 2017
Type Inference
View Demo.scala
import cats.data.EitherT
import cats.instances.future._
import cats.syntax.all._
import scala.concurrent.{ExecutionContext, Future}
/*
* Compiled with:
* Scala 2.12.4
* cats-core 1.0.0-RC1
* -Ypartial-unification
@jferris
jferris / Wrap2.scala
Last active Apr 20, 2017
Reproduction for Shapeless Issue: Can't Comap a type with two type parameters
View Wrap2.scala
import shapeless._
import ops.hlist._
case class Wrap2[T, U](t: T, u: U)
class WrapTest[T, WL <: HList, L <: HList] {
def unwrap
(wrapped: WL)
(implicit comapped: Comapped.Aux[WL, ({ type l[U] = Wrap2[T, U] })#l, L])
= true
@jferris
jferris / defaults.json
Created Sep 6, 2016
Chart.js defaults
View defaults.json
{
"global": {
"responsive": true,
"responsiveAnimationDuration": 0,
"maintainAspectRatio": true,
"events": [
"mousemove",
"mouseout",
"click",
"touchstart",
View Example.hs
{-# LANGUAGE Arrows #-}
import Control.Arrow
double :: Int -> Int
double x = x * 2
triple :: Int -> Int
triple x = x * 3
@jferris
jferris / JSON.hs
Created Apr 14, 2016
Test.Hspec.JSON
View JSON.hs
module Test.Hspec.JSON
( shouldBeJson
) where
import Control.Monad (when)
import Control.Monad.State (StateT, get, modify, runStateT)
import Control.Monad.Writer (Writer, execWriter, tell)
import Data.ByteString.Lazy (ByteString)
import Data.Function (on)
import Data.Monoid ((<>))
@jferris
jferris / empty.hs
Created Mar 31, 2016
Empty Operator
View empty.hs
(?) :: Foldable t => t a -> t a -> t a
a ? b
| null a = b
| otherwise = a
View asoundrc
pcm.dmixed {
type asym
playback.pcm {
type dmix
ipc_key_add_uid true
ipc_key 5678293
ipc_perm 0660
ipc_gid audio
slave {
View combine.rb
def combine_ranges(ranges)
if ranges.empty?
[]
else
first, *rest = ranges
rest.reduce([first]) do |result, current|
previous = result.pop
if previous.max + 1.day >= current.min
result << previous.min..current.min
else
You can’t perform that action at this time.