Skip to content

Instantly share code, notes, and snippets.

View mrserverless's full-sized avatar
🌆
Building a Metaverse

Yun Zhi Lin mrserverless

🌆
Building a Metaverse
View GitHub Profile
@mrserverless
mrserverless / newrelic.gradle
Created February 8, 2015 23:58
newrelic gradle task
configurations {
newrelic
}
dependencies {
newrelic "com.newrelic.agent.java:newrelic-agent:${newrelicVersion}"
}
task newrelicJar(type: Copy) {
from {
@mrserverless
mrserverless / env_config.gradle
Last active November 10, 2017 22:40
yaml config replacement gradle, an easier way would be to use https://github.com/tkrille/dropwizard-template-config
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
apply plugin: 'groovy'
buildscript {
repositories {
jcenter()
}
dependencies {
@mrserverless
mrserverless / Cache-Buster-Dockerfile
Last active August 13, 2016 19:29
Quay.IO Cache Buster when triggering a github Dockerfile build
FROM busybox
# any thing after here will not be cached
# since Quay.IO check out will results in a different timestamp to the cache
ADD .git/HEAD /app/CACHE_BUSTER
RUN rm CACHE_BUSTER
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.LocalDate;
import java.time.LocalDateTime;
public class Dummy {
@JsonProperty
public LocalDate localDate;
@JsonProperty
@mrserverless
mrserverless / CORSContainerResponseFilter.java
Last active October 5, 2022 20:47
Jersey ContainerResponseFilter example of CORS Filter. The Jetty version is more comprehensive: https://gist.github.com/yunspace/07d80a9ac32901f1e149
import javax.inject.Singleton;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
@Singleton
@Provider
@mrserverless
mrserverless / DropwizardJettyCrossOriginIntegrationTest.java
Last active January 19, 2018 22:09
Dropwizard 0.8.0 and 0.9.0 Jetty CORS Filter with Unit Tests. To prove this works once and for all
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.setup.Environment;
import io.dropwizard.testing.junit.DropwizardAppRule;
import org.assertj.core.data.MapEntry;
import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.junit.ClassRule;
import org.junit.Test;
@mrserverless
mrserverless / Resource.java
Created June 17, 2015 10:45
Dropwizard @UnitOfWork with Manual Transactions
@GET
@Path("/update")
@UnitOfWork(transactional = false)
public World update(World world) {
return transactionDao.updatesWorld(world);
}
@mrserverless
mrserverless / SSLJerseyClient.java
Last active February 17, 2017 09:46
Dropwizard JerseyClient loading JKS certificate into SSL TrustStore at runtime
private TrustManager[] loadTrustManagers(String certificateFile) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
KeyStore trustedCertStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustedCertStore.load(SecurityModule.class.getClassLoader().getResourceAsStream(), null);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(trustedCertStore);
return tmf.getTrustManagers();
}
@mrserverless
mrserverless / docker-compose.yml
Last active March 1, 2017 09:56
Tutum HAProxy sample Stackfile for Virtual Host + SSL setup
hello:
image: 'tutum/hello-world:latest'
environment:
- FORCE_SSL=yes
- 'VIRTUAL_HOST=http://hello.example.com, https://hello.example.com'
ports:
- '80'
web:
image: 'example/web-site:latest'
environment:
@mrserverless
mrserverless / TypeInferenceGenericGuiceFactory.java
Last active August 29, 2015 14:27
Generic Guice Factory with Type Inference
install(new FactoryModuleBuilder().build(PayloadServiceFactory.class));
public interface GenericPayloadFactory {
PayloadService<? extends Payload> create();
}
public interface Payload {}
public class JsonPayload implements Payload {}
public class XmlPayload implements Payload {}