Skip to content

Instantly share code, notes, and snippets.

Avatar

Jcy jcyuyi

View GitHub Profile
@jcyuyi
jcyuyi / base36.txt
Created Jan 28, 2020
List of 2-digits Base36
View base36.txt
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
@jcyuyi
jcyuyi / vpc.yaml
Created May 28, 2019
VPC with public and private subnet
View vpc.yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: 'Core network & security group stack template'
Parameters:
app:
Description: 'App name tag'
Type: String
env:
Description: 'Environment tag'
Type: String
@jcyuyi
jcyuyi / SpringBoot Snippet.md
Created Mar 29, 2019
SpringBoot Snippet.md
View SpringBoot Snippet.md

Zoned cron scheduling

@Scheduled(cron = "0 17 11 * * ?", zone = "JST") // At 11:17:00am every day JST
public void reportCurrentTime() {
    log.info("The time is now {}", dateFormat.format(new Date()));
}

Ref:

View SpringBoot Web Snippet.md

Multipart form files uploading

Server side

@PostMapping("/uploads", consumes = ["multipart/form-data"])
fun sendApplyEmail(
    @RequestPart body: FormBodyDto, 
    @RequestPart("files", required = false) files: List<MultipartFile>
) {
@jcyuyi
jcyuyi / JacksonMapUtils.java
Last active Mar 20, 2019
JacksonMapUtils.java
View JacksonMapUtils.java
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.springframework.util.ReflectionUtils;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
public class JacksonMapUtils {
@jcyuyi
jcyuyi / Dockerfile
Last active Mar 13, 2019
SpringBoot Dockerfile using docker-entrypoint
View Dockerfile
FROM openjdk:8-jdk-alpine
ENV JAVA_OPTS=""
VOLUME /tmp
ARG DEPENDENCY=api/build/dependency
COPY docker-entrypoint.sh /usr/local/bin/
COPY ${DEPENDENCY}/BOOT-INF/lib /api/lib
COPY ${DEPENDENCY}/META-INF /api/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /api
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["sh", "-c", "java $JAVA_OPTS -cp api:/api/lib/* xxx.xxx.xxx.App"]
@jcyuyi
jcyuyi / s3-cf-ssl.yml
Last active Dec 26, 2018
AWS CloudFormation Templates: CloudFront distribution with an S3 origin and SSL for static pages
View s3-cf-ssl.yml
AWSTemplateFormatVersion: '2010-09-09'
Description: 'CloudFront distribution with an S3 origin for static pages'
Parameters:
domainName:
Description: 'Domain name for your website (example.com)'
Type: 'String'
acmCertArn:
Description: 'ACM Certification ARN (in us-east-1 region)'
Type: 'String'
@jcyuyi
jcyuyi / hugo-s3-cf-deploy.sh
Created Dec 11, 2018
Deploy Hugo to S3 with CloudFront invalidation
View hugo-s3-cf-deploy.sh
#!/usr/bin/env bash
if [[ "$#" -ne 3 ]]; then
echo "Illegal number of parameters"
echo "Usage: deploy BASE_URL S3_URL DISTRIBUTION_ID"
exit 1
fi
# Base URL
BASE_URL=$1
@jcyuyi
jcyuyi / AWSSecretsProcessor.kt
Last active Nov 28, 2018
Use AWS Secrets Manager to config secret properties in Spring using EnvironmentPostProcessor
View AWSSecretsProcessor.kt
package io.nayu.spring.secretsdemo
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder
import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest
import org.springframework.boot.SpringApplication
import org.springframework.boot.context.event.ApplicationFailedEvent
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.boot.context.event.SpringApplicationEvent