Skip to content

Instantly share code, notes, and snippets.

View fedesilva's full-sized avatar
👁️‍🗨️

federico silva fedesilva

👁️‍🗨️
View GitHub Profile
// for comprehension
scala> for {
| l <- List(2,5,10)
| m <- List(8,10,11)
| } yield l * m
res17: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110)
// map a pure function into applicatives
scala> List(8,10,11) <*> (List(2,5,10) map (((_: Int) * (_: Int)).curried))
res18: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110)
//Usage:
//override def pomPostProcess(node: Node): Node = mcPom(moduleConfigurations)(super.pomPostProcess(node))
trait McPom { self: DefaultProject =>
import scala.xml._
def mcPom(mcs: Set[ModuleConfiguration])(node: Node): Node = {
//make sure we have a trailing slash so we deduplicate URLs properly
def cleanUrl(url: String) = url match {
case null => ""
@fedesilva
fedesilva / service
Created December 19, 2011 21:39 — forked from brentkirby/service
Unicorn + Runit + RVM
#!/bin/bash -e
#
# Since unicorn creates a new pid on restart/reload, it needs a little extra love to
# manage with runit. Instead of managing unicorn directly, we simply trap signal calls
# to the service and redirect them to unicorn directly.
#
# To make this work properly with RVM, you should create a wrapper for the app's gemset unicorn.
#
function is_unicorn_alive {
@gclaramunt
gclaramunt / ListZipper.scala
Created January 18, 2012 02:46
Simple list zipper
case class ListZipper[T](rev:List[T], fwd:List[T]){
override def toString = rev.reverse.toString ++" " ++ fwd.toString
def read:T= fwd.head
def add(c:T)=ListZipper(rev,c::fwd)
def update(c:T)=ListZipper(rev,c::fwd.tail)
def remove()=ListZipper(rev,fwd.tail)
def back=ListZipper(rev.tail,rev.head::fwd)
def forward=ListZipper(fwd.head::rev,fwd.tail)
@fedesilva
fedesilva / build.scala
Created March 12, 2012 22:04
sbt 0.11.2 task dependencies [PARTIALLY SOLVED]
import sbt._
import Keys._
/**
* How in the world do I make bye depend on hello?
* And how do I depend on a task like test?
* I have not been able to make this work
goodbyeTask <<= goodbyeTask.dependsOn(helloTask) as in https://github.com/harrah/xsbt/wiki/Tasks
no matter where I stick it!
Halp!
*/
@fedesilva
fedesilva / planes.scala
Created June 6, 2012 18:22 — forked from gclaramunt/planes.scala
Very simple phantom types example
trait Flying
trait Landed
case class Plane[Status]()
def land(p:Plane[Flying])=Plane[Landed]()
def takeOff(p:Plane[Landed])= Plane[Flying]()
val plane = new Plane[Landed]()
@fedesilva
fedesilva / MersenneTwister.scala
Created August 20, 2012 23:31 — forked from jesperdj/MersenneTwister.scala
Mersenne Twister - Random number generator
// Mersenne Twister 19937
// Based on code from: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
// Note: This implementation is not thread-safe!
final class MersenneTwister (seed: Int = 5489) {
private val N = 624
private val M = 397
private val MatrixA = 0x9908b0dfL
private val UpperMask = 0x80000000L
@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")
@puffnfresh
puffnfresh / where_tdd_fails.md
Last active December 14, 2015 13:39
Where TDD Fails (mirror for http://blog.precog.com/?p=431)

Where TDD Fails

I've just gotten back from the awesome mloc.js conference. There was a talk about compiling C# to JavaScript and one of the benefits explained was static types. Someone from the audience asked, who needs types when you do Test Driven Development?

I tried to address the question in my talk on Roy but I talked to some developers afterwards and they thought that TDD

@fedesilva
fedesilva / output.log
Last active December 20, 2015 15:09
Script to interact with the meetup api sends responses to deadletters.
scala> val rp = pipeline(rq)
rp: scala.concurrent.Future[spray.http.HttpResponse] = scala.concurrent.impl.Promise$DefaultPromise@597aa1d
scala> rp fp2013-08-216 20:18:26.560 INFO akka.actor.DeadLetterActorRef - Message [spray.http.HttpResponse] from Actor[akka://test/user/IO-HTTP/host-connector-0/0#229322353] to Actor[akka://test/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
2013-08-216 20:18:26.561 INFO akka.actor.LocalActorRef - Message [akka.io.Tcp$Write] from Actor[akka://test/user/IO-HTTP/group-0/0#-1483684089] to Actor[akka://test/system/IO-TCP/selectors/$a/0#634853586] was not delivered. [2] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
2013-08-216 20:18:26.561 INFO akka.actor.LocalActorRef - Message [akka.io.Tcp$ConfirmedClos