Skip to content

Instantly share code, notes, and snippets.

View ceedubs's full-sized avatar

Cody Allen ceedubs

  • central Indiana, USA
View GitHub Profile
@ceedubs
ceedubs / fork-pr-model.md
Created April 11, 2018 15:59
Tips for working with the fork and pull-request model on GitHub

working with the fork and pull-request model on GitHub

The common model for contributing to an open-source project is the fork/pull request model. In this model, if you want to contribute to a project, you don't need commit rights to the projects GitHub repository. Instead, you "fork" the repository to create your own copy. You make your changes in your own fork and then submit a "pull request" (PR) which is a request that your changes get merged into the main repository. The fork/PR model is beneficial even in a work environment, as it allows fine-grained control over repository permissions while still allowing non-owners to contribute. See GitHub's About collaborative development models and its "Further reading" section for more information.

This document gives some tips for:

  • cloning (making a local copy of) a repository
  • forking (making a remote copy of) a repository
  • [fetching pull request code](#f
@ceedubs
ceedubs / hlist.scala
Created March 5, 2016 21:45
The start of an HList implementation from my nescala unconf session. There are two errors that are left to the reader as an exercise. Hint: it's mostly right but a couple types are incorrect.
import HList._
sealed abstract class HList
case object HNil extends HList
final case class HCons[H, T <: HList](head: H, tail: T) extends HList
object HList {
type HNil = HNil.type
type ::[H, T <: HList] = HCons[H, T]
@ceedubs
ceedubs / trampoline.scala
Created October 20, 2015 11:20
Port of example code from http://www.scala-lang.org/api/2.10.4/#scala.util.control.TailCalls$ to Trampoline. Note that for this example, Eval is probably more efficient.
import cats.free.Trampoline, Trampoline._
import cats.implicits._
def isEven(xs: List[Int]): Trampoline[Boolean] =
if (xs.isEmpty) done(true) else suspend(isOdd(xs.tail))
def isOdd(xs: List[Int]): Trampoline[Boolean] =
if (xs.isEmpty) done(false) else suspend(isEven(xs.tail))
// returns true (doesn't overflow the stack)
@ceedubs
ceedubs / folds.scala
Created April 25, 2015 16:49
Type inference of curried vs uncurried fold on Option
object CurryInference {
implicit final class OptionOps[A](val oa: Option[A]) {
/** curried fold */
def curriedFold[B](z: => B)(f: A => B): B = oa.fold(z)(f)
/** uncurried fold */
def uncurriedFold[B](z: => B, f: A => B): B = oa.fold(z)(f)
}
trait Show[A] {
def show(a: A): String
}
object Show {
implicit val stringShow: Show[String] = new Show[String] {
def show(a: String) = a
}
}
@ceedubs
ceedubs / NoImplicitFor.scala
Created March 5, 2015 21:51
Evidence that a typeclass instance does not exist for a type. You probably don't want to use this.
trait Show[A] {
def show(a: A): String
}
object Show {
implicit val stringShow: Show[String] = new Show[String] {
def show(a: String) = a
}
}
@ceedubs
ceedubs / TableExample.scala
Created March 5, 2015 20:42
Weird implicit search failure with Shapeless At and Nat._0
package shapeless.examples
import shapeless._
import nat._
import ops.hlist._
object TableExample {
final case class Row[L <: HList](cells: L)
@ceedubs
ceedubs / HDequeue.scala
Created February 25, 2015 23:25
HStack and HDequeue
import scalaz._
import shapeless._
import shapeless.ops.hlist._
/** contrived IndexedState example */
object HStack extends App {
def push[H, T <: HList](h: H): IndexedState[T, H :: T, H] =
IndexedState(t => (h :: t, h))
def pop[H, T <: HList]: IndexedState[H :: T, T, H] =
@ceedubs
ceedubs / FreeCTwoRandomIntExample.scala
Created December 7, 2014 23:18
An app that does some logging and adds two random Ints like https://gist.github.com/ceedubs/510a7eb9147c9d27132c except using FreeC
object FreeCTwoRandomIntExample extends App {
import scalaz._
import scalaz.effect.IO
import scala.util.Random
sealed trait Action[A]
final case class Log(msg: String) extends Action[Unit]
final case class RandomInt(below: Int) extends Action[Int]
@ceedubs
ceedubs / WriterTExample.scala
Created December 6, 2014 17:34
Using WriterT for logging of Random => IO[A]
object WriterTExample extends App {
import scalaz._
import scalaz.effect.IO
import scala.util.Random
import scalaz.syntax.monad._
type Logged[F[_], A] = WriterT[F, DList[String], A]
def log[F[_]](msg: => String)(implicit F: Applicative[F]): Logged[F, Unit] =