czwartek, 13 października 2016

Merging all commits in repo to one

Today note copied from Stack Overflow (please consider of backuping your repo before this):
git log --oneline
Copy SHA of first commit and next (it's reset your local repo state withouch changing files):
git reset --soft <SHA of first commit>
Check that everything to commit is green:
git status
Commit your changes (--amend fixes last commit), you can change commit message by adding "-m <your new message>":
git commit --amend
Push your changes:
git push --force

środa, 3 sierpnia 2016

Custom and localized messages spring validation API

Put this code inside your web configuration:
    @Bean
    public MessageSource messageSource() {
        return new MessageSourceAutoConfiguration().messageSource();
    }
    
    @Bean(name = "validator")
    public LocalValidatorFactoryBean validator()
    {
        LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
        bean.setValidationMessageSource(messageSource());
        return bean;
    }
     
    @Override
    public Validator getValidator()
    {
        return validator();
    }
and in validation annotation use:
@NotBlank(message = "{not.blank.message}")
private String foo;

In your classloader put file /messages_en.properties:
not.blank.message=Custom not blank message

czwartek, 9 czerwca 2016

Single quote and xargs in Bash

xargs strips single quote mark from input, so if you want pass some data by xargs you will se error:
user:~/$ echo "This is single quote: '" | xargs -I {} echo {}
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
To do this properly it is necessary to add "-0" parameter:
user:~/$ echo "This is single quote: '" | xargs -0 -I {} echo {}
This is single quote: '
Or use sed:
user:~/$ echo "This is single quote: '" | sed "s/'/\\\\'/g" | xargs -I {} echo {}
This is single quote: '
Et voilà!

piątek, 15 kwietnia 2016

piątek, 8 kwietnia 2016

PrimeFaces remoteCommand with parameters

HTML view:
<p:remoteCommand name="remoteCommandName" actionListener="#{mBean.remoteCommandActionlistener}" />
Backing bean code:
public void remoteCommandActionlistener() {
  String param1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param1");
  String param2 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param2");
  System.out.println("param1: " + param1 + ", param2: " + param2);
}
JavaScript call:
remoteCommandName([{name: 'param1', value: 'value1'}, {name: 'param2', value: 'value2'}])