Skip to content

Instantly share code, notes, and snippets.

View thomasdarimont's full-sized avatar
🏠
Working from home

Thomas Darimont thomasdarimont

🏠
Working from home
View GitHub Profile
/*
* Copyright 2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright 2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
java.lang.AssertionError: Redefined superclass:
[BasicQuery queryObject=com.mongodb.DBObject$$EnhancerByCGLIB$$5ceafab3@166fa74d fieldsObject=com.mongodb.DBObject$$EnhancerByCGLIB$$5ceafab3@166fa74d sortObject=com.mongodb.DBObject$$EnhancerByCGLIB$$5ceafab3@166fa74d RESTRICTED_TYPES_KEY=_$RESTRICTED_TYPES restrictedTypes=[red] criteria={red_key=red_value} fieldSpec=org.springframework.data.mongodb.core.query.Field@d1da1b74 sort=red skip=1 limit=1 hint=one meta=org.springframework.data.mongodb.core.query.Meta@1585e9f2]-throws AbstractMethodError(com.mongodb.DBObject$$EnhancerByCGLIB$$5ceafab3.keySet()Ljava/util/Set;)
should not equal superclass instance
[Query RESTRICTED_TYPES_KEY=_$RESTRICTED_TYPES restrictedTypes=[red] criteria={red_key=red_value} fieldSpec=org.springframework.data.mongodb.core.query.Field@d1da1b74 sort=red skip=1 limit=1 hint=one meta=org.springframework.data.mongodb.core.query.Meta@1585e9f2]-throws ClassCastException(java.lang.String cannot be cast to org.springframework.data.mongodb.c
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class Test {
public interface TestService{
public class MysteryBox {
private long x0, x1;
private boolean y0, y1, y2, y3;
private int z0;
private double[] a = new double[8];
}
@thomasdarimont
thomasdarimont / gist:227f40929e1c5930b063
Created November 26, 2014 09:26
Node.JS with Spring Boot
To throw in my two cents, if you can install node, then Spring Boot also provides super simple support for doing that:
$ mkdir -p src/main/resources/static
$ cd src/main/resources/static
$ npm init (then answer a few questions)
$ npm install --save requirejs
$ npm install --save jquery-steps
From there, the modules are already available as well via Spring Boot's prebuilt paths.
package test.test;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.GeoSpatialIndexType;
import org.springframework.data.mongodb.core.index.GeoSpatialIndexed;
import org.springframework.data.mongodb.core.mapping.Document;
@Document
public class Shoreline {
@thomasdarimont
thomasdarimont / 100_redis_stats.md
Last active November 16, 2020 06:31
Example for computing various running statistics with Lua in Redis backed by a hash

Update

An updated example can be found here: https://gist.github.com/thomasdarimont/852ba9d79a9e7cfa0be2

Hash Structure

The hash structure for statistics for key "stats_value" via redis which stores various statistics. Note: If you need a specific alpha value for smoothing the average, then set the desired alpha -> e.g. alpha 0.7. If alpha is 0.0 then no smoothing is applied.

HMSET stats_value 
@thomasdarimont
thomasdarimont / 100_redis_median_approx.md
Last active July 28, 2019 13:38
PoC for approximating the median of a Stream via stochastic averaging in Redis with Lua

Approximating the median of a Stream via stochastic averaging

Often it is useful to have access to the median value for fields of a data stream since they are more robust with respect to outliers. The median is defined as the value of a dataset such that, when sorted, 50% of the data is smaller than the value and 50% of the data is larger then the value. Ordinarily this is difficult to calculate on a stream because it requires the collection and sorting of all data.

The median of a data stream can be approximated with a technique called stochastic averaging. To approximate the median value of a data stream one could use the following approach:

Given the current estimate of the median M. If the next observed value in the stream is larger than M, increase the current estimate by r (= the learning rate). If it is smaller, decrease the estimate by r. When M is close to the median, it increases as often as it decreases, and therefore it stabilizes.

This approach was taken from the book "Real-time Analytics -

@thomasdarimont
thomasdarimont / Redis_Stats.md
Last active January 31, 2023 17:27
Example for computing various running statistics with Lua in Redis backed by a hash

Running statistics with Redis and Lua

This is an example for computing running statistics with Lua backed by a hash in Redis. We support counting, average (with and without exponential smoothing), stddev, variance, min, max, sum of observed values. An example for approximating a running median can be found here: https://gist.github.com/thomasdarimont/fff68191d45a001b2d84

Data structure

We use a hash for storing various statistic value under the key "stats_value" in redis. Note: If you need a specific alpha value for smoothing the average, then set the desired alpha -> e.g. alpha 0.7. If alpha is 0.0 then no smoothing is applied.