Angular 4/5 override class in body tag (Shadow Piercing combinators approach)

In angular component CSS styles are encapsulated into the component's view and don't affect the rest of the application; usually this is the behaviour that you want however sometimes it's useful to be able to affect tags outside the component, for example the body tag This can be achieved in a few different ways, like for example tweaking view encapsulation parameters In this post I will show you a CSS approach to this using The Shadow Piercing combinators, starting in Angular 4.3.0 you can use the custom shadow piercing combinator ::ng-deep to achieve this For example if we had a component named "CustomComponent" we could have a set of files similar to : custom.component.tscustom.component.csscustom.component.htmlIn order for us to shadow and override the main body tag would be to put the following in the custom.component.css : ::ng-deep body { min-height: 75rem; padding-top: 4.5rem; }

BigDecimal rounding to the nearest 5 cents with Java's BigDecimal

Recently I hat to implement a function that would round to the nearest 5 cents and after googling around a bit I found bits and pieces here and there but none just worked for me, so below you can find a function that should do just that /** * Rounds a decimal number to the nearest 5 cents using the following rules * * Rounding rules : * - 0.1299 = 0.10 * - 0.1300 = 0.15 * - 0.1799 = 0.15 * - 0.1800 = 0.20 * * @param value the BigDecimal value to round * @return the rounded value for the big decimal with a scale of 2 */ public static BigDecimal roundToNearest5Cents(final BigDecimal value) { return value.setScale(2, RoundingMode.FLOOR).multiply(new BigDecimal(20)).add(new BigDecimal("0.5")) .setScale(0, RoundingMode.FLOOR).divide(new BigDecimal(20)).setScale(2, RoundingMode.FLOOR); }

Spring application events lifecycle and earlyApplicationEvents

Not long ago I learned the hard way the way spring handles earlyApplication events when we started having problems in one of our projectsBasically we were using a MongoDB database as a cache layer, so when the application would startup we would pull most of the data from our RDBMS do some processing and denormalisation then fill the MongoDB with data The application had been running mostly fine for some time but we saw some memory issues as the data kept growing within the application and I suspected a Memory leak issue So I decided to do a java heap dump to try to see what was happening, and I found the culprit; way down the piping of spring the class had a private property earlyApplicationEvents that was keeping references to more than 3 million instances of BasicDBObject that were not Garbage collected even though they were no longer in scope and were already written to the databaseAfter scouring the internet a fellow …

Working with stateless session in hibernate and jpa

When doing heavy read-only operations in with the database it can be a good idea to take advantage of using Hibernate's Stateless SessionAs it name indicates this session does not keep state of the entities that it retrieves from the database and so it bypasses the L1 and L2 cacheThis can have significant performance impact on heavy DBA read operations (since the state of the entities is not bet tracked) @Component @Scope("prototype") public class SomeJpaService { public static final int SCROLL_STEP = 1000; @PersistenceContext private EntityManager entityManager; public void doInStatelessSession(){"ABOUT to perform Heavy read operation on DB"); StatelessSession statelessSession = entityManager.unwrap(Session.class).getSessionFactory().openStatelessSession(); try (ScrollableResults r = statelessSession .createQuery("SELECT c FROM Order c") .setReadOnly(true)…

Serving angular2 content from Spring Boot application

Recently I had to ship an Angular2/Angular4 application within a Spring boot WAR packaged application and I was having some issues when dealing with the the urls in the angular routes, since it goes through the DispatcherServlet I was getting 404 all over the place There are a few ways to handle this, below is my preferred solution : @Controller public class Angular2ViewController { @RequestMapping({"/books", "/login", "/admin", "/logout", "/configure"}) public String index() { return "forward:/index.html"; } } There you go, as easy as thatThe inconvenience about this solution is that you have to maintain a set of urls in your controller also

Editable combobox in HTML5 and bootstrap

Creating an editable combobox in HTML5Recently while reading the HTML5 specification I found out a new cool feature called datalist element
Which basically allows you to create an editable select form element by providing a list of possible values to an input whilst also allowing for new values to be provided (think of it as a basic auto-complete field)Below is an example of how to implement this :Select a color : Note that this is also compatible with Bootstrap 4 and 3

Custom converter for Mongodb and Spring Data for BigDecimal type

Recently I found that MongoDB does not support java's java.math.BigDecimal as you can read in the official spring data mongodb documentation As it turns out java.math.BigDecimal will be converted to java.lang.String when saved to the database and parsed back to BigDecimal which in most cases I guess it's alrightHowever as I found out things get broken when trying to perform range queries on this field such as : $gte, $lte you will get inconsistent results since MongoDB sees this as a StringLuckily this can be easily fixed by creating 2 custom converters (one for each side), below is how I've done it :1. Define custom converters by implementing the appropriate interface import org.springframework.core.convert.converter.Converter; import java.math.BigDecimal; public class BigDecimalToDoubleConverter implements Converter<BigDecimal, Double&gt { @Override public Double convert(BigDecimal source) { return source.doubleValue(); } } import org.spr…