- Here are the instructions for installing MySQL on a MacOS by using
homebrew
.
- First, ensure that
homebrew
is up to date and ready to brew
brew update |
- Installed mysql
brew install mysql |
Enjoy everything in everyday
homebrew
.homebrew
is up to date and ready to brewbrew update |
brew install mysql |
Hippo is a java based Content Management System (CMS) that allows you to create, control, and deliver engaging content to your visitors in every channel. Hippo CMS is an open-source, dual licensed platform.
Ref: onehippo
There are three components to Hippo CMS (wiki):
JSP
or FreeMarker
to generate pages. Alternatively a EST API
can be defined to serve structured content.Apache Jackrabbit
.grep
is a useful command to search text in a file.
Format:grep [–bcEFilnqsvx] [–e pattern] ... [–f patternfile] ... [pattern] [file ...]
grep
with multiple strings:/logs/xxx | grep -e 'error' -e 'falure'
grep
with highlight color:egrep --color=auto -i '(error|fatal|warn|drop)' /logs/xxx
Change grep
display color: following will set background to red and foreground to white:export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;37;41'
Useful links:
Writing shell scripts
Search a file for a specified pattern
Exception Message: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Learn how to recording expectations…, which needs further justification.
In case of sending HTTP post request to a URL
with parameters such as submitting a HTML form and expecting to receive some response.
public void printObjectFields(Object object) { |
Compare every filed of two objects by using CompareToBuilder
…
private int compareBrand(Brand oldBrand, Brand newBrand) { |
Either using java.net.URLEncoder
:
String str = "a=b+c"; |
A Singleto
n means a class can have one instance only (instantiated exactly once).
It gives us the flexibility to change whether the class should be singleton without changing its API.
public class Moose { |
Making an enum type with one element
// Enum singleton |
This approach is functionally equivalent to the public field approach.
In the case that a constructor has many parameters and it’s hard to remember the names.
Problem in JavaBeans pattern:
Builder is a static member of the class.
public class StaffActionLog{
private final StaffMember staffMember;
private final DateTime date;
private String actionField;
private StaffActionLog(Builder builder){
this.staffMember = builder.staffMember;
this.actionField = builder.actionField;
this.date = builder.date;
}
//StaffActionLog builder
public static class Builder{
//mandatary fields
private final StaffMember staffMember;
//reserved field
private final DateTime date = new LocalDate().toDateTimeAtCurrentTime();
//optional fields
private String actionField;
//constructor for mandatory field
public Builder(StaffMember staffMember) {
this.staffMember = staffMember;
}
//setter method for option field
public Builder actionField(String actionField){
this.actionField = actionField;
return this;
}
//build() method, return the object
public StaffActionLog build(){
return new StaffActionLog(this);
}
}
}
Call the builder functionStaffActionLog staffActionLog = new StaffActionLog.Builder(staffMember).actionField(actionField).build();
Use static factory method instead of common constructor…
//static factory method for creating staff action log |
Why we use static factory method
compared to the constructor
?
A readable name for the method to create an instance
+ Refer the static methods in class `java.util.concurrent.Executors` in JDK, such as `newFixedThreadPool`, `newSingleThreadExecutor`, `newCachedThreadPool`, and `newScheduledThreadPool` etc.
Not required to create a new instance each time
+ It's possibly that the static method returns a instance existing in the cache rather than a new instance, which can improve the performance. E.g., static method for `Integer` in JDK,
public static Integer valueOf(int i) {
assert IntegerCache.high >= 127;
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
+ The above code will return the `Integer` instances in the cache with high probability integers.
Can return an object of any type
+ Return the instance of an inherited object, e.g., the application of `java.util.EnumSet` in JDK,
+ In the following code, the `noneOf()` function will return an instance based on the parameters.
public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> implements Cloneable, java.io.Serializable {
EnumSet(Class<E>elementType, Enum[] universe) {
}
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
if (universe.length <= 64)
return new RegularEnumSet<>(elementType, universe);
else
return new JumboEnumSet<>(elementType, universe);
}
}
Siplified the creation of a new object
+ Use this
public static <K, V> HashMap<K, V> newInstance() {
return new HashMap<K, V>();
}
Map<String, List<String>> m = HashMap.newInstance();
Rather than
Map<String, List<String>> m = new HashMap<String, List<String>>();
Disadvantages: