Skip to content

Instantly share code, notes, and snippets.

View ntxinh's full-sized avatar
💭
❤️ .NET & JavaScript

Xinh Nguyen ntxinh

💭
❤️ .NET & JavaScript
View GitHub Profile
@ntxinh
ntxinh / unsaved-changes-guard.ts
Created October 3, 2019 04:41 — forked from Splaktar/unsaved-changes-guard.ts
Guard against navigating away when there are unsaved changes
import {CanDeactivate, Router} from '@angular/router';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Observer} from 'rxjs/Observer';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
export interface CanComponentDeactivate {
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}
@ntxinh
ntxinh / vol.sh
Created July 3, 2018 10:23
Script Increase/Reduce Volume Linux
# Declare variable
command=$1
increment=5%
icon_name=""
display_volume=0
# Increse volume
if [ "$command" = "up" ]; then
pactl set-sink-volume @DEFAULT_SINK@ +$increment
fi
@ntxinh
ntxinh / deploy-google-app-engine.sh
Created February 15, 2018 17:29
Shell Script Deploy Google App Engine
export GAE_PATH=/data/project-name/gae-json-keys
export GAE_KEY=/data/project-name/gae-json-keys/project-name.json
cp -rf $GAE_PATH/tbm-dev/* ./
cd $WORKSPACE
mvn clean install
# 1 - WS AUTH
if [ "$WS_AUTHEN_AUTHORIZE" = "true" ]; then
if [ -d "$WORKSPACE/ws-authen-authorize" ]; then
@ntxinh
ntxinh / main.java
Created February 4, 2018 10:28
Java - Spring boot with FreeMarkerTemplate
Map<String, Object> dataModel = new HashMap<>();
dataModel.put("messages1", "a");
dataModel.put("messages2", "b");
try {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_26);
cfg.setDirectoryForTemplateLoading(new File("/home/local/xinh.nguyen/Gitlab/mycode/src/main/resources/template/mail"));
String body = FreeMarkerTemplateUtils.processTemplateIntoString(
cfg.getTemplate("candidate_pipeline_template.ftl"),
@ntxinh
ntxinh / entity.java
Created February 3, 2018 04:32
Java - Spring Entity
// primitive types
@Column
private Boolean isOpen;
// reference types
@Column
private boolean open;
@ntxinh
ntxinh / BeanValidation.java
Created February 3, 2018 04:31
Java - Bean validation
// org.hibernate.validator.constraints
// javax.validation.constraints
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
for (ConstraintViolation<User> constraint : constraintViolations) {
System.out.println(constraint.getPropertyPath() + " "
+ constraint.getMessage());
}
@ntxinh
ntxinh / Jackson.java
Created February 3, 2018 04:31
Java - Jackson
@JsonCreator
public static EJobStatus create (String value) {
if(value == null) {
return null;
}
for(EJobStatus v : values()) {
if(value.equals(v.toString())) {
return v;
}
}
@ntxinh
ntxinh / Reflection.java
Created February 3, 2018 04:30
Java - Reflection
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
public class Example {
public static void main(String[] args)
@ntxinh
ntxinh / RxJava2.java
Created February 3, 2018 04:30
Java - RxJava2
import io.reactivex.Observable;
import java.util.Arrays;
import java.util.List;
public class ExampleRxJava {
public static void main(String[] args) {
List<String> symbols = Arrays.asList("GOOG", "AMZN", "ITC");
Observable<StockInfo> feed = StockServer.getFeed(symbols);
@ntxinh
ntxinh / 1.java
Created February 3, 2018 04:26
Java - Spring RestTemplate
//
ParameterizedTypeReference<ResponseBean<List<JobHiringPipelineDTO>>> responseType = new ParameterizedTypeReference<ResponseBean<List<JobHiringPipelineDTO>>>() {};
ResponseEntity<ResponseBean<List<JobHiringPipelineDTO>>> exchange = restTemplate.exchange(
"http://localhost:8082/list-job-hiring-pipeline",
HttpMethod.GET,
null,
responseType);
ResponseBean<List<JobHiringPipelineDTO>> jobHiringPipelineDTOS = exchange.getBody();