Skip to content

Instantly share code, notes, and snippets.

@noorulhaq
noorulhaq / BestQuotationSearchService.java
Last active February 10, 2016 13:18
Best loan quotation problem solution using spring integration scatter-gather EIP pattern.
public interface BestQuotationSearchService {
public Double findBestQuotation(Double loanAmount);
}
@noorulhaq
noorulhaq / banking.scala
Last active September 29, 2016 08:27
Functional domain driven design
package fr.ddd.ch3.banking
import scalaz._
import scala.util.Try
import java.util.Date
import scala.util.Failure
import scala.util.Success
import org.joda.time.DateTime._
import scala.collection.mutable.Map
@noorulhaq
noorulhaq / kleisli_monad_transformer_reasoning.scala
Created January 21, 2017 13:09
This Gist demostrate a situation where OptionT monad transformer is used to avoid extra mapping to extract account from stacked Future[Option] monands within Kleisli
trait AccountService {
type Valid[A] = OptionT[Future, A]
type AccountOperation[A] = Kleisli[Valid, AccountRepository, A]
def debit(no: String, amount: Amount): AccountOperation[Account] = ???
def credit(no: String, amount: Amount): AccountOperation[Account] = ???
def transfer(from: String, to: String, amount: Amount) : AccountOperation[(Account,Account)] = for {
debitAcc <- debit(from, amount)
creditAcc <- credit(to, amount)
@noorulhaq
noorulhaq / kleisli_reasoning.scala
Last active January 21, 2017 13:10
This Gist demostrate a situation where Kleisli/ReaderT monad transformer is used to avoid extra mapping to extract account from Future monad.
trait AccountService {
def debit(no: String, amount: Amount): Kleisli[Future,AccountRepository, Account] = ???
def credit(no: String, amount: Amount): ReaderT[Future,AccountRepository, Account] = ???
def transfer(from: String, to: String, amount: Amount) : ReaderT[Future,AccountRepository, (Account,Account)] = for {
debitAcc <- debit(from, amount)
creditAcc <- credit(to, amount)
} yield (debitAcc, creditAcc) // If you do not use ReaderT/Kleisli here then you need extra mapping to extract accounts from Future
}
object AccountService extends AccountService
@noorulhaq
noorulhaq / GitShowCommad.java
Created March 27, 2017 12:09
This gist demostrate how you can implement "git show --name-staus <commit_id>" command using JGIT.
package crossover;
import org.eclipse.jgit.api.DiffCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.diff.*;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
@noorulhaq
noorulhaq / GitLogCommand.java
Last active March 27, 2017 13:19
Git commit log gist, that demostrate how you can list commits from git repsoitory.
package crossover;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import java.io.File;
import java.util.Date;
/**
@noorulhaq
noorulhaq / GitFileDiffCommand.java
Created March 27, 2017 16:09
JGIT emulation "git diff <rev1>..<rev2> -- path/to/file.txt" command.
package crossover;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.diff.*;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.filter.PathFilter;
@noorulhaq
noorulhaq / GitDiffCommand.java
Last active March 27, 2017 16:10
JGIT emulation of "git diff --name-status <rev1>..<rev2>" command.
package crossover;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.diff.*;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import java.util.List;
@noorulhaq
noorulhaq / VCService.java
Last active March 27, 2017 19:42
Unified VCS API for different version control systems.
package crossover;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Future;
/**
* Created by Noor on 3/26/17.
@noorulhaq
noorulhaq / SVNDownloadFile.java
Created March 27, 2017 19:58
This code snippet demonstrates how to download file using SVNKit.
package crossover;
import org.tmatesoft.svn.core.SVNProperties;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
import java.io.ByteArrayOutputStream;