Skip to content

Instantly share code, notes, and snippets.

View akandratovich's full-sized avatar

Andrei Kandratovich akandratovich

  • Zurich, Switzerland
View GitHub Profile
package me.kondratovich.actuator.prometheus;
import static io.micrometer.core.instrument.Statistic.Count;
import static io.micrometer.core.instrument.Statistic.Total;
import static io.micrometer.core.instrument.Statistic.TotalTime;
import static io.micrometer.core.instrument.Statistic.Value;
import com.google.common.base.Objects;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
@akandratovich
akandratovich / BrandsnappeException.java
Last active December 23, 2015 13:09
ExceptionMapper
package com.os.brandsnapper.exception;
public class BrandsnappeException extends RuntimeException {
private final ErrorCode code;
private BrandsnappeException(ErrorCode err, String message) {
super(message == null ? err.getMessage() : message);
code = err;
}
...
post(new Route("zuora-callout-callback") {
@Override
public Object handle(Request request, Response response) {
logger.info("GOT IT");
for (String v : request.queryParams()) {
logger.info(v + " " + request.queryParams(v));
}
...
post(new Route("zuora-callout-callback") {
@Override
public Object handle(Request request, Response response) {
logger.info("GOT IT");
for (String v : request.queryParams()) {
logger.info(v + " " + request.queryParams(v));
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="Default" version="12">
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
...
private static BoneCPDataSource initialize() {
PropertyResourceBundle config = (PropertyResourceBundle) ResourceBundle.getBundle("bonecp");
Properties p = new Properties();
Enumeration<String> keys = config.getKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
p.setProperty(key, config.getString(key));
@akandratovich
akandratovich / gist:4555065
Last active December 11, 2015 05:49
Bistring
package com.os.cpnet.tool;
import java.util.Arrays;
import org.apache.commons.codec.binary.Base64;
public final class BitString implements Comparable<BitString> {
public static final BitString ZERO = new BitString(new long[] {});
public static final int SLOT_SIZE = 64;
"Limit (cost=19359.90..19360.02 rows=50 width=12) (actual time=35.973..36.005 rows=50 loops=1)"
" Output: a.f, a.t, a."time""
" Buffers: shared hit=5238 read=2"
" -> Sort (cost=19359.90..19360.14 rows=96 width=12) (actual time=35.935..35.947 rows=50 loops=1)"
" Output: a.f, a.t, a."time""
" Sort Key: a."time""
" Sort Method: top-N heapsort Memory: 18kB"
" Buffers: shared hit=5238 read=2"
" -> Hash Join (cost=18994.33..19356.74 rows=96 width=12) (actual time=26.953..31.508 rows=7500 loops=1)"
" Output: a.f, a.t, a."time""
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
SET search_path = public, pg_catalog;
@akandratovich
akandratovich / gist:3162849
Created July 23, 2012 09:47
fast serialization
// https://github.com/kondratovich/machariel/blob/master/src/main/java/org/machariel/core/serialization/Serializer.java#L34
private Key serializecm(Object object, int depth, ClassMap cm) {
final int size = Reflection.size(object);
final Key ref = allocator.allocate(cm, size - Reflection.MAGIC_SIZE + PTR_OFFSET); // Unsafe.allocateMemory(size)
allocator.put(ref, 0, size); // Unsafe.putInt(pointer, offset, value)
allocator.put(ref, Reflection.ARRAY_INT_INDEX_SCALE, object.getClass().hashCode()); // Unsafe.putInt(pointer, offset, value)
allocator.copy(object, Reflection.MAGIC_SIZE, ref, PTR_OFFSET, size - Reflection.MAGIC_SIZE); // Unsafe.copyMemory(...)
for (int j = 0; j < cm.refs().length; j++) { // in case we have Reference fields