Skip to content

Instantly share code, notes, and snippets.

object PrimeGenerator {
def getPrimes(start:Int,end:Int):Seq[Int] = Seq(1,2,3,4) //stub
def splitInput(line:String) = {
val parts = line.split(" ")
if(parts.length != 2) { sys.error("not cool") }
(parts(0).toInt,parts(1).toInt)
}
def main(args: Array[String]){
@lossyrob
lossyrob / install-gdal
Last active August 10, 2017 18:53
Script to install GDAL on Ubuntu 12.04 LTS
# Install subversion
sudo apt-get -y install subversion
# Install g++
sudo apt-get -y install g++
# Install Hierarchical Data Format library
# NOTE: This library is not necessarily needed, but was required
# in order for this to compile against a clean Ubuntu 12.04 LTS system.
# I didn't need it on a clean EC2 Ubuntu 12.10 instance, so
@lossyrob
lossyrob / merge.scala
Created December 15, 2013 03:39
GeoTrellis 0.9 code snippet for merging rasters.
import geotrellis._
import geotrellis.source._
import geotrellis.raster._
import geotrellis.data.arg._
object Main {
def main(args:Array[String]):Unit = {
println("Merging...")
GeoTrellis.init(GeoTrellisConfig("/home/rob/data/sf/catalog.json"))
@lossyrob
lossyrob / gist:8983681
Created February 13, 2014 20:57
geotrellis-geotools dependency tree
[info] com.azavea.geotrellis:geotrellis-geotools_2.10:0.10.0-SNAPSHOT [S]
[info] +-com.azavea.geotrellis:geotrellis_2.10:0.10.0-SNAPSHOT [S]
[info] | +-com.azavea.geotrellis:geotrellis-macros_2.10:0.10.0-SNAPSHOT [S]
[info] | | +-org.scala-lang:scala-reflect:2.10.1 (evicted by: 2.10.2)
[info] | | +-org.scala-lang:scala-reflect:2.10.2 [S]
[info] | |
[info] | +-com.typesafe.akka:akka-actor_2.10:2.2.3 [S]
[info] | | +-com.typesafe:config:1.0.2
[info] | |
[info] | +-com.typesafe.akka:akka-cluster_2.10:2.2.3 [S]
@lossyrob
lossyrob / maptojson.scala
Created February 20, 2014 15:30
Mao to Json
// TODO: See if this is any good and worth refactoring. From some internal Scala code written by someone at Azavea.
package object json {
def quote(s:String) = if(s == null) "\"\"" else "\"" + (s.replace("\\", "\\\\").replace("\"", "\\\"")) + "\""
def quote(a:Any):String = if(a == null) "\"\"" else quote(a.toString)
def arrayToJson(left:String, as:Array[String], right:String) = if (as.length > 0) {
val n = as.foldLeft(0)(_ + _.length + 1) + left.length + right.length
val b = new StringBuilder(n)
b.append(left)
b.append(as(0))
@lossyrob
lossyrob / averagelotsofrasters.scala
Created June 25, 2014 16:58
AverageLotsOfRasters for GeoTrellis 0.8
package geotrellis.raster.op
import geotrellis._
import geotrellis.feature.Extent
import geotrellis.process._
import geotrellis.raster.op._
import geotrellis.testkit._
import geotrellis.raster.op.local.Add
import org.scalatest._
/** GDAL will translate a GeoTIFF with these boundies in EPSG:4326 -
* Upper Left ( -85.4969788, 35.4371767) ( 85d29'49.12"W, 35d26'13.84"N)
* Lower Left ( -85.4969788, 35.3464955) ( 85d29'49.12"W, 35d20'47.38"N)
* Upper Right ( -85.2701788, 35.4371767) ( 85d16'12.64"W, 35d26'13.84"N)
* Lower Right ( -85.2701788, 35.3464955) ( 85d16'12.64"W, 35d20'47.38"N)
* Center ( -85.3835788, 35.3918361) ( 85d23' 0.88"W, 35d23'30.61"N)
*
* to these boundry points in EPSG:3857 -
* Upper Left (-9517480.140, 4223451.561) ( 85d29'49.12"W, 35d26'13.84"N)
* Lower Left (-9517480.140, 4211063.427) ( 85d29'49.12"W, 35d20'47.24"N)
@lossyrob
lossyrob / write-one-line-text.scala
Last active August 14, 2019 07:54
Read \ Write a text file in one line Scala
def write(path: String, txt: String): Unit = {
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
Files.write(Paths.get(path), txt.getBytes(StandardCharsets.UTF_8))
}
def read(path: String): String =
scala.io.Source.fromFile(path, "UTF-8").getLines.mkString
@lossyrob
lossyrob / WashingtonDC.wkt
Last active August 29, 2015 14:07
Washing DC transit system in at list of lines as WKT. MultiLineString([lines]).union ends up with an invalid MultiLineString.
This file has been truncated, but you can view the full file.
LINESTRING (-77.001406 38.825079, -77.001508 38.825046, -77.001406 38.825079, -77.00138 38.824887, -77.001353 38.824578, -77.001423 38.824358, -77.001591 38.824169, -77.002189 38.82389, -77.002175 38.823876, -77.00221 38.823879, -77.002011 38.823588, -77.001943 38.823399, -77.001921 38.823229, -77.001931 38.822728, -77.001941 38.822547, -77.001952 38.822279, -77.001961 38.821829, -77.00129 38.821289, -77.000743 38.821709, -77.000664 38.821766, -77.000643 38.821752, -76.999292 38.822807, -76.998492 38.823449, -76.998182 38.823676, -76.998099 38.82361, -76.998099 38.82361, -76.998101 38.823739, -76.997962 38.823849, -76.997344 38.824301, -76.997316 38.824282, -76.996921 38.824608, -76.99644 38.825, -76.996131 38.825249, -76.99591 38.825408, -76.99591 38.825413, -76.99591 38.825413, -76.993595 38.82723, -76.992603 38.827978, -76.992539 38.828044, -76.99202 38.828395, -76.991052 38.829198, -76.991013 38.829228, -76.99103 38.829244, -76.990473 38.829628, -76.988993 38.83079, -76.988932 38.830836, -76.98897 38.8308
@lossyrob
lossyrob / MergeQueue.scala
Last active August 29, 2015 14:12
Merge Queue: Queue which merges Long ranges.
package mergequeue
class MergeQueue(initialSize: Int = 1) {
private var array = if(initialSize <= 1) { Array.ofDim[(Long, Long)](1) } else { Array.ofDim[(Long, Long)](initialSize) }
private var _size = 0
def size = _size
private def removeElement(i: Int): Unit = {
if(i < _size - 1) {