Skip to content

Instantly share code, notes, and snippets.

View jonmcewen's full-sized avatar

Jon McEwen jonmcewen

  • Naimuri
  • Manchester, UK
View GitHub Profile
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);
}
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 September 30, 2024 10:58
Hacky bridge to grab dropwizard metrics and stick them into a micrometer registry. Add as a spring-boot Bean
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;
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 December 16, 2015 13:44
Config for ChainedTransactionManager with Camel, JMS, JDBC
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 November 18, 2015 14:14
Example of a CucumberJVM step pattern for capturing a positive or negative number
@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 September 25, 2015 08:51
nagios plugin for spring-boot app status
#!/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)
#!/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 &
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 December 15, 2015 13:49
frisby/jasmine-node problem
When I run:
$ jasmine-node --verbose .
I get absolutely no output.
Same with:
$ jasmine-node --verbose frisby.spec.js