Skip to content

Protected: SVM Notes

October 22, 2018

This content is password protected. To view it please enter your password below:

Jacoco offline instrumentation in Gradle

August 17, 2018


apply plugin: "java"
apply plugin: "jacoco"

configurations {

jacocoAnt group: 'org.jacoco', name: 'org.jacoco.ant', version: '0.8.1'
jacocoAgent group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.8.1'

test {
jacoco {
append = "false"
destinationFile = file("$buildDir/reports/jacoco/jacoco-sonar/jacoco-coverage.exec")


jacoco {
toolVersion = "0.8.1"
reportsDir = file("$buildDir/customJacocoReportDir")


jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")

task instrument(dependsOn: ['classes']) {
ext.outputDir = buildDir.path + '/reports/classes-instrumented'
doLast {
ant.taskdef(name: 'instrument',
classname: 'org.jacoco.ant.InstrumentTask',
classpath: configurations.jacocoAnt.asPath)
ant.instrument(destdir: outputDir) {
fileset(dir: sourceSets.main.output.classesDir)

gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(instrument)) {
tasks.withType(Test) {
doFirst {
classpath = files(instrument.outputDir) + classpath + configurations.jacocoRuntime

task report(dependsOn: ['instrument', 'test']) {
doLast {
ant.taskdef(name: 'report',
classname: 'org.jacoco.ant.ReportTask',
classpath: configurations.jacocoAnt.asPath) {
executiondata {
ant.file(file: buildDir.path + '/reports/jacoco/jacoco-sonar/jacoco-coverage.exec')
structure(name: 'Example') {
classfiles {
fileset(dir: sourceSets.main.output.classesDir)
sourcefiles {
fileset(dir: 'src/main/java')
html(destdir: buildDir.path + '/reports/jacoco')


October 4, 2016

So unless you put your heart, soul and mind and focus in only one and only one thing which is learning it is difficult to speak the ease with depth of an architect.

How can one develop this focus?  So instead you are asking how does one develop ekagrita – one chitta – one attention for going deep – developing DEPTH.

Depth requires focus, focus requires discarding, and doing only one thing in life. To learn in the right direction.

Guava Mongodb Caching in Grails

July 3, 2016

Basic cache expiration

Expiration in Guava happens when few specific methods (like get/size etc ) are called. It does happen with a timer.So if you set it to 5 mins, expiry may happen few seconds later , when next get comes for same key.

Here is what happens.
Thread A: Get the key. Key has expired, returns false, get lock on cachekey, store data (Data is now doubled as delete on eviction has not yet run)
Thread B: Eviction has taken place, all data gets deleted, data is now 0 in cache .

We used Locks for synchronized access. Synchronize guarantees one thread accesses 1 op at a time, but what it does not guarantee is the Sequence of our operations.
So we want eviction to complete before storage happens, or we want eviction to not delete the newly stored entities. But we only have cacheKey as identifier so how do we differentiate !.

I even checked the mongodb eviction policy but that is also not immediate – it runs every 60 seconds/ depending on load etc. and if immediate eviction with continuous polling or timer can be a costly operation both at the db end as well in the guava cache library, the only option out that is quick and easy is to keep timestamp.

That can only happen when timestamp is maintained in the entities. I remembered that timestamps can be created in domain objects.
But keeping timestamp in all the DO’s is meaningless because we don’t want to know time DO is created but the time cache is created, so what we really want is to keep timestamp in the cacheSignature.

So here could be the scenarios:
· Timestamp is created when the cache is inserted in DB & entry is put in map , so the stored DO’s will have timestamp field but all DO’s will have the same time stamp value indicative of when cache was created. This timestamp is inserted in cacheSignature prior to cacheMap entry put call.
· When get happens, those entries which are older than expiry time than current will not be fetched.
· When delete happens , those entries which are expired as per current timestamp get deleted.

At the time of get/and store/ and delete we use this timestamp feature to fetch selective data.
The other advantage of this approach over writing your own eviction code based on the timestamp is that the getter code will not need to wait for delete Operation to complete before returning results to user.


July 1, 2016

ES problem was handling of relationships:

1. handle it at app level – hit two different indices. with ID’s
2. Nested children – problem is re-indexing of parent every time children are updated, mapping has to be of nested type. costly if too many children
3. Parent Child – can do : parent indexed separately and children indexed separately. link is mantained between them.
children can be queried separately. need not tranverse thru parent

Char Filter-> Tokenizer -> Token Filter

term/ term(s) : not analyzed

field{ gte, lte }

The term query does not analyze the search term, the match query uses the same analyzer for search as was used to index the field

query: filtered : [query, filter ]
query : match_phrase or query :match : field { query: value, type:match_phrase}
query: must : match : field
query : bool or query->filtered->filter:bool
query:fitleredXXXbool does not work

filtered filter OR / AND / EXISTS/

match, latest

must is keep score count, should does not add to score count
term does not use analyzer, must uses the default analyzer,

match_phrase query is the one you should reach for when you want to find words that are near each other:

    "query_string" : {
        "fields" : ["city.*","name","age"],
        "query" : "this AND that OR thus",
        "use_dis_max" : true

query -> match_phrase


multi field mapping with two mappings – one is for existing token other is not analyzed

"title": {
    "type": "multi_field",
    "fields": {
        "title": { "type": "string" },
        "raw":   { "type": "string", "index": "not_analyzed" }


"title": {
    "type": "string",
    "fields": {
        "raw":   { "type": "string", "index": "not_analyzed" }

Kyle’s JS – Points

March 3, 2016

If strict mode is in effect, the global object is not eligible for the default binding, so the this is instead set to undefined:

this Binding Rules 4: default (global) , implicit (fn call) , explicit (bind, call apply) , new binding.

Sequence is: 1. new fn call, 3. obj.fn call 4. default

safe object:

// our   empty object
var ø = Object.create( null );

Concept of soft binding so that global object does not get used ever !! means foo is called in context of obj2

if you do bar = and then you call bar() – bar is called without context – global or undefined in case of strict

Explicit binding is when you use call or apply and pass the first parameter – as the object context.wrap a function with a hard binding

var bb = function() {; }

bb(); // in case of global or set timeout, will always use the right context for calling object.

By calling foo(..) with new in front of it, we’ve constructed a new object and set that new object as the this for the call of foo(..). So new is the final way that a function call’s this can be bound. We’ll call this new binding.

bind(..) returns a new function that is hardcoded to call the original function with the this context set as you specified. obj2 ); // 3 obj1 ); // 2

So, explicit binding takes precedence over implicit binding, which means you should ask first if explicit binding applies before checking for implicit binding.



HTTPS communication jdk version

March 2, 2016

Defaults of ssl protocol differ in each jdk .

Add the property -Dhttps.protocols=TLSv1 in tomcat shell script to ensure same version used in both.  Preferably keyalg=RSA and keysize=2048

The following chart depicts the protocols and algorithms supported in each JDK version:

(March 2014 to present)
(July 2011 to present)
(2006 to end of public updates 2013)
TLS Protocols TLSv1.2 (default)
TLSv1 (default)
TLS v1.1 (JDK 6 update 111 and above)
TLSv1 (default)
JSSE Ciphers: Ciphers in JDK 8 Ciphers in JDK 7 Ciphers in JDK 6
Java Cryptography Extension, Unlimited Strength (explained later) JCE for JDK 8 JCE for JDK 7 JCE for JDK 6