Posts

Showing posts from 2014

OS X ethernet self-assigned ip

Recently I had a problem with my mac, my wifi connection was working properly but my ethernet connection was not it was getting a self-assigned IP. After checking the obvious culprits (cable, router, switch) it turns out that the problem was elsewhere.After searching the internet I realized that I wasn't the only one having this problem, and there are a lot of fixes such as : Deleting the "/Machintosh HD/Library/Preferences/com.apple.alf.plist" and rebootingResetting the PRAMRecreating a network configurationBy chance I decided to try and disable IPv6 on the network interfaces like so : networksetup -setv6off Wi-Fi networksetup -setv6off Ethernet And after rebooting it worked !!So there you go; I hope this works for you too!!On a final note: Another thing I was about to try was uninstalling the virtual interfaces of my VMWARE but it didn't get to that

Git svn clear stored credentials

Recently a change was made in my company in the way the SVN repositories were handled; as a result we had to change the accounts we used to access the reposWhenever I tried pulling or pushing info into those repositories I was getting errors like : RA layer request failed: PROPFIND request failed on '/svn/2001/ufasoli/myproject/trunk': PROPFIND of '/svn/2001/ufasoli/myproject/trunk' : 403 Forbidden (https://internal.svn.com) at /lib/Git/SVN.pm line 717 I realized that it was because the credential information was cached locally on the machine, so the system was sending old information , the tricky part was that the old accounts allowed authentication on the repositories, they were just no longer authorized to do anything on them, so I was getting an HTTP 403 error and the system was not prompting me for a new password (since the old accounts could still log in...) So this is how I fixed it on my windows machine: Under your user folder you should have a folder where …

Building and installing git 2.x on Windows

So Git 2.x has been out for a few months now and it came with some nice stuff, you can read more about it here However if you are under windows, the git portage msysgit has yet to release a 2.X portage(as of this writing the latest version is 1.9.4) If you want to install Git 2 on Windows you will need to build it from the source, and here is how it's done 1. Download the Git build environmentHead up to the Github page https://github.com/msysgit/msysgit and download the latest version from the master branch Unzip it let's say to c:/tmp/git/msygit-env2. Download the latest version of gitHead up to the Github page https://github.com/msysgit/git and download the latest version from the master branch Unzip it let's say to c:/tmp/git/git3. Copy the git folderNow copy the entire contents of the c:/tmp/git/git under c:/tmp/git/msygit-env/git4. Build GitNow you can fire up a DOS console and head up to the msysgit and build Git cd c:/tmp/git/msygit-env msys.bat Once the build s…

NodeJS, tune or disable HTTP agent pooling

When using NodeJS's HTTP module to query you might end-up having performance problems if you do some heavy HTTP querying.By default when executing queries using the HTTP module NodeJS will use connection pooling with the maximum number of connection sockets being 5, so if you hit the bottleneck your HTTP queries will lag as they will be queued. To my knowledge you have 2 options to "counter" this behavior : Increase the number of http sockets Disable the HTTP agent per request1. Increase the number of http sockets var http = require('http'); // increase the maximum number of http connections in the pool http.globalAgent.maxSockets = 100; //regular http request options var options = { port: 1337, hostname: '127.0.0.1', method: 'GET', path: '/test' }; // make http query var req = http.request(options, function(res) { console.log('STATUS: ' + res.statusCode); …

Spring boot JPA broken encoding on database when loaded from data.sql file

As covered in a previous article (here and here) spring-boot is a very useful framework when working on full enabled Spring projectsRecently I wasted some time with yet another encoding problem.. where all my accentuated and special characters where corrupted.I was using the data.sql convention that states that if a file named data.sql is found in the CLASSPATH spring will use this file to bootstrap the database, my SQL file was properly encoded in UTF-8 as well as my maven-resources-plugin however the data recovered from the database was corrupted (accents and special characters where broken) After reading a bit the documentation I found out that the source of the problem was at the moment of reading the SQL file that the encoding was causing trouble.. thankfully you can fix this one pretty easlily by changing one property value : spring.datasource.sqlScriptEncoding=UTF-8 spring-boot has a lot of useful properties that allow you to tune the framework which you can find here

Maven custom packaging with the assembly plugin

It's not uncommon to need a custom packaging or assembly for a given project for some reason or another, this can be accomplished in a certain number of ways Recently I needed an application to be packaged as the following structure : |- runnable-jar.jar |- lib |-- axis.jar |-- commons.logging.jar |- certificates |-- cacerts.jks |- config |-- config.properties |- logs The schema is pretty self-explanatory I needed a runnable JAR at the root of my dist folder with a few other folders such as config, logs, etc.One way to accomplish this with maven is to use maven-assembly-pluginThe Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.Your project can build distribution assemblies easily, using one of the convenient, prefabricated assembly descriptors. These descriptors handle many common operations, such as pac…

Asciidoctor maven integration : introduction to asciidoctor and maven asciidoctor plugin part 2/2

Image
This is the second part of the Asciidoctor maven integration tutorial part 1/2 where we explore some of Asciidoctor cool features 4. Additional cool formatting elements and contentThere are plenty of nice cheat-sheets out there that resume much better all the cool stuff you can do with (see 5. Some useful links) so I will just list here a few tips to get you started 4a. Asciidoc files inclusion or compositionPersonally when writing documentation I like to create a separate file for each topic and then include them in an a big index file (you can do this otherwise if you prefer) this can easily be done using the include macro Let's create a new Asciidoc page named topic1 and add some content to it = Topic 1 == Intro This page describes some information related to topic1 and now include the newly created page using the include macro = Asciidoctor hello world include::topic1.ad[] After re-compiling the code you should end up with the content of the file topic1.ad inside t…

Asciidoctor maven integration : introduction to asciidoctor and integration with maven asciidoctor plugin part 1/2

Image
For some time now I have been hearing a lot aboutAsciiDoc as a mean to write documentation but never had the chance to use it...Recently I stumbled upon AsciiDoctor and since I was about to begin working on a small project with no previous documentation I thought it was the perfect time to try it out.. Documentation is an important part of a project which more often than we would like gets put aside for a great number of reasons. One of them is that we as developpers tend not to like writing documentation...0.Intro and scope In this tutorial I will show you how to integrate Asciidoctor class in your Java project and get you started with a small documentation example as well as some tips such as : Asciidoc templating using fragments Generating a TOC (table of contents) for your documentationIntegrating images in your asciidoc filesCode syntax highlighting in your asciidoc filesMaking external links (i.e. _target blank)Please note that I assume you have some knowledge of Asciidoc so I …

Java Mail network is unreacheable connect exception

Recently I stumbled upon a weird problem while debugging a simple java application that needed to send an emailSince I was debbuging this application locally I used the FakeSMTP tool that I described in this tutorial here : Testing email sending functionality with FakeSMTP which I run locally on my machine So after editing the configuration on my Java program and firing up the SMTP server I was quite surprised to get the following exception : Caused by: javax.mail.MessagingException: Could not connect to SMTP host: 127.0.0.1, port: 25 (java.net.SocketException: Network is unreachable: connect) System.setProperty("java.net.preferIPv4Stack" , "true"); So once you are sure you problem is not coming from a non running SMTP server or a network connection, you can check if the culprit is no other than JavaIf you read the Oracle documentation here you will see that by default Java prefers IPv6 to IPv4 which is the problem in our case since FakeSMTP binds on IPv4Luckily…

Heroku PostgreSQL and DBVisualiser connection using SSL

Image
I occasionally use Heroku to deploy webapps on the cloud combined with a Postgres database to store my relational dataI recently found a multi-platform polyglot SQL client that I could use with my MAC, this product is called DbVisualiserHowever since Heroku requires an SSL security on external connections after providing the usual database connection properties (url, username, password) when I tried to connect through DbVisualiser I was getting the error message : FATAL: no pg_hba.conf entry for host "86.200.9.63", user "u4b1uljsil33m2", database "de9td8cv06p4se", SSL off After playing a bit with the different options and reading the Postgres JDBC driver over here I found out that you can provide an Non Validating SSL factory in the connection properties to satisfy Heroku's SSL requirements In order to configure the SSL properties in DbVisualiser you need to edit the following SSL properties in the Properties tab : SSL : truesslfactory : org.postgres…

SSH linux how to kill an idle or innactive connection

Sometimes when you're disconnected abruptly from a remote server like if your network connection gets dropped, you can be left with a ghost or inactive SSH session. This can become pretty annoying when you're doing some SSH port redirection since you will not be able to bind to a given port since the ghost connection is still using that port, and you might end up with error messages such as the following : debug1: Local connections to LOCALHOST:21521 forwarded to remote address localhost:21521 debug1: Local forwarding listening on 127.0.0.1 port 21521. bind: Address already in use debug1: Local forwarding listen Now there are a few ways of dealing with this issue, the one I prefer is a 3 step operation :1.Check who is connected to the server This step is actually optional but it allows you to check which user is currently connected to the server and prevent accidentally destroying another user's session (or at least warning him that you will do it ;) ) To check who's…

Running a spring boot application with maven

On the last 2 part tutorial that I published recently on Spring boot :Spring boot and spring data (part 1) and Spring boot and spring data (part 2) I said that when using pure maven (not the groovy approach) you needed to either package the project and then run the JAR manually or use the maven mojo exec plugin (which I preferred)But as often after playing a bit more with it I realized that there is an even simpler solution and that is using the run goal of the spring-boot maven pluginSo you can simply run your spring-boot project by executing the following goal on your console/IDE mvn spring-boot:run

Spring boot and spring data jpa tutorial - A sample application using spring 4.0 spring boot and JPA (part 2/2)

This is the second part of the Spring boot and spring data jpa tutorial - A sample application using spring 4.0 spring boot and JPA At the end of the tutorial I promised you that we will be removing one of the steps when running the application, that is merge the package and run in a maven command and make him do the work 5.- Making maven run the JAR directlyWe're going to make maven run the runnable JAR for us after it has been packaged, for this purpose we're going to use one of org.codehaus.mojo maven plugins .... org.springframework.bootspring-boot-maven-pluginorg.codehaus.mojoexec-maven-plugin1.2.1com.ufasoli.tutorials.spring.boot.HelloWorldApp ... So what's happening here ? : By adding the exec plugin to the build section of our pom.xml and providing a mainClass when we run the appropriate maven goals the application will be packaged and run directly from maven You can try this by running : mvn clean package exec:java By running this on your console the appl…

Spring boot and spring data jpa tutorial - A sample application using spring 4.0 spring boot and JPA (part 1/2)

Spring boot is a strongly opinionated framework / generator based on the principle of convention over configuration, which according to the website: Spring Boot makes it easy to create Spring-powered, production-grade applications and services with absolute minimum fuss. It takes an opinionated view of the Spring platform so that new and existing users can quickly get to the bits they need Basically by using a few annotations and minimum boilerplate code the framework/generator will configure all the necessary beans and contexts based on a set of conventions.Spring boot has a few modules that depending on your needs can speed-up development such as : spring data jpa spring data mongodb spring webspring actuator...Personally I find that when using the spring stack this tool is pretty awesome!!When using this tool you must know that there are actually 2 ways to use spring boot : Using the cli (and by extension groovy)Using good old maven and the spring-boot plugins In this tutorial we …

SyntaxHighlighter and blogger dynamic templates

Recently I decided to switch my blogger template to use one of Google's dynamic templates since I really like the possibility to switch the presentation of the blog postsEven though I thought this would be pretty straight-forward as it turns out I run into a problem. I use Alex Gorbatche's SyntaxHighlighter JavaScript plugin to "prettify" my code, and as it turns out Dynamic Templates and the Syntax Highlighter do not play well together (apparently the content of the posts is loaded after the script has been bootstrapped so you end up with ugly unreadable bits of code.After goggling here and there I found a few workarounds some worked, others not.. (I'm sorry I do not have the links now, but they are easy to found). Those who worked basically consisted in altering my previous posts to give an id to each of the pre that I had used before which was unacceptable for me. So here is the solution that I came up with by inspiring myself of the different workarounds ou…

Testing email sending functionality with a free mock smtp server

Image
Intro Often web applications include some email sending functionality that you have to develop/and test and there are certainly a lot of way to do this, use a fake-email recipient, use a dummy email recipient, spam your colleagues, etc. and there are some advantages and drawbacks to each of these approaches.Recently I had to do some maintenance on an application that would send a massive amount of emails (mailing list) and I needed to test if everything was still working properly after the code modifications and since I had to change the application to allow sending multi-part messages with attachments there was a possibility that something was broken in the process.Now for obvious reasons I could not test this in the production environment as it will have an impact on the company's SMTP server and the poor souls receiving an indecent amount of emails so I needed a mock or fake SMTP server to emulate this...A solution I present you Fake SMTP server. This great little Java program …

Keeping alive a SSH connection or in my case a multi-hop ssh tunnel to prevent timeout

Image
A few months ago I wrote an article on how to create a multi-hop SSH tunnel between 3 machines Since then I have been using this a lot for one of the projects I'm working on but I was annoyed that whenever the connection went idle for more than 2 minutes (like if I was reading an article or answering an email) the connection will be dropped abruptly and I will have to start it all over again... After playing a bit with SSH options and reading ssh man I finally found my salvation, that is the -o flag with 2 options : TCPKeepAlive Specifies whether the system should send TCP keepalive messages to the other side. If they are sent, death of the connection or crash of one of the machines will be properly noticed. However, this means that connections will die if the route is down temporarily, and some people find it annoying. On the other hand,if TCP keepalives are not sent, sessions may hang indefinitely on he server, leaving host users and consuming server resources. The de…

MongoDB using MapReduce to filter fields by text content

Let's say that we want to filter a list of documents and extract only those in which the text of one of the fields matches a given constraint, for example a word that is repeated in the text For this example I will be doing it using MongoDB's MapReduce { "_id" : "507f191e810c19729de860ea", "txtField" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus mauris arcu, lacinia a pharetra id, rhoncus in lorem. Morbi tempor consequat ante, vel porta tellus lacinia id. Phasellus vel nisi vitae velit pulvinar tincidunt non id massa. " } Below is the Map/Reduce functions that I will be applying to filter my results the results : 1.- Map Function
function Map() { // count the number of times the regexp is matched in the text for the field txtField var count = this.txtField.match(/lorem/gi); // emit the result when the pattern has been matched at least 2 times if( count != null &…

Custom number formatting in JSP with JSTL for a given locale

So this one was pretty painful to resolve and I spent a few hours struggling with it.. especially since I haven't work with JSP for A WHILE...Usually when you need to format a given number (in my case a BigDecimal) you can use the fmt:formatNumber tag if you have setted your locale properly it should use the appropriate decimal separator according to the language. However this time it wasn't working and I'm really not sure why, other fields in which I was using the spring tag spring:bind the output was properly formatted I needed to output a large number using grouping separators (by groups of 3) and at least 2 decimals What I was trying to accomplish was to have a number with Swiss grouping and decimal separators like this 2'300'120.40 but I was getting this 2 300 120,40 I tried a lot of things, like setting the locale for the page using the setLocaletag Forcing the pattern when calling the formatNumber function And different combinations of values for the dif…