Skip to content

Instantly share code, notes, and snippets.

View sofoklis's full-sized avatar

Sofoklis Papasofokli sofoklis

View GitHub Profile
~01001~^~Y~^~some text1~^~~^1.38
~01002~^~N~^~some text2~^~~^2.38
~01003~^~Y~^~some text3~^~full test~^3.38
~01004~^~N~^~some text4~^~~^4.38
~01005~^~Y~^~some text5~^~dddd~^5.38
~01006~^~N~^~some text6~^~~^6.38
~01007~^~Y~^~some text7~^~~^7.38
~01008~^~Y~^~some text8~^~~^8.38
@sofoklis
sofoklis / gist:1992349
Created March 7, 2012 10:06
simple loop and read regex
lines.foreach(line ⇒ line match {
case RegEx(id, yesNo, name, optional, amount) ⇒ println(Line(id.toLong,
booleanFromString(yesNo).get,
name, optionString(optional), amount.toDouble))
case _ ⇒ println("Something Wrong!")
})
@sofoklis
sofoklis / LogiclaExpressionParser.scala
Last active December 9, 2020 12:40
Parser Combinators - A logical expression parser
package org.papasofokli
import scala.util.parsing.combinator.JavaTokenParsers
/**
* <b-expression>::= <b-term> [<orop> <b-term>]*
* <b-term> ::= <not-factor> [AND <not-factor>]*
* <not-factor> ::= [NOT] <b-factor>
* <b-factor> ::= <b-literal> | <b-variable> | (<b-expression>)
*/
@sofoklis
sofoklis / gist:3483568
Created August 26, 2012 21:00
b_not_factor
private lazy val b_not_factor: Parser[Boolean] = opt("not") ~ b_factor ^^ (x ⇒ x match { case Some(v) ~ f ⇒ !f; case None ~ f ⇒ f })
@sofoklis
sofoklis / gist:3483572
Created August 26, 2012 21:00
b_not_factor part 1
opt("not") ~ b_factor
@sofoklis
sofoklis / gist:3483573
Created August 26, 2012 21:01
b_not_factor part 2
(x ⇒ x match { case Some(v) ~ f ⇒ !f; case None ~ f ⇒ f })
package org.example
import scala.concurrent.{ Future, Promise, future, promise }
import scala.concurrent.ExecutionContext.Implicits.global
class FuturesAndPromises
object FuturesAndPromises {
def main(args: Array[String]) {
futureSample
@sofoklis
sofoklis / GenericType.scala
Last active December 11, 2015 05:08
generic type
class NonVariantType[T]
{
// some functions and fields
}
@sofoklis
sofoklis / NonVariantType.scala
Created January 16, 2013 20:08
NonVariantType.scala
val string: Any = "sofoklis" // String is a proper subtype of any
val nonVariantType1: NonVariantType[String] = new NonVariantType[String] // Allowed
val nonVariantType2: NonVariantType[Any] = new NonVariantType[String] // Compile error
val nonVariantType3: NonVariantType[String] = new NonVariantType[Any] // Compile error
@sofoklis
sofoklis / CovariantType.scala
Created January 16, 2013 20:16
CovariantType
class CovariantType[+T] {
// some functions and fields
}