Skip to content

Instantly share code, notes, and snippets.

@tilakpatidar
tilakpatidar / NLP Lab workshop 17th May 2016.md
Last active May 17, 2016 12:44
Resource links for the workshop conducted by NLP lab on 17th May 2016.

#Semantic Search engine – NLP lab

###17/05/2016 Task

http://blog.aiesec.in/

Use the above blog to scrap the following information and show in terminal (ubuntu) or in a file in windows.

def value(k, degree, coefficients):
ans = 0
prev = 1
for i in xrange(degree+1):
if i != 0:
prev = prev * k
ans += coefficients[i] * prev
return ans
degree = input()
coefficients = map(int,raw_input().split())
@tilakpatidar
tilakpatidar / clojure_basics.clj
Last active January 24, 2017 11:41
clojure basics
;Clojure is compiled language but has a eval function like lisp which allows to run compiler within execution
;Visit https://learnxinyminutes.com/docs/clojure/ for more gists
5 ; ⇒ 5
"hi" ; ⇒ "hi"
[1 2 3] ; evaluates to the vector `[1 2 3]`
(+ 1 2) ; evaluates to the sum of 1 and 2
(if true "yes" "no") ; evaluates to the string "yes"
(println "hello!") ; evaluates to nil (but also prints "hello!")
@tilakpatidar
tilakpatidar / delete_by_query.py
Created April 5, 2017 05:28
Elasticsearch delete by query
import elasticsearch as es
db = es.Elasticsearch(['y-monitoring-vm2.dnspam'], port= 9200)
db.delete_by_query(index= 'lake_garda_hadoop-test', doc_type='stock_accuracy', body={})
@tilakpatidar
tilakpatidar / 0_reuse_code.js
Created April 15, 2017 07:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tilakpatidar
tilakpatidar / lazy_eval_functions.scala
Last active April 15, 2017 07:34
Describes the usage of non-strict functions in scala using lazy and => syntax.
//passing functions as params and executing them when required
def if2[A](cond: Boolean, onTrue: () => A, onFalse: () => A): A ={
if (cond) onTrue() else onFalse()
}
//=> using arrow syntax pass params as unevaluated but they will be
//evaluated once they are referenced no need to mention () to execute them
def if2[A](cond: Boolean, onTrue: => A, onFalse: => A): A ={
if (cond) onTrue else onFalse
}
@tilakpatidar
tilakpatidar / lazy_val.scala
Created April 15, 2017 07:53
From http://stackoverflow.com/questions/7484928/what-does-a-lazy-val-do Example of how lazy val does memoization. Values are evaluated on first call only.
val x = { println("x"); 15 }
//x
//x: Int = 15
lazy val y = { println("y"); 13 }
//y: Int = <lazy>
x
//res2: Int = 15
y
//y
@tilakpatidar
tilakpatidar / monit_http_monitor.conf
Created April 19, 2017 08:47
Monit monitor process without pid instead using HTTP request
check host appsrv1 with address 127.0.0.1
start program = "/sbin/start myapp"
stop program = "/sbin/stop myapp"
alert alerts@example.com on {timeout,connection}
if failed port 9009 protocol HTTP
request /
with timeout 3 seconds
then restart
if 10 restarts within 10 cycles then timeout
if 10 restarts within 10 cycles then exec "/usr/bin/monit start aws-dns-healthcheck"
@tilakpatidar
tilakpatidar / keybase.md
Created August 10, 2017 10:01
My keybase declaration

Keybase proof

I hereby claim:

  • I am tilakpatidar on github.
  • I am tilakpatidar (https://keybase.io/tilakpatidar) on keybase.
  • I have a public key ASBrc8-ucimp_8n0hPOuAsj1mFBpAf84XYHuuGuTavTTewo

To claim this, I am signing this object:

import org.apache.spark.sql.functions.udf
import spark.sessionState.conf
conf.setConfString("spark.sql.pivotMaxValues", "" + Int.MaxValue)
val csv = spark.read.format("csv").option("header", true).load("/Users/tilak/Downloads/Pam/SalesAnalysis/data/store_sales_unified_2017.csv")
val uniqueKey: (String, String, String, String) => String = (x, y, z, v) => x + "_" + y + "_" + z + "_" + v
val someFn = udf(uniqueKey)
val newData = csv.withColumn("unique", someFn(csv.col("receipt_id"), csv.col("cash_register_id"), csv.col("sale_time"), csv.col("date")))
val countArticles = newData.groupBy("unique", "article_id").count()
var articles = countArticles.select("article_id").distinct()
val articleIds = articles.collect.map(x => x(0))