Skip to content

Instantly share code, notes, and snippets.

David Barri japgolly

Block or report user

Report or block japgolly

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@xian
xian / 00_README.md
Last active Dec 14, 2015 — forked from JakeWharton/ActionBarSherlockRobolectric.java
Here's the magic to get ActionBarSherlock working with Robolectric 2.0-alpha-2!
View 00_README.md

You need to add the files below, and do this once in your base test runner:

ActionBarSherlock.registerImplementation(ActionBarSherlockRobolectric.class);
ActionBarSherlock.unregisterImplementation(ActionBarSherlockNative.class);
ActionBarSherlock.unregisterImplementation(ActionBarSherlockCompat.class);
@shangaslammi
shangaslammi / webspider.hs
Created Oct 4, 2011
Haskell Web Spider example
View webspider.hs
import Control.Exception
import Control.Monad
import Control.Monad.IO.Class
import Data.ByteString.Lazy (ByteString)
import Data.ByteString.Lazy.UTF8 (toString)
import Data.Function
import Data.Enumerator
import Data.List
import Data.Maybe
@arosien
arosien / runar-io-free.scala
Last active Sep 10, 2016
Translation of Runar's ScalaIO 2013 presentation on IO and Free monads (http://blog.higher-order.com/assets/scalaio.pdf) to scalaz.
View runar-io-free.scala
import scalaz._
import Scalaz._
import Free._
/** "Pure" interactions with a console. */
sealed trait Console[+A]
case class GetLine[A](k: String => A) extends Console[A]
case class PutLine[A](s: String, a: A) extends Console[A]
object Console {
@nponeccop
nponeccop / Unfold.hs
Created Aug 16, 2015
Unfolds, coalgebras and anamorphisms
View Unfold.hs
{-# LANGUAGE DeriveFunctor #-}
import Data.Functor.Foldable
import Data.Function
unfold1 :: Unfold Int [Int]
unfold1 = xana coalgebra1
xana :: Unfoldable b => Coalgebra a b -> Unfold a b
xana = ana
@holoed
holoed / JsonParser.hs
Last active Mar 31, 2017
Json Parser Example
View JsonParser.hs
{-#LANGUAGE DeriveFunctor#-}
module Main where
fix :: ((a -> b) -> a -> b) -> a -> b
fix f = f (fix f)
newtype Fix f = In { out :: f (Fix f) }
type Algebra f a = f a -> a
@zraffer
zraffer / package.scala
Last active Apr 26, 2017
a few operations with functors
View package.scala
package object types {
import scala.language.reflectiveCalls
import scala.language.higherKinds
// quantifiers aka (co)ends
type Forall[+F[_]] = { def apply[X]: F[X] }
type Exists[+F[_]] = F[_]
// basic categorical notions
@kdrakon
kdrakon / ConsistentHashGroupedStreams.scala
Created Sep 6, 2016
Example of Consistent Hashing for Akka groupBy Streams
View ConsistentHashGroupedStreams.scala
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.{Executors, TimeUnit}
import akka.actor.{ActorSystem, Props}
import akka.routing.ConsistentHash
import akka.stream.actor._
import akka.stream.scaladsl.{Flow, GraphDSL, RunnableGraph, Sink, Source}
import akka.stream.{ActorMaterializer, ClosedShape, ThrottleMode}
import com.kifi.franz.{MessageId, SQSMessage}
View metamorphism.hs
-- | A “flushing” 'stream', with an additional coalgebra for flushing the
-- remaining values after the input has been consumed. This also allows us to
-- generalize the output away from lists.
fstream
:: (Cursive t (XNor a), Cursive u f, Corecursive u f, Traversable f)
=> Coalgebra f b -> (b -> a -> b) -> Coalgebra f b -> b -> t -> u
fstream ψ g ψ' = go
where
go c x =
let fb = ψ c
@Mzk-Levi
Mzk-Levi / ncompositions.scala
Last active Mar 24, 2018
Horizontal & Vertical Compositions of Natural Transformations
View ncompositions.scala
trait Functor[F[_]] {
def map[A, B](as: F[A])(f: A => B): F[B]
}
object Functor {
def apply[F[_]](implicit e: Functor[F]): Functor[F] = e
}
trait ~>[F[_], G[_]] {
def apply[A](x: F[A]): G[A]
@gkossakowski
gkossakowski / asSeenFrom.md
Last active Jun 19, 2018
Understand Scala's core typechecking rules
View asSeenFrom.md

Scala's "type T in class C as seen from a prefix type S" with examples

Introduction

Recently, I found myself in need to precisely understand Scala's core typechecking rules. I was particulary interested in understanding rules responsible for typechecking signatures of members defined in classes (and all types derived from them). Scala Language Specification (SLS) contains definition of the rules but lacks any examples. The definition of the rules uses mutual recursion and nested switch-like constructs that make it hard to follow. I've written down examples together with explanation how specific set of rules (grouped thematically) is applied. These notes helped me gain confidence that I fully understand Scala's core typechecking algorithm.

As Seen From

Let's quote the Scala spec for As Seen From (ASF) rules numbered for an easier reference:

You can’t perform that action at this time.