Skip to content

Instantly share code, notes, and snippets.

View azhawkes's full-sized avatar

Andy Hawkes azhawkes

View GitHub Profile
@azhawkes
azhawkes / WebConfig.groovy
Created August 19, 2015 17:26
Spring Boot (RestController) - support for application/octet-stream using InputStream
/**
* Adds support for application/octet-stream through a RestController using streams.
*/
@Configuration
class WebConfig extends WebMvcConfigurationSupport {
@Override
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new AbstractHttpMessageConverter<InputStream>(MediaType.APPLICATION_OCTET_STREAM) {
protected boolean supports(Class<?> clazz) {
return InputStream.isAssignableFrom(clazz)
@azhawkes
azhawkes / SnakeCaseApplicationConfiguration.java
Created October 15, 2015 15:32
Spring Boot: convert inbound parameters from snake_case to camelCase
@Configuration
public class SnakeCaseApplicationConfiguration {
@Bean
public OncePerRequestFilter snakeCaseConverterFilter() {
return new OncePerRequestFilter() {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
final Map<String, String[]> parameters = new ConcurrentHashMap<>();
for (String param : request.getParameterMap().keySet()) {
@azhawkes
azhawkes / random-led-chart.js
Created December 7, 2017 20:39
Fun random LED chart
var columns = 200;
var ticker = document.getElementById("ticker");
for (var i = 0; i < columns; i++) {
addTickerColumn();
}
function addTickerColumn() {
var value = Math.floor(Math.random() * 5);
var column = document.createElement("div");
// This is a contrived example of some of the things you can do in a Loadster code step.
// HTTP and Wait methods are synchronous by design, no callbacks required.
// More documentation is coming soon!
console.log("We're in a code step.");
// Wait between 0 and 2 seconds
user.wait(Math.random() * 2000);
// Make a GET request with page resources