Skip to content

Instantly share code, notes, and snippets.

View oluies's full-sized avatar

Örjan Angré (Lundberg) oluies

  • Sweden
  • 21:45 (UTC +02:00)
  • X @oluies
View GitHub Profile
@jaimefjorge
jaimefjorge / scalaCliffHanger.scala
Created June 10, 2011 05:06
cliff hanger in Scala done in 15 minutes
object cliffHanger extends App{
val man = List(" 0\n","-","-","-\n"," |\n"," /","\\\n")
def drawState(tries:Int,word:String,letters:List[Char]) = {
println("\n\n\n")
println(man.dropRight(tries).mkString)
word.toList.foreach(c => if (letters.exists(c == _)) print(c) else print("_"))
println()
}
@jboner
jboner / SBT.sublime-build
Created May 6, 2011 09:47
Sublime Editor SBT build setup
{
"cmd": ["sbt-no-color compile"],
"file_regex": "^\\[error\\] ([.a-zA-Z0-9/-]+[.]scala):([0-9]+):",
"selector": "source.scala",
"working_dir": "${project_path:${folder}}",
"shell": "true"
}
@etorreborre
etorreborre / gist:958304
Created May 6, 2011 01:29
A great configuration trick with implicits and default values!
case class Config(name: String="none")
def methodNeedingAConfig(implicit config: Config = Config()) = config.name
// by default there is no config
methodNeedingAConfig === "none"
// just add one in the current scope
implicit val myConfig = Config("some")
anonymous
anonymous / gist:926273
Created April 18, 2011 21:53
apply plugin: 'groovy'
apply plugin: 'jetty'
apply plugin: 'eclipse'
apply from: 'http://resolver/gradle-scripts/repo-settings/internal-maven.gradle'
dependencies {
groovy 'org.codehaus.groovy:groovy:1.7.10'
compile 'org.springframework:spring-webmvc:3.0.5.RELEASE'
class Calc extends PackratParsers {
type Elem = Char
val vars = mutable.Map[Char,Int]()
def parse(input:CharSequence) = doIt(new PackratReader(new CharSequenceReader(input)))
val spaces: Parser[Seq[Char]] = elem("Whitespace", _.isWhitespace)*
val digit: Parser[Char] = elem("Digit", _.isDigit)
val letter: Parser[Char] = elem("Letter", _.isLetter)
package com.banksimple.util
private[util] final class Effectful[T](val origin: T) {
/**
* A special case of doto, andAlso is useful for
* quick logging or output tasks. Similar in use
* to doto, but only takes one function.
* */
def andAlso(x: T => Unit): T = { x(origin) ; origin }
@krasserm
krasserm / PromiseEither.scala
Created February 22, 2011 16:59
Composition of concurrent functions that may fail
import scalaz._
import Scalaz._
import scalaz.concurrent._
/**
* Result type of concurrent functions that may fail.
*/
case class PromiseEither[A, B](value: Promise[Either[A, B]]) extends NewType[Promise[Either[A, B]]]
/**
@buka
buka / AkkaWebSocketSampleService.scala
Created February 18, 2011 07:37
example to illustrate different ways of using websockets...
package sample
import akka.actor._
import akka.http._
class SampleService extends Actor with Endpoint
{
self.dispatcher = Endpoint.Dispatcher;
@viktorklang
viktorklang / MiniSTM.scala
Created February 9, 2011 18:06
Optimistic concurrency using AtomicReference
class MiniSTM[T <: AnyRef](initialValue: T) {
private val value = new AtomicReference[T](initialValue)
def apply(fun: T => T) {
@tailrec def update(expect: T): Unit =
if ( !value.compareAndSet(expect, fun(expect)) ) update(value.get)
update(value.get)
}
@seanparsons
seanparsons / gist:812488
Created February 5, 2011 14:30
Local Map-Reduce in less than 60 lines of code.
import java.util.concurrent.atomic.AtomicInteger
import akka.actor._
import akka.actor.Actor._
import akka.dispatch.Future
case class Reduce(val size: Int)
case class MappingDetail[T](val item: T, val reducer: ActorRef)
class MapperActor[T, U](val mapping: (T) => U) extends Actor {