Skip to content

Instantly share code, notes, and snippets.

View skhatri's full-sized avatar

Suresh Khatri skhatri

  • Sydney, Australia
View GitHub Profile
@skhatri
skhatri / ListenableFutureAdapter.java
Created November 17, 2016 00:28
Converts from ListenableFuture to CompletableFuture
public class ListenableFutureAdapter<T> {
private final ListenableFuture<T> listenableFuture;
private final CompletableFuture<T> completableFuture;
public ListenableFutureAdapter(ListenableFuture<T> listenableFuture) {
this.listenableFuture = listenableFuture;
this.completableFuture = new CompletableFuture<T>() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
@skhatri
skhatri / ca.sh
Created May 20, 2023 03:37
generate signed cert by self-signed ca
#create CA cert and self sign
if [[ ! -d ca ]];
then
mkdir ca
openssl genrsa -out ca/ca.key 2048
openssl req -new -x509 -key ca/ca.key -out ca/ca.crt -subj "/C=AU/ST=NSW/L=Sydney/O=Software Company/OU=IT/CN=ca"
fi;
cert=${1:-localhost}
@skhatri
skhatri / initdependencies.gradle
Created March 13, 2023 02:01
Init Extra Gradle Tasks
def getDependencyList(org.gradle.api.Project proj, String configName) {
def dep = []
def dd = new HashSet<String>()
proj.configurations.all { cf ->
if (cf.canBeResolved && cf.name == configName) {
cf.incoming.each { p ->
p.dependencies.each { dt ->
dd.add("$dt.group:$dt.name:$dt.version".toString())
dep << [group: dt.group, name: dt.name, version: dt.version, transitive: false]
}
@skhatri
skhatri / PokemonSolr.cql
Last active February 1, 2023 23:18
Pokemon Solr with CQL
create keyspace pokedex with replication = {
'class': 'NetworkTopologyStrategy',
'dc1': 1
};
drop table if exists pokedex.pokemons;
create table pokedex.pokemons(
name text,
primary_type text,
@skhatri
skhatri / fluentd-elasticsearch-logging-timestmap.md
Last active December 17, 2022 11:34
FluentD to Elasticsearch Index with Custom Timestamp

This is an example of forwarding logs to elasticsearch using fluentd. In the process, it does use a custom time key.

The setup

Run Elasticsearch and FluentD locally

#run elasticsearch
docker run -e discovery.type=single-node -e xpack.security.enabled=false -p 9200:9200 -d elasticsearch:7.2.0
#install fluentd
@skhatri
skhatri / s3.js
Last active October 31, 2022 16:26
NodeJS AWS S3 list/clear/delete buckets.
module.exports = {
deleteObject: function (client, deleteParams) {
client.deleteObject(deleteParams, function (err, data) {
if (err) {
console.log("delete err " + deleteParams.Key);
} else {
console.log("deleted " + deleteParams.Key);
}
});
},
@skhatri
skhatri / tasks.gradle
Created October 16, 2022 02:14
gradle dependency printer
gradle.taskGraph.whenReady { tg ->
configurations.all { cf ->
if (cf.canBeResolved && cf.name == "runtimeClasspath") {
cf.incoming.each { p ->
println(p.name)
//resolved artifact dependency
p.artifacts.each { at ->
println(at.id.componentIdentifier)
}
//direct dependency
@skhatri
skhatri / WordCount.md
Created September 27, 2022 02:59
WordCount Apache Spark

With RDD

    val sc = new SparkContext(new SparkConf()
                                .setAppName("word-count-rdd").setMaster("local[1]")
                                .set("spark.driver.ip", "127.0.0.1")
            )

    sc.textFile(path).flatMap(line => line.toLowerCase().split(" "))
    .map(w => (w, 1))
    .reduceByKey((v1, v2) => v1 + v2)
@skhatri
skhatri / quality.gradle
Created February 24, 2012 00:45
Gradle Checkstyle HTML Reporting
apply plugin: 'checkstyle'
checkstyleMain {
ignoreFailures = false
reports {
include ( '**/*.java')
xml {
destination "${rootProject.buildDir}/reports/checkstyle/main.xml"
}
}
@skhatri
skhatri / value_of_pi.go
Created August 7, 2022 11:24
value of pi
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())