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
//example: http://www.bing.com/local/default.aspx?what=Saravana&where=London | |
var html = new WebClient().DownloadString("http://www.bing.com/local/default.aspx?what=" + name + "&where=" + location); | |
var htmlDoc = new HtmlAgilityPack.HtmlDocument(); | |
htmlDoc.OptionFixNestedTags = true; | |
htmlDoc.LoadHtml(html); | |
var nodes = htmlDoc.DocumentNode.SelectNodes("//div[@class='ecEnclosure']"); | |
if (nodes != null) | |
{ |
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
var chunkSize = 1048; //default chunksize | |
var a = new XMLHttpRequest(); | |
a.onreadystatechange = function() { | |
if (a.readyState == 4 && a.status == 200) { | |
var timeToLoad = new Date - startPingDate; | |
chunkSize = Math.round(chunkSize - (timeToLoad * Math.random())); | |
if (chunkSize < 256) | |
chunkSize = 256; //set a default value if too low |
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 class ImagePersistanceActor: ReceiveActor, ILogReceive { | |
public ImagePersistanceActor() { | |
Receive < string > (message => { | |
Console.WriteLine("Echo from Recieve actor: " + message); | |
}); | |
Receive < Image > (image => { | |
Console.WriteLine("OK form Receive Actor: " + image.Id); | |
}); | |
} |
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
<script type="text/javascript"> | |
var productsArray = []; | |
{% for item in cart.items %} | |
item = { | |
'sku': '{{ item.sku }}', | |
'price': {{ item.price | money_without_currency }}, | |
'size': '{{ item.variant.option2 }}', | |
'quantity': {{ item.quantity }} |
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
<script type="text/javascript"> | |
var items = {{ order.line_items | json }}; | |
var item; | |
var productsArray = []; | |
for(var i = 0; i < items.length; i++) { | |
item = { | |
'sku': items[ i ].variant.sku, | |
'price': items[ i ].price, | |
'size': items[ i ].variant.option2, |
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 org.scalatest.matchers.ShouldMatchers | |
import org.scalatest._ | |
class SQLParserSpec extends FunSpec with ShouldMatchers { | |
val p = new SQLParser | |
describe("given a sql string with an order clause") { | |
describe("(when direction is asc)") { | |
val sql = "select name from users order by name asc" | |
it("should be parsed into an Asc object containing the given field") { | |
val query = p.parse(sql).get |
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
//case classes: https://github.com/karthik20522/ESQL/blob/master/src/main/scala/com/karthik/esql/sql/QueryBuilder.scala | |
import scala.util.parsing.combinator._ | |
import scala.util.parsing.combinator.syntactical._ | |
case class Query( | |
val operation: Operation, | |
val from: From, | |
val where: Option[Where], | |
val order: Option[Direction] = None, |
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
def where: Parser[Where] = "where" ~> rep(predicate) ^^ (Where(_: _*)) | |
def predicate = ( | |
ident ~ "=" ~ wholeNumber ^^ { case f ~ "=" ~ i => NumberEquals(f, i.toInt) } | |
| ident ~ "<" ~ wholeNumber ^^ { case f ~ "<" ~ i => LessThan(f, i.toInt) } | |
| ident ~ ">" ~ wholeNumber ^^ { case f ~ ">" ~ i => GreaterThan(f, i.toInt) }) | |
//output: GreaterThan("age", 30) |
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
abstract class Direction | |
case class Asc(field: String*) extends Direction | |
case class Desc(field: String*) extends Direction | |
def order: Parser[Direction] = { | |
("order" ~> "by" ~> ident ~ ("asc" | "desc") ^^ { | |
case f ~ "asc" => Asc(f) | |
case f ~ "desc" => Desc(f) | |
}) | ("order" ~> "by" ~> repsep(ident, ",") ~ ("asc" | "desc") ^^ { | |
case f ~ "asc" => Asc(f: _*) |
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
abstract class Direction | |
case class Asc(field: String*) extends Direction | |
case class Desc(field: String*) extends Direction | |
def order: Parser[Direction] = { | |
"order" ~> "by" ~> ident ~ ("asc" | "desc") ^^ { | |
case f ~ "asc" => Asc(f) | |
case f ~ "desc" => Desc(f) | |
} | |
} |