Skip to content

Instantly share code, notes, and snippets.

View jmnarloch's full-sized avatar

Jakub Narloch jmnarloch

View GitHub Profile
@jmnarloch
jmnarloch / Node Http File Server
Last active December 10, 2015 10:28
Node based simple Http Server for serviing static files.
#!/usr/bin/env node
var path = require('path');
var fs = require('fs');
var optimist = require('optimist');
var argv = optimist.usage('$0 --dir [base_directory] --port [port]')
.default({ dir: '.', port: 8080 })
.argv;
if (argv.help) {
/**
* Copyright (c) 2015 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@jmnarloch
jmnarloch / gist:fc1aa7fa303cb983e6c0
Created July 7, 2015 21:41
Spring Cloud Eureka register
2015-07-07 23:33:55.528 INFO 18690 --- [pool-7-thread-1] o.s.boot.SpringApplication : Starting application on MacBook-Pro-Jakub.local with PID 18690 (/Users/jakubnarloch/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot/1.2.5.RELEASE/d12969adffe18f6f778451b1a8d1dab485ab4a03/spring-boot-1.2.5.RELEASE.jar started by jakubnarloch in /Users/jakubnarloch/workspace/github/jmnarloch/spring-boot-microservices)
2015-07-07 23:33:55.533 INFO 18690 --- [pool-7-thread-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5014c19b: startup date [Tue Jul 07 23:33:55 CEST 2015]; root of context hierarchy
2015-07-07 23:33:55.562 INFO 18690 --- [pool-7-thread-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2015-07-07 23:33:55.573 INFO 18690 --- [pool-7-thread-1] trationDelegate$BeanPostProcessorChecker : Bean 'encrypt.CONFIGURATION_PROPERT
@jmnarloch
jmnarloch / .editorconfig
Last active August 29, 2015 14:24
.editorconfig
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# Change these settings to your own preference
indent_style = space
@jmnarloch
jmnarloch / .gitattributes
Last active August 29, 2015 14:24
.gitattributes
# All text files should have the "lf" (Unix) line endings
* text eol=lf
*.bat text eol=crlf
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.java text
*.js text
*.css text
*.html text
@jmnarloch
jmnarloch / Guardfile
Created July 17, 2015 21:51
Guardfile
require 'asciidoctor'
require 'erb'
options = {:to_dir => 'docs/dist/', :safe => 'safe', :mkdirs => true}
guard 'shell', :all_on_start => true do
watch(/^docs\/src\/main\/adoc\/.*\.adoc$/) {|m|
Asciidoctor.render_file(m[0], options)
}
end
@jmnarloch
jmnarloch / gist:a6f13d2a2e72b6ec42aa
Created July 20, 2015 12:08
Eureka NullPointerException
java.lang.NullPointerException: null
at com.netflix.eureka.resources.StatusResource.isReplicaAvailable(StatusResource.java:90)
at com.netflix.eureka.resources.StatusResource.getStatusInfo(StatusResource.java:70)
at org.springframework.cloud.netflix.eureka.server.EurekaController.status(EurekaController.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
@jmnarloch
jmnarloch / gist:2272daa872f6945f1f13
Created August 22, 2015 16:56
Enabling HTTP2 in Undertow
@Bean
UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {
UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory();
factory.addBuilderCustomizers(
builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true));
return factory;
}
@jmnarloch
jmnarloch / EurekaHealthCheckHandler
Last active September 2, 2015 18:05
Propagating the application health status to Eureka
public class EurekaHealthCheckHandler implements HealthCheckHandler, ApplicationContextAware, InitializingBean {
private static final Map<Status, InstanceInfo.InstanceStatus> healthStatuses = new HashMap<Status, InstanceInfo.InstanceStatus>() {{
put(Status.UNKNOWN, InstanceInfo.InstanceStatus.UNKNOWN);
put(Status.OUT_OF_SERVICE, InstanceInfo.InstanceStatus.OUT_OF_SERVICE);
put(Status.DOWN, InstanceInfo.InstanceStatus.DOWN);
put(Status.UP, InstanceInfo.InstanceStatus.UP);
}};
private final CompositeHealthIndicator healthIndicator;
public class AcceptGzipEncodingFeignRequestInterceptor implements RequestInterceptor {
private static final String ACCEPT_ENCODING_HEADER = "Accept-Encoding";
private static final String GZIP_ENCODING = "gzip";
private static final String DEFLATE_ENCODING = "deflate";
@Override
public void apply(RequestTemplate template) {