My learning diary

Abstract classes and AOP

I wanted to avoid writing boilerplate code for CRUD in Spring Boot. But I failed - I could not make my child aspect get along with my child controller. Before adopting AOP, I had an abstract controller which the child controller inherited. CRUD worked well and I no longer needed to repeat the code for simple CRUD anymore. I was happy. // MyAbstractController public abstract class MyAbstractController<T extends UniversalModel> { private final .

Continue reading "Abstract classes and AOP"

Sticky

I found myself entangled in CSS. I needed app-header to stick to the top at all times. I also needed template-header to be right beneath app-header at all times. Lastly, embedded-content should begin immediately after template-header and should not be sticky. Here’s how the page organisation might look like: <div class="app"> <div class="app-header"> <!-- Content --> </div> <div class="app-content"> <div class="template-container"> <div class="template-header"> <!-- Content --> </div> <div class="embedded-content"> <!-- Content --> </div> </div> </div> </div> The simplest approach is to place app-header and template-header inside a single div.

Continue reading "Sticky"

Iterator to Stream

With Google Guava, you can transform an Iterator into a Stream with Streams.stream(...). But that API is only available from Guava 21. If you don’t want to use Guava or if your Guava version is below 21, you need an additional step to convert your Iterator to a Stream: Stream<String> stream = StreamSupport.stream( Spliterators.spliteratorUnknownSize( iterator, Spliterator.ORDERED ), false ); Reference: mkyong.

Continue reading "Iterator to Stream"

reCaptcha on-error

Polling wasn’t effective because: Hot reloading did not happen because of some heap limit error. I called the wrong function to check if the reCaptcha errored. To deal with the heap limit, my buddy suggested updating the docker-dev script in package.json to: { "scripts": { "docker-dev": "export NODE_OPTIONS=\"--max-old-space-size=4096\" && ..." } } As for checking if the reCaptcha errored, neither on-expire nor captchaService.isValid worked. A possible explanation for the former would be that the reCaptcha didn’t expire.

Continue reading "reCaptcha on-error"

pip uninstall All

I found a one-liner which can uninstall all pip packages: pip3 freeze | grep -v "^-e" | xargs sudo pip3 uninstall -y I used to do the following: pip3 freeze > reqs.txt sudo pip3 uninstall -r reqs.txt I didn’t realise I could do pip uninstall -r reqs.txt -y and get rid of those confirmation questions. And I’m pretty sure I messed up the actual requirements file at least once when adopting this approach.

Continue reading "pip uninstall All"