Skip to content

Instantly share code, notes, and snippets.

View daithiocrualaoich's full-sized avatar

Daithi O Crualaoich daithiocrualaoich

View GitHub Profile
@daithiocrualaoich
daithiocrualaoich / gist:4269195
Created December 12, 2012 16:20
Circular impress.js slide layout in Javascript
var steps = document.getElementsByClassName("step");
var r = 2000;
for (var i = 0; i < steps.length; i++) {
var theta = -i/(steps.length-1) * 2 * Math.PI;
var x = r * Math.cos(theta);
var y = r * Math.sin(theta);
var rotation = theta/(2*Math.PI) * 360 - 90;
steps[i].setAttribute("data-x", Math.round(x).toString());
@daithiocrualaoich
daithiocrualaoich / ApplicationParameters.scala
Created December 18, 2012 16:03
Using the Hadoop Java API from Scala.
package com.gu.hadoop
import org.apache.hadoop.util.GenericOptionsParser
object ApplicationParameters {
def apply(args: Array[String]): List[String] = {
new GenericOptionsParser(args).getRemainingArgs.toList
}
}
@daithiocrualaoich
daithiocrualaoich / build.sbt
Created December 19, 2012 10:17
Scoobi `build.sbt` with the Avro snapshot fixed.
name := "Scoobi"
version := "1-SNAPSHOT"
scalaVersion := "2.9.2"
scalacOptions ++= Seq("-Ydependent-method-types", "-deprecation")
libraryDependencies += "com.nicta" %% "scoobi" % "0.6.0-cdh3-RC2"
package com.gu.scoobi
import com.nicta.scoobi.Scoobi._
object ScoobiRemoteCalculation extends ScoobiApp {
def run() {
val test = onHadoop {
scala.math.pow(2, 16)
}
@daithiocrualaoich
daithiocrualaoich / intersect.scala
Last active December 21, 2015 10:48
Intersection for ordered lists.
def intersect(ens: List[Int], ems: List[Int]): List[Int] = (ens, ems) match {
case (Nil, _) => Nil
case (_, Nil) => Nil
case (en :: ensTail, em :: emsTail) if en == em => en :: intersect(ensTail, emsTail)
case (en :: ensTail, em :: _) if en < em => intersect(ensTail dropWhile { _ < em }, ems)
case (en :: _, em :: emsTail) => intersect(ens, emsTail dropWhile { _ < en })
}
intersect(List(1, 2, 3, 4), List(3, 4, 5, 6)) // = List(3, 4)
intersect(List(3, 4, 5, 6), List(1, 2, 3, 4)) // = List(3, 4)
@daithiocrualaoich
daithiocrualaoich / gist:1189097
Created September 2, 2011 16:37
Scala Collections Pimp to add distinctBy(hash: ... => ...) for hash filterings
implicit def seq2Distinct[T, C[T] <: Seq[T]](tees: C[T]) = new {
import collection.generic.CanBuildFrom
import collection.mutable.{HashSet => MutableHashSet}
def distinctBy[S](hash: T => S)(implicit cbf: CanBuildFrom[C[T],T,C[T]]): C[T] = {
val builder = cbf()
val seen = MutableHashSet[S]()
for (t <- tees) {
if (!seen(hash(t))) {