View JType.scala
This file contains 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 io.circe.{Decoder, Encoder} | |
import io.circe.syntax._ | |
sealed trait JType | |
/* | |
etype = "number" | "object" | "integer" | "string" | "null" | "array" | |
jtype = etype | array[etype] | |
see: https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.1.1 |
View 📊 Weekly development breakdown
This file contains 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
Scala 14 hrs 14 mins ███████████████▊░░░░░ 75.3% | |
YAML 2 hrs 46 mins ███░░░░░░░░░░░░░░░░░░ 14.7% | |
sbt 51 mins ▉░░░░░░░░░░░░░░░░░░░░ 4.6% | |
textmate 23 mins ▍░░░░░░░░░░░░░░░░░░░░ 2.1% | |
SQL 14 mins ▎░░░░░░░░░░░░░░░░░░░░ 1.3% |
View Anagrams.scala
This file contains 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 forcomp | |
import scala.collection.mutable | |
object Anagrams { | |
/** A word is simply a `String`. */ | |
type Word = String |
View Huffman.scala
This file contains 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 patmat | |
import common._ | |
/** | |
* Assignment 4: Huffman coding | |
* | |
*/ | |
object Huffman { |
View TweetSet.scala
This file contains 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 objsets | |
import TweetReader._ | |
/** | |
* A class to represent tweets. | |
*/ | |
class Tweet(val user: String, val text: String, val retweets: Int) { | |
override def toString: String = | |
"User: " + user + "\n" + |
View Funsets.scala
This file contains 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 funsets | |
/** | |
* 2. Purely Functional Sets. | |
*/ | |
object FunSets { | |
/** | |
* We represent a set by its characteristic function, i.e. | |
* its `contains` predicate. |
View refun.scala
This file contains 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 recfun | |
object Main { | |
def main(args: Array[String]) { | |
println("Pascal's Triangle") | |
for (row <- 0 to 10) { | |
for (col <- 0 to row) | |
print(pascal(col, row) + " ") | |
println() | |
} |
View binarySearch.scala
This file contains 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
def binarySearchFunctional(list: Array[Int], target: Int): Int = { | |
def bsf(list: Array[Int], target: Int, start: Int, end: Int): Int = { | |
if (start>end) return -1 | |
val mid = start + (end-start+1)/2 | |
list match { | |
case (arr:Array[Int]) if (arr(mid)==target) => mid | |
case (arr:Array[Int]) if (arr(mid)>target) => bsf(list, target, start, mid-1) | |
case (arr:Array[Int]) if (arr(mid)<target) => bsf(list, target, mid+1, end) | |
} | |
} |
View grep.scala
This file contains 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 filesHere = (new java.io.File(args(0))).listFiles | |
def fileLines(file: java.io.File) = | |
scala.io.Source.fromFile(file).getLines().toList | |
def grep(pattern: String) = | |
for ( | |
file <- filesHere | |
if file.getName.endsWith(".scala"); | |
line <- fileLines(file) | |
if line.trim.matches(pattern) | |
) println(file + ": " + line.trim) |
View tail.scala
This file contains 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.sys.process._ | |
def someProcessing(line: String): Unit = { | |
print("[just read this line] ") | |
println(line) | |
} | |
val file = "1.txt" | |
val tail = Seq("tail", "-F", file) |