Skip to content

Instantly share code, notes, and snippets.

View almendar's full-sized avatar

Tomasz Kogut almendar

View GitHub Profile
def p9[T](list: Seq[T]): Seq[Seq[T]] = {
@tailrec
def p9acc[T](list: Seq[T],acc:Seq[Seq[T]]): Seq[Seq[T]] = {
list match {
case Nil => acc
case x::xs =>
val (pref, suf) = list.span(_ == list.head)
p9acc(suf,pref+:acc)
}
}
@almendar
almendar / 0_reuse_code.js
Created June 7, 2014 20:56
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@almendar
almendar / gist:3d41fcec6ea8bb1dc44c
Last active August 29, 2015 14:16
Stacking actors
import akka.actor.{Props, ActorSystem, Actor, ActorLogging}
object AllActorsActions {
case object PrintHello
}
trait AllActorsActions extends Actor { self : ActorLogging =>
import AllActorsActions._
@almendar
almendar / FpDynamicDispatch.scala
Last active October 15, 2018 13:47
Functional dynamic dispatch
case class Circle(radius: Double)
case class Rectangle(x: Double, y: Double)
case class Square(x: Double)
trait ShapeOps[T] {
def perimter(t: T): Double
def area(t: T): Double
}
object ShapeOps {
package main
import (
"fmt"
"io/ioutil"
"log"
"sort"
"strconv"
"strings"
)
package main
import (
"fmt"
"io/ioutil"
"log"
"sort"
"strings"
)
import java.nio.file.{Files,Paths}
import scala.collection.mutable.ArrayDeque
import scala.collection.mutable
val mapping = Map(
']' -> '[',
')' -> '(',
'}' -> '{',
'>' -> '<'
package main
import (
"fmt"
"io/ioutil"
"log"
"strings"
)
func readInput(input string) map[string][]string {
package main
import (
"fmt"
"io/ioutil"
"log"
"strconv"
"strings"
)
package main
import (
"fmt"
"io/ioutil"
"log"
"math"
"strings"
)