2014-04-06

Manipulate / change git' commit timestamp

After doing a regular commit, issue this command:
git commit --amend --date="Mon Apr 7 07:33 2014 +0200"

2014-03-25

Maven PermGen space OutOfMemoryError issue

If you get something like
[ERROR] PermGen space -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
...try doing this to resolve this OutOfMemoryError issue:

 export MAVEN_OPTS="-Xmx1g -XX:MaxPermSize=512m"

2014-03-24

@Inject vs. @Resource vs. @Autowired — Java vs. Spring

@Autowired (Spring) & @Inject (Java)
  1. Matches by type
  2. Restricts by qualifiers
  3. Matches by name
@Resource (Java)
  1. Matches by name
  2. Matches by type
  3. Restricted by qualifiers, ignored if match is found by name

Replace SourceTree by CLI Git, branch names in "git log"

A graphical representation of a multi-branch commit history is usually one of the most used features of GUI tools like SourceTree. You can get the same thing in a much simpler way using
git log --graph --all --decorate
So you will see all branches, their merge commits and the branches that have been merged including a visual branch graph.

2014-03-20

Maven: No plugin found for prefix 'jetty' in the current project...

 If you get something like

[ERROR] No plugin found for prefix 'jetty' in the current project and in the plugin groups [de.hybris.mavenplugins, org.codehaus.cargo, de.hybris.platform, com.sap.research, org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/alex/.m2/repository), central (http://repo1.maven.org/maven2), hybris-repository (http://repository.hybris.com/hybris-repository)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
add something like the following to your ~/.m2/settings.xml
<pluginGroups>
    <pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
...to resolve this issue.

2014-03-12

Git branch name in your prompt

When you want to get something similar like
idea:~/my/project/hybris/order-service (develop) 
as your Bash prompt on a Mac or perhaps some other Unix OSs — where "(develop)" could be your currently checked out Git branch — add this
PS1='\h:\[\e[0;31m\]\w\[\e[m\]`__git_ps1` ' 
or 
PS1='\h:\[\e[0;31m\]\w\[\e[m\] \e[1;31m\]$(__git_ps1 %s)\e[m ' 
to your ~/.bash_profile

Alternatively you could use
PS1='`__git_ps1` '
just to see the branch name.

2014-03-08

NPE killer in Java8 to prevent NullPointerExceptions

In JDK8 the Optional<T> type monad has been introduced. The purpose of this class is essentially to facilitate the active thinking about the case when null might be assigned to an object causing a NullPointerException when this object will be dereferenced.

Consider this:
public static Optional<Drink> find(String name, List<Drink> drinks) {  
  for(Drink drink : drinks) {
    if(drink.getName().equals(name)) {
    return Optional.of(drink);
    }
  }
  return Optional.empty();
}
List<Drink> drinks = Arrays.asList(new Drink("Beer"), new Drink("Wine"), new Drink("Cocktail"));
Optional<Drink> found = find("Beer", drinks);
if(found.isPresent()) {
  Drink drink = found.get();
  String name = drink.getName();
}

2014-03-06

Delete a remote / local Git branch

git branch -d your_local_branch_to_delete # use the simple name
git push origin :your_remote_branch_to_delete # use the simple name

Mark conflicting files as resolved in Git

After you've manually resolved a Git merge conflict, you have to mark the resulting file as "resolved" (notion from other DVCSs). Just do this to achieve this:

git add your_file_with_manually_resolved_conflicts.txt

Generics: difference between a wildcard vs Object

The short version is:

Collection<Object> != (Collection<?, ?> == Collection)
or
Map<Object, Object> != (Map<?, ?> == Map)
Why? Using just Collection is — since Java 5 & the introduction of Generics — a short form for Collection<?> collectionOfUnknown which is not the same as Collection<Object> collectionOfObjects because you can assign any collection to collectionOfUnknown like Collection<Foo> collectionOfFoos, Collection<Bar> collectionOfBars or Collection<Object> collectionOfObjects but you cannot assign Collection<Foo> collectionOfFoos to a Collection<Object> collectionOfObjects.