Skip to content

Instantly share code, notes, and snippets.

View saswata-dutta's full-sized avatar
💭
I may be slow to respond.

Saswata Dutta saswata-dutta

💭
I may be slow to respond.
View GitHub Profile
@saswata-dutta
saswata-dutta / CacheConfig.java
Created September 17, 2020 10:30 — forked from anataliocs/CacheConfig.java
Guava cache with spring boot and clear cache method
import com.google.common.cache.CacheBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.guava.GuavaCache;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.interceptor.KeyGenerator;
DatabaseMetaData databaseMetaData = connection.getMetaData();
int majorVersion = databaseMetaData.getDatabaseMajorVersion();
int minorVersion = databaseMetaData.getDatabaseMinorVersion();
String productName = databaseMetaData.getDatabaseProductName();
String productVersion = databaseMetaData.getDatabaseProductVersion();
int driverMajorVersion = databaseMetaData.getDriverMajorVersion();
int driverMinorVersion = databaseMetaData.getDriverMinorVersion();
@saswata-dutta
saswata-dutta / DataFrameTesting.scala
Created September 8, 2020 11:45 — forked from andfanilo/DataFrameTesting.scala
An implementation of DataFrame comparison functions from spark-testing-base's DataFrameSuiteBase trait in specs2
package utils
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.{DataFrame, Row}
import org.specs2.matcher.{Expectable, Matcher}
import org.specs2.mutable.Specification
/**
* Utility class to compare DataFrames and Rows inside unit tests
path="s3://path-to-file/"
sc = spark.sparkContext
URI = sc._gateway.jvm.java.net.URI
Path = sc._gateway.jvm.org.apache.hadoop.fs.Path
FileSystem = sc._gateway.jvm.org.apache.hadoop.fs.FileSystem
Configuration = sc._gateway.jvm.org.apache.hadoop.conf.Configuration
fs = FileSystem.get(URI(path), Configuration())
files = fs.listStatus(Path(path))
@saswata-dutta
saswata-dutta / gist:5ff1f32a8be41029eac47326f5bca5d5
Created August 24, 2020 12:33 — forked from MHawksworth/gist:2700832
Getting DBUnit to play nice with Hibernate hbm2ddl.auto database changes by extending DBTestCase
package com.ossAccounts.ac.server;
import java.io.FileInputStream;
import org.dbunit.DBTestCase;
import org.dbunit.IDatabaseTester;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.dbunit.ext.mssql.InsertIdentityOperation;
import org.dbunit.operation.DatabaseOperation;
import org.hibernate.Session;
import org.apache.spark.sql.types._
val subjectSchema = StructType(Array(
StructField("correspondence_id", StringType, false),
StructField("subject", StringType, false),
StructField("thread_subject", StringType, false)
))
val internal_subjects = spark.read.schema(subjectSchema).csv("internal")
val external_subjects = spark.read.schema(subjectSchema).csv("external")
import re
import sys
def getWords(subject):
return re.sub(r"\W", " ", subject).split()
def isDigit(ch):
return ch.isdigit()
def isIdChar(ch):
@saswata-dutta
saswata-dutta / CallerBlocksPolicy.java
Created August 4, 2020 10:10 — forked from jexp/CallerBlocksPolicy.java
CallerBlocksPolicy as alternative to CallerRunsPolicy if the calling thread and the pool threads(tasks) share a similar thread local which would then be messed up.
public static ExecutorService createDefaultPool() {
int threads = Runtime.getRuntime().availableProcessors()*2;
int queueSize = threads * 25;
return new ThreadPoolExecutor(threads / 2, threads, 30L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(queueSize),
new CallerBlocksPolicy());
// new ThreadPoolExecutor.CallerRunsPolicy());
}
static class CallerBlocksPolicy implements RejectedExecutionHandler {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
@saswata-dutta
saswata-dutta / gremlin-cheat-sheet.md
Created August 1, 2020 16:21 — forked from jeremysears/gremlin-cheat-sheet.md
Gremlin Cheat Sheet in Groovy

Gremlin Cheat Sheet in Groovy

Gremin traversal examples taken from the excellent DS330: DataStax Enterprise Graph course.

Creating Vertices and Vertex Properties

Add a Vertex

Vertex u = graph.addVertex("user");
       u.property("userId","u2016");
 u.property("age",36);
original on :https://www.webslesson.info/2018/09/insert-tree-view-node-using-php-ajax.html
http://www.techsapphire.in/index/grandparent_parent_and_child_hierarchy_sql_server_or_bread_crumb/0-170
https://www.youtube.com/watch?v=RswtHsz4v-0
https://www.ruvictor.com/article/php-recursive-functions
<?php
//fetch.php
include('database_connection.php');