Skip to content

Instantly share code, notes, and snippets.


Andy Hawkes azhawkes

View GitHub Profile
azhawkes /
Created Oct 15, 2015
Spring Boot: convert inbound parameters from snake_case to camelCase
public class SnakeCaseApplicationConfiguration {
public OncePerRequestFilter snakeCaseConverterFilter() {
return new OncePerRequestFilter() {
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 / WebConfig.groovy
Created Aug 19, 2015
Spring Boot (RestController) - support for application/octet-stream using InputStream
View WebConfig.groovy
* Adds support for application/octet-stream through a RestController using streams.
class WebConfig extends WebMvcConfigurationSupport {
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 /
Created Dec 20, 2012
Simple Java/SWT class for image sprites. Quickly slice up a larger image into smaller ones, while preserving alpha transparency. Most of the existing examples out there don't handle alphas properly.
package com.andyhawkes.gists;
import org.eclipse.swt.widgets.Display;
* Simple class that demonstrates how to slice up regions of a sprite image in SWT, while preserving
* alpha transparency. There are shorter ways to do this if you don't care about alpha transparency.
azhawkes /
Created Jan 13, 2014
Really simple wget spider to obtain a list of URLs on a website, by crawling n levels deep from a starting page.
wget -r --spider --delete-after --force-html -D "$DOMAINS" -l $DEPTH "$HOME" 2>&1 \
| grep '^--' | awk '{ print $3 }' | grep -v '\. \(css\|js\|png\|gif\|jpg\)$' | sort | uniq > $OUTPUT
View code-step-example.js
// 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
View random-led-chart.js
var columns = 200;
var ticker = document.getElementById("ticker");
for (var i = 0; i < columns; i++) {
function addTickerColumn() {
var value = Math.floor(Math.random() * 5);
var column = document.createElement("div");
azhawkes / .htaccess
Created Jan 22, 2014
Apache mod_rewrite config to treat requests for /something as /something.html behind the scenes. Using this for a static Jekyll site because I don't want the .html extensions visible to end users.
View .htaccess
RewriteEngine on
# Automatically rewrite /something -> something.html
RewriteRule /(.*)$ /$1.html [L]
# Strip off .html extensions from the request and redirect
RewriteCond %{REQUEST_URI} ^(.+)\.html$
RewriteRule /(.*)\.html$ /$1 [R=301,L]
azhawkes / .vimrc
Created Jan 15, 2014
Finally decided to fix my .vimrc and other configs
View .vimrc
" Vundle package manager
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" Vundle packages
Bundle 'gmarik/vundle'
Bundle 'maksimr/vim-jsbeautify'
Bundle 'einars/js-beautify'
azhawkes / .editorconfig
Created Jan 15, 2014
Vim configs for the JsBeautify plugin in ~/.vim/.editorconfig
View .editorconfig
; .editorconfig
root = true
indent_style = space
indent_size = 4
indent_style = space
azhawkes / gist:5009567
Last active Dec 14, 2015
Workaround to disable SWT full-screen mode on the Mac, to get around this nasty bug:
View gist:5009567
public static void disableFullScreen(Shell shell) {
try {
Field windowField = Shell.class.getDeclaredField("window");
Object window = windowField.get(shell);
invoke(window.getClass(), window, "setCollectionBehavior", new Long[] { 0L });
} catch (Exception e) {
log.error("couldn't disable full screen mode", e);