Skip to content

Instantly share code, notes, and snippets.

@bbejeck
bbejeck / PartiallyAppliedFunctionsTest.java
Created Jul 17, 2015
Source code from "Partially Applied Functions in Java" post.
View PartiallyAppliedFunctionsTest.java
package bbejeck.function;
import org.junit.Test;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
@bbejeck
bbejeck / MonitorExample.java
Created Nov 16, 2011
Sample Code for Guava Monitor Blog
View MonitorExample.java
import com.google.common.util.concurrent.Monitor;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Created by IntelliJ IDEA.
* User: bbejeck
* Date: 11/11/11
* Time: 10:01 PM
*/
@bbejeck
bbejeck / backup_config.sh
Created Dec 7, 2011
Source for Simple WordPress backups Blog
View backup_config.sh
#! /bin/sh
BLOG=blog_backup
BASE_DIR=/home/<username>/webapps/wp
USER=remote_username
PASS=database_password
DBUSER=database_user
DATABASE=database_name
DEST_DIR=destination_dir
IP_ADDRESS=blog_ip_address
@bbejeck
bbejeck / LambdaGuavaTest.java
Created Dec 23, 2011
Source for Guava Functions and Java 8 Lambdas
View LambdaGuavaTest.java
import bbejeck.guava.futures.SearchingTestBase;
import bbejeck.support.model.Person;
import com.google.common.base.Function;
import com.google.common.util.concurrent.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.lang.SuppressWarnings;
import java.util.List;
@bbejeck
bbejeck / tmux-kafka.sh
Created Dec 11, 2015
A script for using tmux with kafka
View tmux-kafka.sh
#!/bin/sh
KAFKA_DIR=/usr/local/kafka_2.11-0.9.0.0-SNAPSHOT
START_ZK="./bin/zookeeper-server-start.sh"
ZK_PROPS="config/zookeeper.properties"
START_KAFKA="./bin/kafka-server-start.sh"
KAFKA_PROPS="config/server.properties"
@bbejeck
bbejeck / ListenableFuturesTest.java
Created Nov 23, 2011
Unit test/sample code for ListneableFutures blog
View ListenableFuturesTest.java
import com.google.common.util.concurrent.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
@bbejeck
bbejeck / dataByAirportStream.java
Created Sep 15, 2017
Kafka Streams Topology for online predictions
View dataByAirportStream.java
dataByAirportStream.join(regressionsByAirPortTable,(k, v) -> k, DataRegression::new)
.mapValues(Predictor::predict)
.filter((k, v) -> v != null)
.peek((k, v) -> System.out.println("Prediction " + v))
.to("predictions");
@bbejeck
bbejeck / buildingKStreamAndGlobalKTable.java
Created Sep 15, 2017
Builds The KStream and GlobalKTable
View buildingKStreamAndGlobalKTable.java
// configuration and Serde creation left out for clarity
KStream<String, String> dataByAirportStream = builder.stream("raw-airline-data");
GlobalKTable<String, byte[]> regressionsByAirPortTable = builder.globalTable(Serdes.String(),
byteArraySerde,
"onlineRegression-by-airport");
// stream reads raw data joins with coefficients then makes prediction
dataByAirportStream.join(regressionsByAirPortTable,
(k, v) -> k,
DataRegression::new)
@bbejeck
bbejeck / predictionPredictMethod.java
Last active Sep 15, 2017
Showing the Prediction Process
View predictionPredictMethod.java
public static String predict(DataRegression dataRegression) {
try (OnlineLogisticRegression logisticRegression = new OnlineLogisticRegression()) {
FlightData flightData = new FlightData(dataRegression.data);
logisticRegression.readFields(new DataInputStream(new ByteArrayInputStream(dataRegression.coefficients)));
double prediction = logisticRegression.classifyScalar(flightData.vector);
String arrivalPrediction = prediction > 0.5 ? "on-time" : "late";
return String.format("%s predicted to be %s", new Flight(dataRegression.data), arrivalPrediction);
} catch (Exception e) {
LOG.error("Problems with predicting " + dataRegression.data, e);
return null;
@bbejeck
bbejeck / punctuateMethodForProcessor.java
Last active Oct 18, 2017
Updating the Prediction Model
View punctuateMethodForProcessor.java
// process call left out for clarity; it places airline data
// in a list, storing in state store by airport code
@Override
public void punctuate(long timestamp) {
KeyValueIterator<String, List<String>> allFlights = flights.all();
while (allFlights.hasNext()) {
KeyValue<String, List<String>> kv = allFlights.next();
List<String> flightList = kv.value;
String key = kv.key;
if(flightList.size() >= 100) {
You can’t perform that action at this time.