Skip to content

Instantly share code, notes, and snippets.

Avatar

Jon McEwen jonmcewen

  • Naimuri
  • Manchester, UK
View GitHub Profile
View avro serdes
private static <T extends SpecificRecord> T getSpecificRecord(
String json, Schema writersSchema, Class<T> recordClass)
throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Schema readersSchema = (Schema) recordClass.getMethod("getClassSchema").invoke(null);
Decoder jsonDecoder = DecoderFactory.get().jsonDecoder(writersSchema, json);
ResolvingDecoder resolvingDecoder = DecoderFactory.get().resolvingDecoder(writersSchema, readersSchema, jsonDecoder);
DatumReader<T> reader = new SpecificDatumReader<>(recordClass);
return reader.read(null, resolvingDecoder);
}
View gist:1bf7751f3f7ba25442e6d7414a9dc3ad
set -e
for dir in ../*
do
echo
echo "=============="
echo "$dir"
echo "=============="
git --git-dir=$dir/.git --work-tree=$PWD/$dir checkout master
git --git-dir=$dir/.git --work-tree=$PWD/$dir pull
git --git-dir=$dir/.git --work-tree=$PWD/$dir status -s
@jonmcewen
jonmcewen / DropwizardToMicrometerBridge.java
Last active Aug 7, 2019
Hacky bridge to grab dropwizard metrics and stick them into a micrometer registry. Add as a spring-boot Bean
View DropwizardToMicrometerBridge.java
package com.boohoo.esbdefused.metrics;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
View Java DateTimeFormatter to parse varying number of decimal places
private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss")
.appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true).appendPattern("X").toFormatter();
@jonmcewen
jonmcewen / springboot-camel-jms-jdbc-tx.java
Created Dec 16, 2015
Config for ChainedTransactionManager with Camel, JMS, JDBC
View springboot-camel-jms-jdbc-tx.java
import javax.jms.ConnectionFactory;
import javax.sql.DataSource;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.RedeliveryPolicy;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.activemq.pool.PooledConnectionFactory;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spring.spi.SpringTransactionPolicy;
import org.springframework.boot.SpringApplication;
@jonmcewen
jonmcewen / cucumber-jvm-signed-integer-pattern.java
Created Nov 18, 2015
Example of a CucumberJVM step pattern for capturing a positive or negative number
View cucumber-jvm-signed-integer-pattern.java
@When("^an Adjustment of \\+?(-?\\d+) is received$")
public void an_Adjustment_of_x_is_received(int qty) throws Throwable {
//send "qty" as input
}
@jonmcewen
jonmcewen / springboot.py
Created Sep 25, 2015
nagios plugin for spring-boot app status
View springboot.py
#!/usr/bin/env python
import requests, sys, getopt
try:
opts, args = getopt.getopt(sys.argv[1:], "p:", ["port="])
except getopt.GetoptError:
print('springboot.py -p <port>')
sys.exit(2)
View Spring-boot-start-script.sh
#!/bin/sh
cd "`dirname "$0"`"
jmxOpts="-Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.password.file=config/jmxremote.password"
nohup java $jmxOpts -Djava.security.egd=file:/dev/./urandom -jar my-app-1.0.0.jar 1>/dev/null 2>stderr.log &
View gist:60f8576e192a9ff11d24
import static com.codahale.metrics.MetricRegistry.name;
import java.lang.management.ManagementFactory;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.management.AttributeNotFoundException;
@jonmcewen
jonmcewen / gist:5270359
Last active Dec 15, 2015
frisby/jasmine-node problem
View gist:5270359
When I run:
$ jasmine-node --verbose .
I get absolutely no output.
Same with:
$ jasmine-node --verbose frisby.spec.js