Embracing the Messiness in Search of Epic Solutions

Home

Welcome to my encyclopedia of shitty code!

  • Java: Builder for Immutable POJO

    PROBLEM Let’s assume we have an immutable Person object:- … and an immutable Car object:- To create the Person object, we need to write something like this:- If the POJO has a lot of properties, it becomes very difficult to keep track all the constructor argument positions. SOLUTION @mkarneim wrote a POJO Builder that creates… Read More…

  • IntelliJ IDEA 14.1: Better equals(), hashCode() and toString()

    PROBLEM Let’s assume we want to create the default equals(), hashCode() and toString() with the following bean:- Most IDEs, including older version of IntelliJ, have code generation features that would create something similar to this:- While it works, the generated code is usually crazy horrendous. SOLUTION With IntelliJ 14.x, it allows us to select templates… Read More…

  • Underscore.js: Introducing _.chain(…)

    PROBLEM Let’s assume we have the following JSON data:- What we want to do is to get all unique employees and ordered them by their names so that we get the following data:- SOLUTION 1: Less Elegant Underscore.js provides various functions that allow us to pull this off. While doable, the code is virtually not… Read More…

  • IntelliJ IDEA: Generating Immutable Classes and Fields

    PROBLEM By default, IntelliJ IDEA generates mutable classes and fields. One of the steps to achieve immutability is to make all classes and fields to be final. SOLUTION Making Fields Final Go to Preferences… -> Code Style -> Java -> Code Generation tab Under Final Modifier, check both Make generated local variables final and Make… Read More…

  • Better Preconditions: v0.1.0

    DEPENDENCY Introduction The goal of Better Preconditions is to provide a set of Java APIs that allows developers to create succinct, yet readable and testable preconditions. Why Write Preconditions? Let’s assume we have the following code:- Although this example is simple and trivial, every developer that looks at this code will interpret this API differently.… Read More…

  • Maven: Deploying Generated Site to GitHub

    INTRO GitHub provides an incredible feature that allows us to easily push Maven generated site to our project’s GitHub repository. Here’s how to do it… STEP 1: Define GitHub credential Go to ~/.m2/settings.xml and add your GitHub username and password:- STEP 2: Define GitHub’s site-maven-plugin GitHub provides its own site-maven-plugin that can be used to… Read More…

  • Guava: Testing equals(..) and hashcode(..)

    PROBLEM Let’s assume we want to test the following equals(..):- A correctly implemented equals(..) must be reflexive, symmetric, transitive, consistent and handles null comparison. In another word, you have to write test cases to pass at least these 5 rules. Anything less is pure bullshit. SOLUTION You can write these tests yourself… or you can… Read More…

  • Spring Security: Invalid CSRF Token ‘null’ was found on the request parameter ‘_csrf’ or header ‘X-CSRF-TOKEN’

    PROBLEM With Spring Security 4.x, the CSRF protection is enabled by default. You may disable it, but to be more aligned with OWASP and the industry security standard, it’s best to leave this setting the way it is. Learn more about CSRF attack… To prevent this attack, Spring Security 4.x requires you to attach a… Read More…

  • Jackson 2.x: JSON Serialization Difference for Map.Entry between 2.4.x vs 2.5.x

    It appears Jackson 2.4.5 and 2.5.1 behave a little differently when handling Map.Entry. Let’s assume we have the following bean:- We have a simple Spring MVC rest controller that creates this bean and returns the JSON data back to the client:- Jackson 2.4.5 generates the following JSON:- Jackson 2.5.1 generates the following JSON:- Read More…

About Author

This author has 20+ years of experience in software engineering and cloud engineering. In an industry where knowledge becomes obsolete in the next three months, he learns anything that crosses his path indiscriminately. He floats from one technology to another like a moth and stings the problem sets like a mosquito. This author codes Java while drinking Espresso and writes Spock specifications while listening to Groovy beats. He masters Google Cloud Platform just like how he masters the art of predicting the movement of dark clouds over his backyard, where 60% of the time, he is right every time.

This author suffers from the Dunning-Kruger effect, where he overestimates his competence and underestimates his ignorance. Technology buzzwords never faze him, for he does not know enough to be afraid of in the first place. GCP, GCS, GCR, GKE, GWT… everything sounds the same to him. He never fears acronyms, synonyms, or antonyms, for he has ChatGPT in his back pocket. This author is a jack of all trades but a master of none. He writes like he knows all the answers, yet he googles for better solutions from elsewhere. He fakes it until he makes it; if he doesn’t, that’s okay because he has the attention span of a squirrel. The blog posts are his buried walnuts, in case he needs them one day.

In conclusion, this author is full of something. He apologizes in advance if you are trying to solve your company’s real problems with his shitty solutions. There, he has successfully written paragraphs of nonsense because every professional blogging website needs a section about the author, with a too-cool-to-smile portrait staring sideways into the abyss.