Posts

Spring boot and mongodb with geo-localisation queries 1/3

MongoDB offers a number of indexes and query mechanisms to handle geospatial information, below are some of the features offered by the database : SurfacesLocation DataQuery OperationsGeospatial indexes.....More detailed information can be found at their website : MongoDB Geospatial queriesIn this 3 part post we will be creating a sample REST API application using Spring Boot, Spring Data and MongoDB to determinate if a given "Interest Point" is within a certain distance of the provided coordinates 1. Setup Before we start please ensure that you have a running MongoDB instance So let's get things started, we will be using Gradle as our build tool for this project, if you're not familiar with this build tool you can read the documentationBelow is the build file used to build our project, there is some noise in here that is related to IDE support as well as a few things needed to deploy this application in heroku which can be avoided but I've chosen to leave here f…

Spring Data force version and lastmodified date to update on JPA Entity

Spring data has a feature that allows you to track automatically a certain amount of fields through annotations :@CreatedDate : The date on which the entity was created@CreatedBy : The user that created the entity@LastModifiedDate : The date the entity was last modified@LastModifiedBy : The user that modified last the entity@Version : the version of the entity (increased each time the entity is modified and savesd)Let's say for example we have this simple entity with the appropriate annotations : @Entity @EntityListeners(AuditingEntityListener.class) public class Contact implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Version() private Long version = 0L; @NotNull @CreatedDate private Date creationDate; @NotNull @Size(max = 50) @CreatedBy private String creationUserLogin; @NotNull @LastModifiedDate private Date m…

Use Github as a CDN to store and serve static content (JavaScript, CSS, Images) with rawgit

Image
In this article I will be explaining how to use Github's "raw" feature coupled with rawgit to store and serve static content Please note I assume you have some basic git knowledge 1.- Creating a Github accountOk so first things first, in order to do this you need a Github account; so if you don't have one head up to the GitHub website and create one ; go ahead I'll wait :) 2.- Creating a Github repositoryLogin to your Git account and create a new repository :Provide a name for your repo (for example static_files) :3.- Build repository structure We will now create a folder structure for our repository in order for us to organise the files, for example : cssjsimgSo now go ahead and clone your git repository from either the command line or with your favorite tool git clone https://github.com/xxxx/static_files.git Once the repository is cloned; go ahead and create the 3 folders mentioned above cd static_files mkdir css mkdir js mkdir img Ok so Git does not allow y…

Preventing bash commands to be displayed in the history or deleting a specific command from history

It's sometimes useful when using the linux command line to prevent things to go into the bash history; for example if you're using curl to download a file while providing your username password.This can be easily done in linux by configuring the HISTCONTROL variable in either your ~/.bashrc (which I recommend in order to have it permanently in your bash sessions) or by just changing the value for your current session. Either way either set the variable as follows on your ~/.bashrc or on your current session HISTCONTROL=ignorespace If you took the ~/.bashrc approach don't forget to source it to have i Once this is done commands that you start with a white space will be ignored : [root@myserver] curl -o strx25.tar.bz2 --user user:password http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2 note the whitespace before the curl commandRemoving a specific line from historyNow if you have to remove a specific line from history this is done in 2 steps Display commands…

OSX Wi-fi and Ethernet network simultaneously connected and static routing

Image
So recently I had a situation where I had my Ethernet and Wifi connected to 2 different networks in my MAC OS X, and I had a very specific use case for this I needed to use the Ethernet connection to access 1 specific host (an internal web service), the connection through the ethernet cable allowed this but did not allow internet access, the Wifi connection allowed internet access but will not allow access to the internal web service, so basically what I needed was :Have both connections activeAccess the internal web service through the Ethernet connectionAccess all the other hosts through the Wi-fi connectionJust connecting both interfaces does not work I was either getting access to the internet or either access to the internal WebService; if you check this article over at apple OS X network interfaces priority you can see that you can change the priority used by the system to route the requests; so if you change the priority of the Wi-fi to be on top you get internet access but not…

Debug Java SSL/HTTPS WebService with man in the middle proxy

Image
In this article I will be showing how to debug WebServices HTTPS/SSL requests by using a Man in the Middle proxy, this can especially be useful when dealing with WebServices errors since all request will go through the proxy we will be able to see all the content that is sent back and forwardThere are several proxies out there that support HTTPS/SSL queries but my favorite by far is mitmproxy and this is the one I will be showing in this post.The installation instructions detailed here for mitmproxy are for MacOSX but can easily be adapted to Linux distributions; please note that a lot of the instructions detailed here apply to Java applications1. Install mitmproxyPersonally I use home-brew for my package management; so I assume you have it installed (otherwise you'll have to install mitmproxy manually) Run the following command to install mitmproxy : brew install mitmproxy Your output should look something similar to this ==> Installing dependencies for mitmproxy: libpng, f…

Linux change timezone and force ntpd synchronization

This short article shows how to change the timezone of the Linux distribution as well as forcing the synchronisation of date/time with the ntpd serversThis applies specifically applies to CentOS so some changes might be possible depending on the distribution1.Change timezone cp /etc/localtime /root/old.timezone rm /etc/localtime ln –s /usr/share/zoneinfo/Europe/Zurich /etc/localtime 2.Add ntpd servers to you configuration file (optional)Edit (or create) the /etc/ntpd.conf and add the appropriate ntpd servers : server xxx.xxx.xxx.xxx server xxx.xxx.xxx.xxx note: xxx.xxx.xxx.xxx is the ip or domain name of the server 3.Stop the ntpd daemon /etc/init.d/ntpd stop 4.Force the date updateForce the update of the date with the new timezone and eventually the ntpd servers ntpdate xxx.xxx.xxx.xxx 5.Stop the ntpd daemon /etc/init.d/ntpd start 6.Stop the ntpd daemon date