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 / 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
@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 / 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 / Dropwizard DockerFile minimal
Created February 6, 2015 09:06
Dropwizard DockerFile minimal, less than 200mb
errordeveloper/oracle-jre
WORKDIR /app/
ADD app-config.yml /app/
ADD build/app.jar /app/
# port and run
EXPOSE 9090
ENTRYPOINT [ "java" ]
CMD [ "-jar", "app.jar", "server", "app-config.yml" ]
@Singleton
@javax.ws.rs.ext.Provider
public class NewRelicTimedApplicationListener implements ApplicationEventListener {
private Map<Method,String> methodMap = new HashMap<>();
@Override
public void onEvent(ApplicationEvent event) {
if (event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) {
for (Resource resource : event.getResourceModel().getResources()) {
@mrserverless
mrserverless / MultiTenantDataSource
Last active February 17, 2017 09:52
Dropwizard MultiTenant DataSource using RequestScope injected Schema object
public class MultiTenantDataSource implements ManagedDataSource {
private final ManagedDataSource managedDataSource;
private final SchemaResolver schemaResolver;
public MultiTenantDataSource( final ManagedDataSource managedDataSource, final SchemaResolver schemaResolver )
{
this.managedDataSource = managedDataSource;
this.schemaResolver = schemaResolver;
}
@mrserverless
mrserverless / build.gradle
Created December 22, 2014 00:15
Gradle maven publish replace default runtime scope with compile scope. See: http://forums.gradle.org/gradle/topics/using_the_maven_publish_plugin_no_dependencies_in_pom_xml
publishing {
publications {
mavenJava(MavenPublication) {
pom.withXml {
asNode().dependencies.'*'.findAll() {
it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
dep.name == it.artifactId.text()
}
}.each() {
it.scope*.value = 'compile'
@mrserverless
mrserverless / Configuration.java
Last active March 14, 2019 12:08
Dropwizard serving Static Assets on Root URL "/" and APIs on "/api/"
public class ApplicationConfiguration extends Configuration implements AssetsBundleConfiguration {
@Valid
@NotNull
@JsonProperty
private AssetsConfiguration assets;
@Override
public AssetsConfiguration getAssets() {
return assets;
}
@mrserverless
mrserverless / DropwizardGovernatorApplication.java
Last active February 17, 2017 09:53
Using Governator with Dropwizard-Guice, pending pull request https://github.com/HubSpot/dropwizard-guice/pull/39/
@Override
public void initialize( final Bootstrap<PlatformConfiguration> bootstrap ) {
final GuiceBundle<PlatformConfiguration> guiceBundle = GuiceBundle.<PlatformConfiguration>newBuilder()
.addModule( new PlatformModule() )
.enableAutoConfig( "com.apmasphere.platform.resources", "com.apmasphere.platform.health" )
.setConfigClass( PlatformConfiguration.class )
.setInjectorFactory( new GovernatorInjectorFactory() )
.build();
bootstrap.addBundle( guiceBundle );
}
// Bridge all Guice injection from AppServletContextListener
GuiceBridge.getGuiceBridge().initializeGuiceBridge( serviceLocator );
GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService( GuiceIntoHK2Bridge.class );
guiceBridge.bridgeGuiceInjector( injector );