Skip to content

Instantly share code, notes, and snippets.

@eed3si9n
eed3si9n / kind.scala
Created September 3, 2012 16:40
calculates a type's kind
// requires Scala 2.10.0-M7
def kind[A: scala.reflect.TypeTag]: String = {
import scala.reflect.runtime.universe._
def typeKind(sig: Type): String = sig match {
case PolyType(params, resultType) =>
(params map { p =>
typeKind(p.typeSignature) match {
case "*" => "*"
case s => "(" + s + ")"
}
@gclaramunt
gclaramunt / Ids.scala
Created September 9, 2012 03:05
Tagged Ids using Phantom types
trait Entity
trait User extends Entity
trait Product extends Entity
case class Id[T<:Entity](id:String)
def buy(pId:Id[Product],uId:Id[User])="Bought product %s for user %s".format(pId.id,uId.id)
val pId=new Id[Product]("1")
@tonymorris
tonymorris / Balance.scala
Created September 23, 2012 01:43
Balance Parentheses
// Missing support libraries
object MissingLibraries {
case class State[S, +A](run: S => (A, S)) {
def map[B](f: A => B): State[S, B] =
State(s => {
val (a, t) = run(s)
(f(a), t)
})
def flatMap[B](f: A => State[S, B]): State[S, B] =
C:\Users\brianf>curl -I --insecure "https://repository.apache.org/service/local/
artifact/maven/redirect?r=snapshots&g=org.apache.maven&a=maven-core&v=3.1-SNAPSH
OT&e=jar"
HTTP/1.1 301 Moved Permanently
Date: Tue, 06 Nov 2012 17:19:19 GMT
Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V4
Content-Type: application/xml; charset=ISO-8859-1
Location: https://repository.apache.org/service/local/repositories/snapshots/con
tent/org/apache/maven/maven-core/3.1-SNAPSHOT/maven-core-3.1-20121105.160646-45.
jar
@tixxit
tixxit / fizzbuzz.scala
Created November 14, 2012 16:04
Compile time FizzBuzz in Scala.
package net.tixxit
import shapeless._
import Nat._
final class Fizz
final class Buzz
trait FizzBuzzAux[A <: Nat, B <: HList] {
def apply(): List[String]
@stew
stew / fizzbuzz.scala
Created November 14, 2012 20:55
fizzbuzz in the scala type system
package fizzbuzz
// This is church encoding of natural numbers
sealed trait Num {
def toInt : Int
override def toString = toInt.toString
}
final case object Z extends Num {
def toInt : Int = 0
@olasitarska
olasitarska / pgessays.py
Created November 18, 2012 10:11
Builds epub book out of Paul Graham's essays.
# -*- coding: utf-8 -*-
"""
Builds epub book out of Paul Graham's essays: http://paulgraham.com/articles.html
Author: Ola Sitarska <ola@sitarska.com>
Copyright: Licensed under the GPL-3 (http://www.gnu.org/licenses/gpl-3.0.html)
This script requires python-epub-library: http://code.google.com/p/python-epub-builder/
"""
@travisbrown
travisbrown / fizzbuzz.scala
Created November 18, 2012 19:31
FizzBuzz in the type system
// Searching for large ModAux instances can be extremely slow.
// See this version for a faster solution: https://gist.github.com/4108026
import shapeless._, Nat._
trait FizzBuzz[N <: Nat] {
def steps: List[String]
def show = println(steps.reverse.mkString("\n"))
}
@ymasory
ymasory / bay-scala-jobs
Last active February 18, 2020 20:48
Companies hiring Scala developers in the Bay Area.
Companies hiring Scala developers in the Bay Area.
Created in response to a thread on scala-base.
My favorites:
- CloudPhysics
- Wordnik
Unbiased list:
- 10Gen
- Audax Health
@puffnfresh
puffnfresh / MonadMonoid.hs
Created May 9, 2013 20:38
Monad is a monoid.
class Monoid m where
mappend :: m -> m -> m
mempty :: m
mconcat :: Monoid m => [m] -> m
mconcat = foldr mappend mempty
newtype MonadMonoid m a =
MonadMonoid { getMonad :: a -> m a }