Skip to content

Instantly share code, notes, and snippets.

View sofoklis's full-sized avatar

Sofoklis Papasofokli sofoklis

View GitHub Profile
@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 / 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: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!")
})
~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:1992310
Created March 7, 2012 09:56
scala regular expressions example
case class Line(id : Long, yesNo : Boolean, name : String, optional : Option[String], amount : Double)
object SimpleImport {
// Create the field regex so you can compose them
//and be able to simply extract the information
val sourceFolder : String = "/home/sofoklis/Desktop"
val digit = """~(\d*)~"""
val double = """([-+]?[\d]*\.?[\d]+)*"""
val text = """~([^~]*)~"""
val separator = """\^"""
@sofoklis
sofoklis / gist:1766971
Created February 8, 2012 08:55
lift json autocomplete snippet
import net.liftweb.http._
import S._
import js._
import JsCmds._
import JE._
import net.liftweb.textile._
import net.liftweb.common._
import net.liftweb.util._
import Helpers._
import scala.xml._
@sofoklis
sofoklis / gist:1766968
Created February 8, 2012 08:54
lift json autocomplete html
<div class="lift:surround?with=default;at=content">
<div class="lift:jsonAutocomplete">
<script id="script"></script>
<div class="demo">
<div class="ui-widget">
<label for="city">Your city: </label>
<input id="city" />
</div>
</div>
</div>
@sofoklis
sofoklis / gist:1747029
Created February 5, 2012 18:24
jQuery autocomplete
$( "#city" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
name_startsWith: request.term
@sofoklis
sofoklis / gist:1730616
Created February 3, 2012 15:10
html template
<div class="lift:surround?with=default;at=content">
<b>Ajax Example</b>
<br />
<div class="lift:ajaxCall.sample">
<div id="script"></div>
<textarea id="ajax_question" rows="8" cols="50"></textarea>
<br />
<button id="button">Click Me</button>
</div>
</div>
@sofoklis
sofoklis / gist:1730594
Created February 3, 2012 15:05
lift ajax basics
import net.liftweb.http._
import S._
import js._
import JsCmds._
import JE._
import net.liftweb.util._
import Helpers._
import scala.xml.Text
class AjaxCall {