четверг, 22 декабря 2016 г.

Maven Enforcer Plugin

Due to continuous integration sometimes it is difficult to control build environment. Someone can wrongly setup Jenkins job and your project won't build. In order to identify such errors much more faster one can use maven-enforcer-plugin. Just add the following xml to the pom and that's it:

                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>${maven.enforcer.plugin.version}</version>
                <executions>
                    <execution>
                        <id>enforce-versions</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <!--
                                      Maven 3.0.3 or later. That's the earliest version to enforce
                                      declaration ordering for plugins in the same phase.
                                     -->
                                    <version>[3.0.3,)</version>
                                </requireMavenVersion>
                                <requireJavaVersion>
                                    <!-- Java 1.8 or later. -->
                                    <version>[${java.version},)</version>
                                </requireJavaVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Java Jackson 2. Custom Date deserialization in JSON.

Hi. I want to share receipt with you how to write custom date deserializator for Jackson 2. This could be helpful when you deserialize value into generic Map and want that dates actually were stored like java.util.Date not String.

Deserialization usually done like so:
 Map<String,Object> data = null;
 data = mapper.readValue(someInputStream,Map.class);


In order to create custom serializator one needs to extend the class com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer. Here is the example of custom date deserializator:
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonTokenId;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer;
import com.fasterxml.jackson.databind.module.SimpleModule;

import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class DDeserializer extends UntypedObjectDeserializer
   
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");

    @Override
    public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {

        if (jp.getCurrentTokenId() == JsonTokenId.ID_STRING) {
            try {
                LocalDate localDate = LocalDate.parse(jp.getText(),formatter);
                java.util.Date date = java.sql.Date.valueOf(localDate);
                return date;
            } catch (Exception e) {
                return super.deserialize(jp, ctxt);
            }
        } else {
            return super.deserialize(jp, ctxt);
        }
    }

    public static ObjectMapper regObjectMapper(ObjectMapper mapper){
        SimpleModule simpleModule = new SimpleModule();
        simpleModule.addDeserializer(Object.class, new DDeserializer());
        mapper.registerModule(simpleModule);
        return mapper;
    }
}

Please note, that here is java 8 Date & Time API is mixed with plain old Date API. But the approach here is important.
Take a note in regObjectMapper method. In order to use custom deserializator it needs to be registered in ObjectMapper. After this you could use it to deserealize strings in to Date.

понедельник, 20 июня 2016 г.

The Pragmatic Programmer: From Journeyman to Master.

Hello, my dear reader!

Today I'm going to provide some thoughts after reading the Pragmatic Programmer book.
Here are the thoughts that caught me:
  1. Tag a commit, to see how many number of files affected by the bug fix.
  2. Find the opportunity to refine the code.
  3. Flexible, adaptable design.
  4. Deployment: stand-alone, client-server, n-tier model just by changing a configuration file.
  5. Domain specific language.
  6. Know your shell & text editor.
  7. Fix the problem, not the Blame.
  8. Bertrand Meyer.
  9. Design by contract for java.
  10. Perl for text processing.
  11. Pluggable exception handlers.
  12. Resources: memory, transactions, threads, files, timers, sockets.
  13. Metaprogramming.
  14. Large-Scale C++ Software design.
  15. The project needs at least two "heads" -- one technical, the other administrative. The technical head sets the development philosophy & style, assigns responsibilities to teams, and arbitrates the inevitable "discussions" between people. The technical head also looks constantly at the big picture, trying to find any unnecessary commonality between teams that could reduce the orthogonality of the overall effort. The administrative head, or project manager, schedules the resources that the teams need, monitors and reports on progress, and helps decide priorities in terms of business needs. The administrative head might also act as the team's ambassador when communication with the outside world.
  16. Tool builders -> Automation of project activities.
  17. Give each member the ability to shine in his or her own way.
  18. Unit testing: resource exhaustion, errors, and recovery.
  19. Surviving Object-Oriented Projects: A Manager's Guide: Alister Cockburn.
  20. Eiffel.
  21. Michael Holt. Math puzzles & games.
 Nice book. Keep up!

суббота, 11 июня 2016 г.

My reading list. What has been done

Here is the first attempt to present you my reading list - what I had read already.
There are knowledge that expire too fast and knowledge that have more long term value.  Here I want to share the list of books that I think should be read by every developer.

This is not a complete list. I'm working on it. If only I knew that all these books existed when I was studying at the institute...
  1. Code Complete: A Practical Handbook of Software Construction, Second Edition 2nd Edition by Steve McConnell
  2. Effective Programming - More Than Writing Code - Jeff Atwood
  3. Soft Skills: The software developer's life manual 1st Edition by John Sonmez
  4. How to Stop Sucking and Be Awesome Instead by Jeff Atwood
  5. Joel on Software: And on Diverse and Occasionally Related Matters That Will Prove of Interest to Software Developers, Designers, and Managers, and to Those Who, Whether by Good Fortune or Ill Luck, Work with Them in Some Capacity by Joel Spolsky
  6. More Joel on Software: Further Thoughts on Diverse and Occasionally Related Matters That Will Prove of Interest to Software Developers, Designers, ... or Ill Luck, Work with Them in Some Capacity 2008th Edition by Avram Joel Spolsky
  7. Getting Started as an Independent Computer Consultant by Mitch Paioff
  8. The Deadline: A Novel about Project Management by Tom DeMarco 
  9. Design Patterns: Elements of Reusable Object-Oriented Software 1st Edition by Erich Gamma

If anyone wants to add something, feel free ;-)

суббота, 9 апреля 2016 г.

SQL and MongoDB

It has been a long time since I had used MongoDB. In the meantime I am very interested in the possibility to use plain SQL when working with MongoDB.

At first my toolbelt has the https://robomongo.org/ tool. This tool allow to ease the work with Mongo console. How can use SQL? That's the main question. There is a project Apache Drill which allows you to connect to MongoDB, Hadoop, Hbase, files and query with SQL. Moreover, you can use the Apache Drill jdbc driver with any tools that support JDBC!
Pretty good!

среда, 30 марта 2016 г.

Corpus analysis software

Here is the list of software for corpus analysis:
  1. AntConc
  2. TextStat
  3. Poliqarp and sources.
Here is the videos of how to use AntConc.

Tom DeMarco. Quotes from the "Deadline"

  • By avoiding risk man loose new opportunities and benefits which can bring him changes.
  • Define the list of the risks for each project.
  • Avoid unnecessary work.
  • Day we loose at start of the project is the same as the day at the end.
  • Define the size of each project.
  • People won't think faster under pressure.
  • Always announce the questions under consideration before the meeting.

воскресенье, 20 марта 2016 г.

Tom DeMarco. The Deadline: A Novel About Project Management

Started to read this book. It is a classic now and classic among project management books. Like it style. Very fascinating. Easy to read. And not to forget to make quotes!

Here are some quotes from the diary of the hero.
Four main management rules:
  1. Find the right people
  2. Give them the job they most fitted to
  3. Do not forget about motivation
  4. Help them to be as one team and continue to operate as such.
All other is administration nonsense. ;-)

пятница, 29 января 2016 г.

My new hardware

On my birthday I've got WD Black 750GB for my notebook. Only recently I had time to replace it in Lenovo. 

The movement process went smoothly. To move the existing partitions to the disk I have used Acronis True Image, which can be downloaded from WD site for free. 

One problem I encounter is how to resize the partition after the partition movement? Windows builtin utility couldn't help me. It couldn't resize the partition who has free space before the begining. But I have found out the Partition Manager 14 Free Edition which is free for personal use. With it I could resize the partition in no time. 

Now my PC boots much faster then before. Think the next step is to get the SSD for 1 Tb :-).

четверг, 14 января 2016 г.

Learn Git in a Month of Lunches

Happy New Year, 2016!

I have decided to structure my knowledge of git, so I took the Learn Git in a Month of Lunches.
This is book is easy to read and understand. Every chapter contains no bloat and self-contained. It's written like tutorial and contains practice labs.

Besides git it also has the description about tools like Sourcetree and Eclipse git integration.

If you like you can start to read from any chapter.
What I particularly like is the chapter about git rebase. I think this is a must have book on your shelf.