Install Tor with torsocks and proxychains on Ubuntu 18.04

sudo apt install tor torsocks proxychains
tor --hash-password "passwordhere"

CookieAuthentication OR HashedControlPassword (if you choose to uncomment HashedControlPassword, copy the hashed password you got in the previous step and paste it next to HashedControlPassword in the torrc file)

nano /etc/tor/torrc
# This provides a port for our script to talk with. If you set this then be
# sure to also set either CookieAuthentication *or* HashedControlPassword!
#
# You could also use ControlSocket instead of ControlPort, which provides a
# file based socket. You don't need to have authentication if you use
# ControlSocket. For this example however we'll use a port.

ControlPort 9051 # <--- uncomment this ControlPort line

# Setting this will make Tor write an authentication cookie. Anything with
# permission to read this file can connect to Tor. If you're going to run
# your script with the same user or permission group as Tor then this is the
# easiest method of authentication to use.

CookieAuthentication 1 #either uncomment this or below HashedControlPassword line

# Alternatively we can authenticate with a password. To set a password first
# get its hash...
#
# % tor --hash-password "my_password"
# 16:E600ADC1B52C80BB6022A0E999A7734571A451EB6AE50FED489B72E3DF
#
# ... and use that for the HashedControlPassword in your torrc.

HashedControlPassword 16:E600ADC1B52C80BB6022A0E999A7734571A451EB6AE50FED489B72E3DF #if you choose to uncomment this line, paste your hashed password here
sudo /etc/init.d/tor restart

Test

curl 'https://api.ipify.org'
torsocks curl 'https://api.ipify.org'
proxychains curl 'https://api.ipify.org'

References
https://www.linux.com/blog/beginners-guide-tor-ubuntu%20

Install VirtualBox on KDE Neon Ubuntu 18.04

sudo apt install build-essential dkms linux-headers-$(uname -r)
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb http://download.virtualbox.org/virtualbox/debian bionic contrib"
sudo apt install virtualbox-6.0

Download VirtualBox Extension Pack

sudo VBoxManage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-${LatestVirtualBoxVersion}.vbox-extpack

 

References
https://tecadmin.net/install-virtualbox-on-ubuntu-18-04/
https://www.virtualbox.org/wiki/Downloads
https://download.virtualbox.org/virtualbox/
https://www.tecmint.com/install-virtualbox-guest-additions-in-ubuntu/

Convert Joda-Time `DateTime` with timezone

DateTime dateTimePlus2 = DateTime.parse("2015-07-09T05:10:00+02:00");
System.out.println(dateTimePlus2);

DateTime dateTimeUTC = dateTimePlus2.withZone(DateTimeZone.UTC);
System.out.println(dateTimeUTC);

LocalDateTime localDateTimeUTC = dateTimeUTC.toLocalDateTime();
System.out.println(localDateTimeUTC);

References
https://stackoverflow.com/questions/27381626/convert-joda-time-datetime-with-timezone-to-datetime-without-timezone
https://stackoverflow.com/questions/23939576/how-to-specify-a-timezone-for-a-joda-datetime-object

Returning Image/Media Data with Spring

@RequestMapping(value = "/image-manual-response", method = RequestMethod.GET)
public void getImageAsByteArray(HttpServletResponse response) throws IOException {
    InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg");
    response.setContentType(MediaType.IMAGE_JPEG_VALUE);
    IOUtils.copy(in, response.getOutputStream());
}

or

@GetMapping(
  value = "/get-image-with-media-type",
  produces = MediaType.IMAGE_JPEG_VALUE
)
public @ResponseBody byte[] getImageWithMediaType() throws IOException {
    InputStream in = getClass()
      .getResourceAsStream("/com/baeldung/produceimage/image.jpg");
    return IOUtils.toByteArray(in);
}

References
https://www.baeldung.com/spring-mvc-image-media-data
https://www.baeldung.com/spring-controller-return-image-file

Make iptables rules persistent after reboot on Ubuntu 18.04

sudo apt install iptables-persistent netfilter-persistent
systemctl enable netfilter-persistent
netfilter-persistent save
netfilter-persistent start

iptables-save  > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6

iptables-restore  < /etc/iptables/rules.v4
ip6tables-restore < /etc/iptables/rules.v6

systemctl stop    netfilter-persistent
systemctl start   netfilter-persistent
systemctl restart netfilter-persistent

Remove persistent iptables rules

To remove persistent iptables rules simply open a relevant /etc/iptables/rules.v* file and delete lines containing all unwanted rules.

References
https://askubuntu.com/questions/1052919/iptables-reload-restart-on-ubuntu-18-04
https://linuxconfig.org/how-to-make-iptables-rules-persistent-after-reboot-on-linux