This Week I Learnt: week 37

Java: convert LocalDate to string LocalDate today = LocalDate.now(); System.out.println(DateTimeFormatter.ofPattern("dd-MM-yyyy"); // Outputs "12-09-2019" Source: https://howtodoinjava.com/java/date-time/localdate-format-example/ Java: Spring Boot integration testing and rolling back the changes After some fiddling with Spring Boot integration testing this week, I came across a scenario where some of my tests would fail. They only failed when running all tests in one go; running the tests isolated did work. Apparently, the test data in your H2 database is not cleared after or before running the test.

Read More

Ubuntu 18.04: unable to log in after locking PC

Hi, Ok, this was an interesting one. I want to write this down for myself and other people who might have this problem in the future. Last thursday, while at work, I decided to get a cup of coffee, so naturally I locked my PC. After getting back and trying to log in, the spinner kept spinning and after a about 10-20 seconds I got the text “Authentication error”. Crap.

Read More

Git Submodules

Hi, I always forget those damn commands for adding and deleting submodules from a GIT repository. I thought it might be wise to put those commands on my website, for future reference. Adding submodules git submodule add https://github.com/dukeofharen/Ducode.Essentials Initializing submodules If you’ve already checked out your repository, but haven’t pulled the submodules yet, execute the following command. git submodule update --init --recursive Pull all changes for all submodules git submodule update --remote Deleting submodules Source: https://gist.

Read More

Windows Tools

Welcome to my ultimate Windows tools list. This is the list with tools I always install when I install a fresh copy of Windows. This list is constantly updated. If you have any good suggestions, I’m open to it :) Just leave a reaction. Dev tools Notepad++ (https://notepad-plus-plus.org/download/v7.html) Sublime Text (https://www.sublimetext.com/3) XAMPP (https://www.apachefriends.org/index.html) MySQL (http://dev.mysql.com/downloads/mysql/) SQLYog (https://github.com/webyog/sqlyog-community/wiki/Downloads) Node.js (https://nodejs.org/en/) Oracle VirtualBox (https://www.virtualbox.org/wiki/Downloads) dotPeek (https://www.jetbrains.com/decompiler/) Fiddler (https://www.telerik.com/download/fiddler) LINQPad (https://www.linqpad.net/Download.aspx) Putty (http://www.

Read More

.NET (Core) Web API return content as plain text

Hi, Whenever I’m working on a WebAPI solution, I always return to the problem on “how to let WebAPI return the content as plain text”. The answer to this solution is posted on StackOverflow. [HttpGet] public HttpResponseMessage HelloWorld() { string result = "Hello world! Time is: " + DateTime.Now; var resp = new HttpResponseMessage(HttpStatusCode.OK); resp.Content = new StringContent(result, System.Text.Encoding.UTF8, "text/plain"); return resp; } In the code above, a response message is created with which you can specify what kind of content type should be returned.

Read More

C# Find Free TCP Port

Hi, Use this handy little code snippet to find a free TCP port on your machine. I always use this so I can perform multiple in-memory WebApi unit tests at the same time. public static class TcpUtilities { public static int GetFreeTcpPort() { var listener = new TcpListener(IPAddress.Loopback, 0); listener.Start(); var port = ((IPEndPoint)listener.LocalEndpoint).Port; listener.Stop(); return port; } }

Read More

Configuration validation in .NET Core

Hi, TLDR: Configuration validation using the .NET Core configuration and data annotations library. Not interested in reading the whole thing? The GitHub link to the repository is at the bottom of the page. The customer I currently work at has a large and very intricate collection of .NET reusable libraries. One of these libraries contains code to validate and read custom configuration sections in Web.config and App.config files. With the dawn of .

Read More

Powershell Complete Clean

Hi, Everybody who works with Visual Studio (no matter which version) has probably, at some point, ran a “Clean solution” on the project, only to discover that nothing was cleaned. In other cases, your code doesn’t build for no reason. In this case, it might help to run this little PowerShell oneliner: Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse } From the folder this script is executed in, it searches recursively to all folders named bin or obj and deletes those folders.

Read More

IForgot - Review Your Working Days

If you have a job and have to sit behind the PC a lot, you probably know the problem of not remembering what you’ve done earlier today (or even earlier this week). I also have the exact problem; for example, sometimes when I have to fill in the monthly hour form. Also handy for those daily standups. I’ve created a little command line tool which captures a screenshot every once in a while (you can set the interval in minutes) and saves it to a specific location on your PC.

Read More

Tutorial: Build A URL Shortener with ASP.NET MVC

Updated on 2019-04-19 Even though this code is very usable if you would like to learn about ASP.NET MVC, ASP.NET Core is the way to go for new projects. I might write this tutorial for ASP.NET Core at a certain point. The code is available on GitHub A few months ago, I’ve written a tutorial on how to create a URL shortener using Node.js, Express and MySQL (/posts/url-shortener-in-node-js-express-js-mysql-tutorial-learning-by-doing/). Since a few months, I’m a full time ASP.

Read More