This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scala.collection.AbstractIterator | |
| class CustomIterator[T,U](it: Iterator[T])(f: (T => U)) extends AbstractIterator[U] { | |
| override def hasNext: Boolean = it.hasNext | |
| override def next(): U = f(it.next) | |
| } | |
| private def resourceAsStream(resource: String): Iterator[(String, String)] = { | |
| val stream : java.io.InputStream = getClass.getResourceAsStream(resource) | |
| val it = scala.io.Source.fromInputStream( stream ).getLines |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val x = Map(1 -> "a", 2 -> "b", 3 -> "c") | |
| val y = Map(1 -> "a", 2 -> "b") | |
| val diff : Map[Int, String] = x -- y.keySet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //------------------------------------------------------------------------------------------------- | |
| // This would be something equivalent to: | |
| // $ cat inputs.txt | fgrep -f includes.txt | fgrep -v -f excludes.txt | uniq | sort | |
| //------------------------------------------------------------------------------------------------- | |
| import scala.util.matching.Regex | |
| def grep(inputs: Seq[String], includes: Set[Regex], excludes: Set[Regex], sort: Boolean = false, uniq: Boolean = false): Iterable[String] = { | |
| def pass(s: String, set: Set[Regex]): Boolean = set.exists(r => r.findFirstIn(s).isDefined) | |
| val grep1: Iterable[String] = if(includes.size==0) inputs else for { c <- inputs if(pass(c, includes)) } yield { c } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Jupyter Scala kernel magic | |
| classpath.add("org.json4s" % "json4s-native_2.11" % "3.4.0") | |
| import org.json4s._ | |
| import org.json4s.native.Serialization | |
| implicit val formats = Serialization.formats(NoTypeHints) | |
| case class Subject(article: String, page: Int) | |
| case class Speaker(name: String, age: Int, subject: Subject) | |
| val speaker = Speaker("John Doe", 45, Subject("Doing It Yourself", 200)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Section "ServerLayout" | |
| Identifier "aticonfig Layout" | |
| Screen 0 "aticonfig-Screen[0]-0" 0 0 | |
| EndSection | |
| Section "Files" | |
| EndSection | |
| Section "Module" | |
| EndSection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # IntelliJ can be sluggish when indexing big projects. | |
| # So, I'm bashing IntelliJ on its head here with a huge sledgehammer. | |
| function intellij_clean { | |
| for home in $HOME/.IntelliJ* ;do | |
| for dir in caches jars js_caches jsp_related_caches compiler index compile-server ;do | |
| if [ -d $home/system/$dir ] ;then | |
| rm -r -f $home/system/$dir | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public enum Category { | |
| DIR (true, false), | |
| CLASS (false, true, true, ".class"), | |
| JAR (false, true, true, ".jar"), | |
| ZIP (false, true, true, ".zip"), | |
| NATIVE (false, true, true, Platform.instance().natives()), | |
| MANIFEST(false, false, false, "/MANIFEST.MF"), | |
| __ (false, false); // should not use '_' since source code compatibility with JDK8 prevents it. | |
| // http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import EasyMock._ | |
| def session: quickfix.Session = { | |
| val dictionaryXML = "/FIX42.xml" | |
| val dictionary = new DataDictionary(getClass.getResourceAsStream(dictionaryXML)) | |
| "Dictionary version"-{ | |
| assert("FIX.4.2"==dictionary.getVersion) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| implicit class RichMessage(m: quickfix.Message) { | |
| implicit def populate: quickfix.fix42.Message = { | |
| import quickfix.field.BeginString | |
| import quickfix.field.SenderCompID | |
| import quickfix.field.SenderLocationID | |
| import quickfix.field.SenderSubID | |
| import quickfix.field.TargetCompID | |
| import quickfix.field.TargetLocationID | |
| import quickfix.field.TargetSubID | |
| import quickfix.Message.Header |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package info.rgomes | |
| //-------------------------------------------------------------------------------- | |
| //NOTE: This implementation is "convenient" but it is O(n), which | |
| // is bad if you need realtime (predictable!) performance. | |
| // | |
| // A much better implementation which is O(1) can be found at | |
| // http://github.com/frgomes/scala-ring-buffer | |
| //-------------------------------------------------------------------------------- |