Skip to content

Instantly share code, notes, and snippets.

@fsarradin
fsarradin / PartitionCheck.scala
Created July 31, 2013 11:44
ScalaTest + ScalaCheck to test Java
import objectx.WeightedPoint
import objects.Pair
import org.scalacheck.Arbitrary
import org.scalatest.FreeSpec
import org.scalatest.matchers.MustMatchers
import org.scalatest.prop.Checkers
class PartitionCheck extends FreeSpec with Checkers with MustMatchers {
@fsarradin
fsarradin / MyHttpServer.scala
Created September 5, 2013 12:38
A Web Framework in Scala From Scratch
package scalawebapp
import com.sun.net.httpserver.{HttpExchange, HttpHandler, HttpServer}
import java.net.InetSocketAddress
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
class MyHttpServer(port: Int = 8080) {
@fsarradin
fsarradin / SortTest.java
Created April 11, 2014 07:27
Sort algo
import org.junit.Ignore;
import org.junit.Test;
import java.util.*;
public class SortTest {
@Test
public void testCollectionsSort() {
List<Integer> values = getValues();
@fsarradin
fsarradin / functor.py
Last active August 29, 2015 14:00
Attempt of typeclass in Python
from maybe import Maybe
from validation import Validation
def Typeclass():
class _Typeclass(object):
registered_class = {}
@classmethod
def instance_for(cls, object_type):
@fsarradin
fsarradin / gist:0f4b16938e0c010ce40c
Created August 5, 2014 04:31
IntelliJ IDEA live template for enum with by-name behavior
private static final Map<String, $CLASS_NAME$> $VAR_CLASS_NAME$sByName = create$CLASS_NAME$sByName();
private final String name;
$CLASS_NAME$() {
this(null);
}
$CLASS_NAME$(String name) {
this.name = name;
@fsarradin
fsarradin / FunctorModule.scala
Created December 9, 2014 15:18
Reader functor in Scala (the typeclass way)
object FunctorModule {
trait Functor[F[_]] {
def map[A, B](f: A => B): F[A] => F[B]
}
implicit class ReaderFunctor[E](r: E => _) extends Functor[({ type l[a] = E => a })#l] {
override def map[A, B](f: A => B): (E => A) => (E => B) = { r => r andThen f }
}
@fsarradin
fsarradin / GenericsTest.java
Last active August 29, 2015 14:21
Java generics confusion
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
public class GenericsTest {
@Test
public void should_convert___well_huh() throws Exception {
package me;
import java.util.Collection;
import java.util.function.Function;
public interface ClassToRefactor_Copy {
default void sendMessages(Collection<ParseResult<InputMessage>> parsedMessages) {
parsedMessages.stream()
.map(parsedMessage ->
import java.util.function.Function;
public interface Continuation<R, A> extends Function<Function<A, R>, R> {
@Override
R apply(Function<A, R> f);
default <B> Continuation<R, B> map(Function<A, B> f) {
return continuation(g -> apply(g.compose(f)));
}
@fsarradin
fsarradin / build.sbt
Created August 13, 2015 13:29
SBT vs MAVEN
libraryDependencies ++= Seq(
"org.springframework.data" % "spring-data-mongodb" % "1.7.2.RELEASE",
"org.springframework.boot" % "spring-boot-autoconfigure" % "1.2.5.RELEASE"
)