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 / jdbc101.java
Created April 12, 2020 07:58
sample jdbc connect
package com.labex;
import java.sql.*;
public class JdbcTest {
// JDBC driver name
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
//database url
static final String DB_URL = "jdbc:mysql://localhost/example";
@saswata-dutta
saswata-dutta / DatabaseModule.java
Created March 25, 2020 15:35 — forked from jwgmeligmeyling/DatabaseModule.java
Test Guice projects using the JPAPersistModule with Jukito
import javax.persistence.EntityManager;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.persist.PersistService;
import com.google.inject.persist.jpa.JpaPersistModule;
public class DatabaseModule extends AbstractModule {
@saswata-dutta
saswata-dutta / gist:c2c45638e84895b5cb189692b13b697f
Created March 24, 2020 09:20 — forked from digitaljhelms/gist:4287848
Git/GitHub branching standards & conventions

Branching

Quick Legend

Description, Instructions, Notes
Instance Branch
#!/bin/bash
#
# Cleans all target directories.
#
# Just `sbt clean` won't remove all downloaded and/or compiled classes and .jars, and this may
# result in compilation exceptions when moving between branches with different dependencies.
#
set -o nounset -o errexit
find . -name 'target' | grep '/target$' | awk '{print "rm -Rf " $1 "/*"}' | sh
scala> val PATTERN = """\s*SELECT\s+(.+?)\s+FROM\s+(.+?)(\s+WHERE\s+(.+?))?\s*""".r
PATTERN: scala.util.matching.Regex = \s*SELECT\s+(.+?)\s+FROM\s+(.+?)(\s+WHERE\s+(.+?))?\s*
scala> "SELECT a,b FROM t WHERE c=1,d=2" match {case PATTERN(f, t, _, c) => println(s"|$f|$t|$c|")}
|a,b|t|c=1,d=2|
scala> " SELECT a,b FROM t " match {case PATTERN(f, t, _, c) => println(s"|$f|$t|$c|")}
|a,b|t|null|
-- Functional parsing library from chapter 13 of Programming in Haskell,
-- Graham Hutton, Cambridge University Press, 2016.
module Parsing (module Parsing, module Control.Applicative) where
import Control.Applicative
import Data.Char
-- Basic definitions
object Main {
/*
input: data = [
[1487799425, 14, 1],
[1487799425, 4, 0],
[1487799425, 2, 0],
[1487800378, 10, 1],
[1487801478, 18, 0],
[1487801478, 18, 1],
[1487901013, 1, 0],
// given
def getFriends(id: Id): Set[Id] = ???
// implement suggestions for friends who have the most mutual friends with user
def suggestedFriends(id: Id, limit: Int): Set[Id] = {
require(limit > 0)
require(id != null)
val friends = getFriends(id)
val friendsOfFriends =
@saswata-dutta
saswata-dutta / streams-tutorial.md
Created December 30, 2019 13:15 — forked from djspiewak/streams-tutorial.md
Introduction to scalaz-stream

Introduction to scalaz-stream

Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.

The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca

@saswata-dutta
saswata-dutta / di-in-fp.md
Created December 20, 2019 19:01 — forked from gvolpe/di-in-fp.md
Dependency Injection in Functional Programming

Dependency Injection in Functional Programming

There exist several DI frameworks / libraries in the Scala ecosystem. But the more functional code you write the more you'll realize there's no need to use any of them.

A few of the most claimed benefits are the following:

  • Dependency Injection.
  • Life cycle management.
  • Dependency graph rewriting.