Skip to content

Instantly share code, notes, and snippets.

View fancellu's full-sized avatar

Dino Fancellu fancellu

View GitHub Profile
@fancellu
fancellu / PostProcessScalaxb.scala
Last active December 23, 2015 07:29
Quick app to postprocess source files. Created because Scalaxb was converting '-' to u45 in class names.
package com.felstar.playpen.scalaxb
import java.io.File
object PostProcessScalaxb {
def allFiles(path:File):List[File]= {
val (dirs,files)=path.listFiles.toList.partition(_.isDirectory)
files ::: dirs.flatMap(allFiles)
}
package com.barclays.buyit.mgs
import java.util.Date
import com.espertech.esper.client._
import scala.beans.BeanProperty
object EsperTest extends App {
case class Tick(@BeanProperty symbol:String,@BeanProperty price:Double,@BeanProperty timestamp:Long=System.currentTimeMillis)
package com.felstar.xqs.example
import com.felstar.xqs.XQS._
import com.felstar.xqs.XQS.AllImplicits._
import xml.PrettyPrinter
import com.xqj2.XQConnection2
object BaseXEmbeddedXQS extends App {
@fancellu
fancellu / SunSpot.scala
Created January 20, 2014 18:13
Scala Sunspot Interview question I was given. Here's the word doc question https://app.box.com/s/1e8ukxjr25f2luj99t2f
object SunSpot {
def main(args: Array[String]): Unit = {
type Cube = Array[Array[Int]]
def sumCube(arr: Cube):Int = arr map (_.sum) sum
def getSampleCube(cube: Cube, y: Int, x: Int): Cube = cube.slice(y - 1, y + 2) map (_.slice(x - 1, x + 2))
def toCube(st: String, size: Int): Cube = st.split(" ").map(_.toInt).grouped(size).toArray
@fancellu
fancellu / Spec
Created February 11, 2014 09:12
Scala coding test (note error in the Spec I was sent, I'll let you work out what it was)
Exercise
Implement a console-based social networking application (similar to Twitter) satisfying the scenarios below.
Scenarios
Posting: Alice can publish messages to a personal timeline
> Alice -> I love the weather today
> Bob -> Oh, we lost!
> Bob -> at least it's sunny
@fancellu
fancellu / ForScalaJS.scala
Last active April 15, 2016 03:36
Conway's Game of Life in Scala
import org.scalajs.dom
// Paste here http://www.scala-js-fiddle.com/
// Ctrl-enter to recompile
@JSExport
object ScalaJSExample{
type Coord = Pair[Int, Int]
type CoordSet = Set[Coord]
@fancellu
fancellu / XMLCR.scala
Created February 28, 2014 17:48
Fix for better control over XML output. Hope this little tip helps.
val that= <that>x</that>
val thatcr= Seq(that,Text("\n"))
val xml= <root>
{ for (x<-1 to 4) yield that }
{ for (x<-1 to 4) yield
@fancellu
fancellu / Debbie_Harry.xquery
Created March 14, 2014 15:28
Example of MarkLogic 7 Semantic triple query, emitting as custom XML
xquery version "1.0-ml";
let $out:=sem:sparql('
SELECT *
WHERE { <http://dbpedia.org/resource/Debbie_Harry> ?p ?o }
')
for $i in $out
let $p:=map:get($i,"p")
let $o:=map:get($i,"o")
@fancellu
fancellu / Rational.scala
Last active August 29, 2015 13:57
Nice OO Scala example for a talk for Harvey Nash
object Rational extends App {
case class Rational(n: Int, d: Int=1) extends Ordered[Rational]{
require(d != 0)
private def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
private val g = gcd(n.abs, d.abs)
val numer = n / g
val denom = d / g
def + (that: Rational) = Rational( numer * that.denom + that.numer * denom, denom * that.denom)
@fancellu
fancellu / ThrottledProcessor.scala
Created April 1, 2014 18:34
ThrottledProcessor.scala (little example for an intro to Scala talk)
import akka.actor.ActorSystem
import scala.concurrent.duration._
import akka.actor.ActorDSL._
object ThrottledProcessor extends App {
implicit val system = ActorSystem("ThrottledProcessor")
import system.dispatcher
case object Dump
case object Process