Skip to content

Instantly share code, notes, and snippets.

View npathai's full-sized avatar

Narendra Pathai npathai

  • Ahmedabad, India
View GitHub Profile
@npathai
npathai / Domain Driven Design Notes.md
Last active September 15, 2020 04:10
Notes for capturing the understanding from the books on Domain Driven Design

Ubiqutous language

In DDD it really important that everyone business people and developers share a model. A model is shared understanding of the system. It helps in forming a common language between all the stakeholders. This makes sure that the code design doesn't drift from the model and it reflects the domain.

Model

The model has to be tightly associated with the domain it comes from. Designing without a model can lead to software which is not true to the domain it serves, and may not have the expected behavior.

One of the first things we are taught about modeling is to read the business specifications and look for nouns and verbs. The nouns are converted to classes, while the verbs become methods. This is a simplification, and will lead to a shallow model. All models are lacking depth in the beginning, but we should refactor the model toward deeper and deeper insight.

@npathai
npathai / understanding-zookeeper.md
Last active June 1, 2020 03:57
Understanding Zookeeper

Why Zookeeper

  • Coordination services are notoriously hard to get right.
  • Race conditions and deadlock.

The motivation behind ZooKeeper is to relieve distributed applications the responsibility of implementing coordination services from scratch.

Zookeeper

  • Distributed co-ordination service
  • eases the development of distributed systems
@npathai
npathai / chapter6.md
Last active May 30, 2020 03:09
Working Effectively With Legacy Code Book Notes

I don't have much time and I have to change it

Sprout Method

If a change is too difficult to make in existing method, then create a new method which performs additional work and call it from existing method. Unit test the new method, even if it requires to make it static and pass all dependencies in it.

Sprout Class

Similar to sprout method, but if creating instance of class is too difficult to do in limited time, or maybe it will require separating a lot of dependencies. Create another class to hold changes and use from original difficult to test class. Unit test sprouted class properly. This may seem like making the code worse, and sometimes is, but many times it helps in figuring out commanality between sprouted class and some new class in future and improves chances of carving out interfaces or resusable classes.

Wrap method

If new functionality is cleanly separable, then rather than adding more stuff to existing method, we can make original method as private and rename it to give apt

@npathai
npathai / commands.sh
Last active November 14, 2018 08:01
Import Certificate Chain (Root, Intermediate and Client/Server) and Private key in Java KeyStore (JKS)
keytool -importkeystore -srckeystore middleware_keystore_org -destkeystore private_key.p12 -deststoretype PKCS12
openssl pkcs12 -in private_key.p12 -out private_key.pem -nodes
openssl pkcs12 -export -inkey private_key.pem -in Meydan1-certnew_941.cer -name test -out test.p12
keytool -importkeystore -srckeystore test.p12 -srcstoretype pkcs12 -destkeystore middleware_keystore_try3.jks
keytool -list -v -keystore middleware_keystore_try3.jks
@npathai
npathai / ClassUnderTest.java
Last active August 29, 2015 14:10
Unit testing a class dependent on System clock
/*
* This is a mockup of JLine2 library structure. I am working on a feature that provides timestamp
* and wanted to test it and hence this gist. The question that I asking via this gist is that how
* should I test MemoryHistory?
*/
/**
* Represents the history of commands a user has given to a system via any interface such as
* Command Line
@npathai
npathai / Currying.scala
Created August 10, 2014 16:06
Practicing the currying lecture of Functional Programming in scala course on coursera.
object Currying {
def sum(f: Int => Int) : (Int, Int) => Int = {
def sumF(a: Int, b: Int) : Int = {
if(a > b) 0
else f(a) + sumF(a + 1, b)
}
sumF
}
public class MapVsFlatMap {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(1, 2, 3);
//Stream<X> --map (square)--> Stream<X>
list.stream()
.map(it -> it * 2)
.forEach(it -> System.out.println(it));
// Stream<X> --map--> Stream<Optional<X>> --filter--> Stream<Optional<X>> --each--> Print
@npathai
npathai / Optional.java
Created August 9, 2014 13:22
Using Optional in Java8 in a functional way using the flatMap operation to give it a monadic touch!
public abstract class Optional<T> {
public static <T> Optional<T> of(T value) {
return value != null ? new Present<T>(value) : Absent.<T>instance();
}
public <V> Optional<V> flatMap(Function<T, Optional<V>> function) {
return isPresent() ? function.apply(get()) : Absent.<V>instance();
}