How to load packages in R automatically?

Put library(foo) in your .Rprofile file or set R_DEFAULT_PACKAGES: see ?Rprofile … In particular (because ?Rprofile is long and potentially intimidating): If you want a different set of packages than the default ones when you start, insert a call to ‘options’ in the ‘.Rprofile’ or ‘Rprofile.site’ file. For example, ‘options(defaultPackages = character())’ will attach no … Read more

open resource with relative path in Java

I had problems with using the getClass().getResource(“filename.txt”) method. Upon reading the Java docs instructions, if your resource is not in the same package as the class you are trying to access the resource from, then you have to give it relative path starting with “https://stackoverflow.com/”. The recommended strategy is to put your resource files under … Read more

How to create a JavaScript callback for knowing when an image is loaded?

.complete + callback This is a standards compliant method without extra dependencies, and waits no longer than necessary: var img = document.querySelector(‘img’) function loaded() { alert(‘loaded’) } if (img.complete) { loaded() } else { img.addEventListener(‘load’, loaded) img.addEventListener(‘error’, function() { alert(‘error’) }) } Source: http://www.html5rocks.com/en/tutorials/es6/promises/

How and when should I load the model from database for h:dataTable

Do it in bean’s @PostConstruct method. @ManagedBean @RequestScoped public class Bean { private List<Item> items; @EJB private ItemService itemService; @PostConstruct public void init() { items = itemService.list(); } public List<Item> getItems() { return items; } } And let the value reference the property (not method!). <h:dataTable value=”#{bean.items}” var=”item”> In the @PostConstruct you have the advantage … Read more