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
@thomasdarimont
thomasdarimont / format.js
Last active August 29, 2015 14:04
Nice sprintf-Style placeholder replacement in format strings (only %s supported)
function format(format, a, b, c, d, e, f){
if (format === undefined) {
return "";
}
var idx = 0;
var args = [a, b, c, d, e, f];
return format.replace(/%s/g, function() { return args[idx++]; });
package de.tutorials.training.math;
import de.tutorials.training.JavaFxUtil;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
@thomasdarimont
thomasdarimont / ReplaySourceOptionsMetadata.java
Last active August 29, 2015 14:05
replay: A prototypic XD source module definition that is able to replay pre-recorded events from a file. Allows to configure a fixed delay in milliseconds or an SpEL expression that the module waits for issuing a new event.
/*
* 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
@thomasdarimont
thomasdarimont / DynamicPmmlModelSelectionExample.java
Last active March 7, 2021 10:43
Small jpmml-evaulator demo (with a dummy model) on how to dynamically select a regression model based on an input attribute value. In this case we use the "attribute1" to select the right model.
package de.tutorials.training;
import org.dmg.pmml.FieldName;
import org.dmg.pmml.PMML;
import org.jpmml.evaluator.FieldValue;
import org.jpmml.evaluator.ModelEvaluator;
import org.jpmml.evaluator.ModelEvaluatorFactory;
import org.jpmml.manager.PMMLManager;
import org.jpmml.model.ImportFilter;
import org.jpmml.model.JAXBUtil;
package de.tutorials.training;
import java.time.LocalDateTime;
public class SnapToCurrentTimeWindowExample {
public static void main(String[] args) {
LocalDateTime ldt = LocalDateTime.of(2013,9,1,13,39,0);
System.out.println(ldt);
@thomasdarimont
thomasdarimont / XD Stream Definition.md
Last active August 29, 2015 14:05
Example for a custom groovy based XD aggregator that is able to combine multiple messages for a logical group when a "group change" is detected.

Stream definition

stream create --name simple --definition "http --outputType=application/x-xd-tuple | script --location=aggregate.groovy | filter --expression=!payload.isEmpty() | splitter | log" --deploy

Post http data

http post --target http://localhost:9000 --contentType application/json --data "{ \"ts\":1, \"house_id\":1, \"plug_id\":0, \"load\":11}"
@thomasdarimont
thomasdarimont / Redis-time-series.md
Last active August 29, 2015 14:05
Redis-time-series: key, value scheme and data structure

Scenario

In a stream processing context I want to store sensor readings over time with redis.

I have multiple sensors (~2k) that and potentially mutiple readings, e.g. value1, value2, value3 that can happen at a fixed rate for some sensor (e.g. every second) or at arbitrary points in time for other sensors.

Later I want to be able to load the time-series data, completly as well as just a slice, from redis in order to plot them, values since start with dynamic updates.

Values should be stored as key-value pairs.

require(stringr)
require(pmml)
require(RODBC)
channel <- odbcConnect("PostgreSQL35W32")
#for(houseId in 0:39){
houseId <- "*"
with
base_data as (
select
s.*
, d.day
, d.hour
, d.minute
from
smart_plug_info as s
JOIN dim_date d
copy(
with
base_data as
(
select
alm.*
, dd.day
, dd.hour
, dd.minute
from