Skip to content

Instantly share code, notes, and snippets.

View vicly's full-sized avatar

Vic vicly

  • Auckland, New Zealand
View GitHub Profile
@vicly
vicly / AbstractMaskPredicate.java
Last active June 27, 2018 02:48
[Change log message in Dropwizard] #Java #Dropwizard
import java.util.function.Predicate;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.spi.DeferredProcessingAware;
class AbstractMaskPredicate<E extends DeferredProcessingAware>
implements Predicate<E>
{
@Override
@vicly
vicly / hibernate_savetypemethods.md
Created June 6, 2018 03:35
[Hibernate save,saveOrUpdate,persist,update,merge] #JPA

save()

  • can be called outside a trasnaction (not good), but should AVOID this, otherwise mapped entities will not be saved which causes data inconsistency.(only the primary entity gets saved unless we flush the session)
  • primary object is saved ASAP, the mapped object will be saved when committing transaction or flush the session
  • if object is in persist state, when calling save(), trigger SQL UPDATE, otherwise SQL INSERT
  • e.g. start a tran; read a obj, modify obj, save(obj), commit tran;
  • load object to persistent context, further change will be tracked and saved when transaction is committed

persist()

  • similar to save()
@vicly
vicly / aws_basic_concept.md
Last active November 10, 2020 04:50
[AWS basic concept] #AWS

Basic Concept

127.0.0.1 vs 0.0.0.0

127.0.0.1 is the loopback Internet protocol (IP) address also referred to as the localhost. The address is used to establish an IP connection to the same machine or computer being used by the end-user.

0.0.0.0 is a special IP which is "no particular address" (invalid/unknown/not-applicable).

0.0.0.0/0 : all IPs

public class Product {
  @Id
  private String id;

  @Column(name = "name", nullable = false)
  private String name;

 @ElementCollection(fetch = FetchType.LAZY) // 
@vicly
vicly / linux_replace_string.sh
Created November 30, 2017 22:27
[Replace string using Linux command] #Shell
# OPS_PASSWORD are environment variables, need to export before running this command
# $ENV.json is a template, and OPS_PASSWORD as ${OPS_PASSWORD}
# parameters.json is the command output
envsubst '${OPS_PASSWORD},${DCS_PASSWORD},${SSM_PASSWORD},${SVOF_PASSWORD}' < $ENV.json > parameters.json
@vicly
vicly / AbstractClientTest.java
Last active November 22, 2017 02:37
[Test API Client with Mock Server] #REST #Test
// testCompile "junit:junit:4.12"
// testCompile "org.assertj:assertj-core:3.5.2"
// testCompile "com.github.tomakehurst:wiremock-standalone:2.7.1"
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.delete;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.put;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
@vicly
vicly / aws_kinesis_code_snippet.md
Created October 15, 2017 20:08
[AWS Kinesis code snippet] #AWS

Create client

  private static AmazonKinesis setupKinesisClient()
  {
    AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain();

    ClientConfiguration kinesisConfig = new ClientConfiguration();
    kinesisConfig.setMaxConnections(1);
 kinesisConfig.setProtocol(Protocol.HTTPS);
@vicly
vicly / aws_cloudwatch_to_lambda.md
Last active July 15, 2018 05:01
[AWS Lambda handles CloudWatch log event] #AWS
  1. Lambda stack exports lambda ARN
  2. App stack defines log group
  3. App stack defines subscription to the log group for lambda

So, by design, many app stacks share the same lambda stack to handle log events.

Stack

App Stack LogGroup

@vicly
vicly / oauth_jwt_token.md
Last active December 16, 2018 19:55
[OpenId OAuth2 JWT] #OAuth #JWT

ID Token

  • a JWT contains user profile information, e.g. user’s name, email, etc, represented in claims.

Access Token

  • a credential used by an application to access a protected resource, e.g. API
  • sent from client to server, server use information in the token to decide whether the client is authorised or not
  • token has expired time
  • must also be kept secret, but due to its shorter life, security considerations are less critical
@vicly
vicly / jpa_query_elementcollection_field.java
Created September 28, 2017 00:08
[JPA query using ElementCollection field] #JPA
@Entity
@Table(name = "product")
public class Product
{
@Id
private String id;
@Column(name = "visible")
private boolean visible;