Embracing the Messiness in Search of Epic Solutions

Home

Welcome to my encyclopedia of shitty code!

  • Java: Programmatically Compile and Unit Test Generated Groovy Source Code

    My previous post shows how you can programmatically compile and unit test the generated Java source code. In this example, we will programmatically compile and unit test the generated Groovy source code. Let’s assume we have the following service class that generates Groovy source code as one big String:- To unit test the generated Groovy… Read More…

  • Java: Programmatically Compile and Unit Test Generated Java Source Code

    In one of the projects I’m currently working on, I have to write a parser to translate a scripting language into Java code. This tutorial shows how you can unit test the generated Java code. Let’s assume we have JavaCodeGeneratorService that looks something like this:- This service class generates Java source code as one big… Read More…

  • Java: Properly Indenting XML String

    PROBLEM Let’s assume we want to perform a pretty print on the following XML string:- We have the following code to create a formatted XML string:- However, the generated output looks like just the original XML string:- Why? SOLUTION You may think the above code is wrong, but it is not. Based on the DOM… Read More…

  • Guava: Elegant Caching Mechanisms

    There are many different ways to implement a caching mechanism. Google’s Guava provides very simple and elegant solutions to do so. OPTION 1: Caching using Supplier If you want to cache just one thing, Supplier should satisfy that requirement. In the above example, we cache all employees for a day. OPTION 2: Caching using LoadingCache… Read More…

  • MockMvc : Circular view path [view]: would dispatch back to the current handler URL [/view] again

    PROBLEM Let’s assume we want to test this controller:- Here’s the test file:- When executing this test, we get the following error:- SOLUTION The reason this is happening is because the uri “/help” matches the returned view name “help” and we didn’t set a ViewResolver when constructing the standalone MockMvc. Since MockMvcBuilders.standaloneSetup(…) doesn’t load Spring… Read More…

  • MockMvc + Mockito = Epic Tests

    Spring Framework 3.2 introduces a very elegant way to test Spring MVC controller using MockMvc. Based on the documentation, there are two ways to configure MockMvc:- The first approach will automatically load the Spring configuration and inject WebApplicationContext into the test. The second approach does not load the Spring configuration. While both options work, my… Read More…

  • Guava: Elegant Collection Ordering

    PROBLEM Java provides a built-in API to sort a list, but it is flat out ugly and prone to error especially when dealing with Comparator. Here’s an example:- Number of puppies killed = 3 … from the if-else statement. SOLUTION A better way to do this is to use Ordering from Guava:- </request,> In this… Read More…

  • Developing against H2 Database: Lesson Learned

    While my production database is MS SQL Server, I have been using H2 database for rapid local development. I wrote my DDL scripts as “Transact-SQL” as possible so that I don’t need to maintain multiple DDL scripts for each database. So far, it has been working out great. My web development runs against H2’s file-based… Read More…

  • HTML: Creating a Default Placeholder for Image that Fails to Load

    PROBLEM Let’s assume our web application relies on an external system to provide the image link, for example: employee photo link of a company. If the image link is invalid, we will get the ugly looking “x” on certain browsers. SOLUTION To fix this, we can load an image placeholder from our own web application… 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.