Skip to content

Instantly share code, notes, and snippets.

View counter2015's full-sized avatar
📖
study

counter2015 counter2015

📖
study
View GitHub Profile
@counter2015
counter2015 / JType.scala
Last active August 2, 2022 08:04
A json-schema draft
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
@counter2015
counter2015 / 📊 Weekly development breakdown
Last active June 12, 2022 16:05
Weekly development breakdown
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%
@counter2015
counter2015 / Anagrams.scala
Created May 6, 2020 15:58
Coursera Programming in Scala Week 6 homework
package forcomp
import scala.collection.mutable
object Anagrams {
/** A word is simply a `String`. */
type Word = String
@counter2015
counter2015 / Huffman.scala
Last active November 25, 2019 11:38
Functional Programming Principles in Scala Week4 Code
package patmat
import common._
/**
* Assignment 4: Huffman coding
*
*/
object Huffman {
@counter2015
counter2015 / TweetSet.scala
Created September 3, 2019 16:25
Functional Programming Principles in Scala Week2 Code
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" +
@counter2015
counter2015 / Funsets.scala
Created August 3, 2019 14:35
Functional Programming Principles in Scala Week2 Code
package funsets
/**
* 2. Purely Functional Sets.
*/
object FunSets {
/**
* We represent a set by its characteristic function, i.e.
* its `contains` predicate.
@counter2015
counter2015 / refun.scala
Created July 30, 2019 08:50
Functional Programming Principles in Scala Week1 Code
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()
}
@counter2015
counter2015 / binarySearch.scala
Created May 17, 2019 07:34
functional style of binary search
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)
}
}
@counter2015
counter2015 / grep.scala
Created May 17, 2019 06:52
a simple implement of grep
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)
@counter2015
counter2015 / tail.scala
Created December 14, 2018 02:52
a simple tail script which can detect file change of symbol link
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)