Skip to content

Instantly share code, notes, and snippets.

View luanvuhlu's full-sized avatar

luan vu luanvuhlu

View GitHub Profile
button{
border: 0;
background: none;
box-shadow:none;
border-radius: 0px;
}
@luanvuhlu
luanvuhlu / check_date.js
Created April 5, 2017 06:34
Validate date format yyyy/MM/dd
function checkDate(dateString){
if(!/^\d{4}\/\d{1,2}\/\d{1,2}$/.test(dateString))
return false;
var parts = dateString.split("/");
var year = parseInt(parts[0], 10);
var month = parseInt(parts[1], 10);
var day = parseInt(parts[2], 10);
console.log(parts)
@luanvuhlu
luanvuhlu / SendMail.java
Last active June 11, 2018 09:17
Send mail by /usr/sbin/sendmail
try {
Process p = Runtime.getRuntime().exec(new String[]{
"/usr/sbin/sendmail",
"-t"
});
try (OutputStreamWriter os = new OutputStreamWriter(p.getOutputStream(), "UTF8")) {
os.write("Content-Type: text/html\n");
os.write("From: [email protected]\n");
os.write("To: [email protected]\n");
os.write("CC: [email protected]\n");
public final class OsCheck {
/**
* types of Operating Systems
*/
public enum OSType {
Windows, MacOS, Linux, Other
};
// cached result of OS detection
protected static OSType detectedOS;
@luanvuhlu
luanvuhlu / map.java
Created May 30, 2017 10:18
Iterator map
Map<String, String> map = ...
for (Map.Entry<String, String> entry : map.entrySet())
{
System.out.println(entry.getKey() + "/" + entry.getValue());
}
@luanvuhlu
luanvuhlu / AntPathMatcher.txt
Created May 31, 2017 02:07
Ant-style path patterns
Part of this mapping code has been kindly borrowed from Apache Ant.
The mapping matches URLs using the following rules:
? matches one character
* matches zero or more characters
** matches zero or more directories in a path
{spring:[a-z]+} matches the regexp [a-z]+ as a path variable named "spring"
Examples
com/t?st.jsp — matches com/test.jsp but also com/tast.jsp or com/txst.jsp
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
iptables -L -n
iptables-save | sudo tee /etc/sysconfig/iptables
service iptables restart
mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=design"
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'IP' IDENTIFIED BY 'PASSWORD';
FLUSH PRIVILEGES;
exit;
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody
public ValidationError handleValidationException(MethodArgumentNotValidExceptionexception) {
Set<ValidationError> errors = new HashSet<ValidationError>();
for (ObjectError er : exception.getBindingResult().getAllErrors()) {
errors.add(new ValidationError(er.getObjectName(), er.getDefaultMessage()));
}
return new ValidationErrorResponse(errs);