Skip to content

Instantly share code, notes, and snippets.

View nickman's full-sized avatar

Nicholas Whitehead nickman

View GitHub Profile
@nickman
nickman / AttributeValueSerializer.java
Last active March 1, 2024 04:14
Jackson JSON serializer for the DynamoDB V2 SDK's AttributeValue
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import software.amazon.awssdk.core.SdkBytes;
@nickman
nickman / FileUploadReplayingDecoder.java
Created August 28, 2018 18:45
ReplayingDecoder to read a sequence of uploaded files
/**
*
*/
package net.example;
import java.nio.charset.Charset;
import java.util.List;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
@nickman
nickman / AnnotationBuilder.java
Created March 16, 2018 11:41
Example of adding annotations at runtime
package com.heliosapm.aop.retransformer;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
@nickman
nickman / IntArrayCodec.java
Created September 3, 2017 21:57
Netty Int Array Codec
import java.util.Arrays;
import java.util.Random;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
public class IntArrayCodec {
static final int MAP_WIDTH = 10;
static final int MAP_HEIGHT = 10;
static final Random RANDOM = new Random(System.currentTimeMillis());
@nickman
nickman / app.html
Created June 3, 2016 19:47 — forked from bellbind/app.html
[electron]Use electron as a Web Server
<!doctype html>
<html><head><script src="app.js"></script></head><body></body></html>
/**
* Modifies the pipeline to handle HTTP requests
* @param ctx The calling channel handler context
* @param maxRequestSize The maximum request size in bytes
*/
private void switchToHttp(final ChannelHandlerContext ctx, final int maxRequestSize) {
ChannelPipeline p = ctx.pipeline();
p.addLast("compressor", new HttpContentCompressor());
p.addLast("httpHandler", new HttpServerCodec()); // TODO: config ?
p.addLast("decompressor", new HttpContentDecompressor());
final DefaultFileRegion region = new DefaultFileRegion(file.getChannel(), 0, length);
final ByteBuf fb = ctx().alloc().directBuffer((int)length);
region.transferTo(new WritableByteChannel(){
@Override
public boolean isOpen() {
return true;
}
@Override
public void close() throws IOException { /* No Op */}
@Override
@nickman
nickman / properCase.groovy
Created December 23, 2015 17:09
Groovy to proper case underscore containing strings (i.e. DB column names) to convert to reasonable java/groovy field names
int US = '_';
uinds = { name ->
int index = 1;
int offset = 0;
int loops = 0;
uids = [];
while(index!=-1) {
index = name.indexOf(US, offset);
hbase.region.namespace_default_table_tsdb-meta_region_2081c4861498f0bc22df9ffa0c66c2c0_metric_appendCount
hbase.region.namespace_default_table_tsdb-meta_region_2081c4861498f0bc22df9ffa0c66c2c0_metric_compactionsCompletedCount
hbase.region.namespace_default_table_tsdb-meta_region_2081c4861498f0bc22df9ffa0c66c2c0_metric_deleteCount
hbase.region.namespace_default_table_tsdb-meta_region_2081c4861498f0bc22df9ffa0c66c2c0_metric_get_75th_percentile
hbase.region.namespace_default_table_tsdb-meta_region_2081c4861498f0bc22df9ffa0c66c2c0_metric_get_95th_percentile
hbase.region.namespace_default_table_tsdb-meta_region_2081c4861498f0bc22df9ffa0c66c2c0_metric_get_99th_percentile
hbase.region.namespace_default_table_tsdb-meta_region_2081c4861498f0bc22df9ffa0c66c2c0_metric_get_max
hbase.region.namespace_default_table_tsdb-meta_region_2081c4861498f0bc22df9ffa0c66c2c0_metric_get_mean
hbase.region.namespace_default_table_tsdb-meta_region_2081c4861498f0bc22df9ffa0c66c2c0_metric_get_median
hbase.region.namespace_default_table_tsd
2015-03-15 16:51:26,848 INFO  [main] Main: Built on 2015/03/08 20:49:56 +0000 by nwhitehead@tpmint:/home/nwhitehead/hprojects/opentsdb

tsd extended usage:
  --async-io=BOOL             Whether or not to use NIO or tradditional blocking IO
  --auto-metric=BOOL          Whether or not a data point with a new metric will assign a UID to the metric. When false, a data point with a metric that is not in the database will be rejected and an exception will be thrown
  --auto-tagk=BOOL            Whether or not a data point with a new tag name will assign a UID to the tagk. When false, a data point with a tag name that is not in the database will be rejected and an exception will be thrown
  --auto-tagv=BOOL            Whether or not a data point with a new tag value will assign a UID to the tagv. When false, a data point with a tag value that is not in the database will be rejected and an exception will be thrown
  --backlog=GTZEROINT         The connection queue depth for completed or incomplete connection req