Skip to content

Instantly share code, notes, and snippets.

View karthik20522's full-sized avatar
๐Ÿ‘Š

Karthik Srinivasan karthik20522

๐Ÿ‘Š
View GitHub Profile
@karthik20522
karthik20522 / scp4.scala
Created May 25, 2019 06:54
Scala Query Parser
//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,
@karthik20522
karthik20522 / scp5.scala
Created May 25, 2019 06:57
Scala Query Parser
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
@karthik20522
karthik20522 / shopify.js
Created May 25, 2019 07:19
Shopify conversion tracking
<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,
@karthik20522
karthik20522 / shopify2.js
Created May 25, 2019 07:21
shopify cart tracking
<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 }}
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);
});
}
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
//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)
{
public class Weather {
public string city;
public int curr_temp;
public string curr_text;
public int curr_icon;
public List < Forecast > forecast = new List < Forecast > ();
}
public class Forecast {
public string day_date;
using System.Web.Optimization;
namespace ClipTheTripWeb {
public class BundleConfig {
public static void RegisterBundles(BundleCollection bundles) {
var homeBundleJs = new Bundle("~/content/js/home", new JsMinify());
homeBundleJs.Include(
"~/Content/Js/jquery.fullscreenr.js",
"~/Content/Js/jquery.autoSuggest.js",
"~/Content/Js/home.js"
@karthik20522
karthik20522 / dockerfunctions.sh
Created August 17, 2019 19:23
docker functions
#!/bin/bash
function dock() {
# Point docker client and docker-machine to the given node
eval "$(docker-machine env --shell bash $@)"
}
# Remove all containers as well as clear out dangling images
function cleardock() {
docker rm -f $(docker ps -aq) 2> /dev/null
docker rmi $(docker images --filter "dangling=true" -q) 2> /dev/null