Skip to content

Instantly share code, notes, and snippets.

View songyunlu's full-sized avatar

Jimmy Lu songyunlu

View GitHub Profile
@songyunlu
songyunlu / ConfigServerApp.java
Created January 8, 2015 03:14
main class of config server.
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApp {
@Bean
public EnvironmentRepository repository() {
return new CassandraEnvironmentRepository();
//return new ZooKeeperEnvironmentRepository();
}
@SpringBootApplication
@EnableEurekaServer
public class ServiceRegistryApp {
public static void main(String[] args) {
SpringApplication.run(ServiceRegistryApp.class, args);
}
}
@SpringBootApplication
@EnableDiscoveryClient
public class DiscoveryClientApp {
public static void main(String[] args) {
SpringApplication.run(DiscoveryClientApp.class, args);
}
}
@songyunlu
songyunlu / RefactoringFeatureEnvy.java
Created March 9, 2016 06:37
Refactoring of the code of Feature Envy
public class HourlyPayCalculator {
private int tenthRate;
private int tenthsWorked;
private HourlyPayCalculator(CalculatorBuilder builder) {
this.tenthRate = builder.tenthRate;
this.tenthsWorked = builder.tenthsWorked;
}
public class MyProcessor extends Processor<String, String> {
private ProcessorContext context;
private KeyValueStore<String, Long> kvStore;
@Override
@SuppressWarnings("unchecked")
public void init(ProcessorContext context) {
// keep the processor context locally because we need it in punctuate() and commit()
this.context = context;
TopologyBuilder builder = new TopologyBuilder();
builder.addSource("SOURCE", "src-topic")
.addProcessor("PROCESS1", () -> new MyProcessor1(), "SOURCE")
.addProcessor("PROCESS2", () -> new MyProcessor2(), "PROCESS1")
.addProcessor("PROCESS3", () -> new MyProcessor3(), "PROCESS1")
.addSink("SINK1", "sink-topic1", "PROCESS1")
.addSink("SINK2", "sink-topic2", "PROCESS2")
.addSink("SINK3", "sink-topic3", "PROCESS3");
KStream<String, String> source = builder.stream("streams-file-input");
KTable<String, Long> counts = source
.flatMapValues(new ValueMapper<String, Iterable<String>>() {
@Override
public Iterable<String> apply(String value) {
return Arrays.asList(value.toLowerCase(Locale.getDefault()).split(" "));
}
}).map(new KeyValueMapper<String, String, KeyValue<String, String>>() {
@Override
import org.apache.kafka.streams.kstream.KStreamBuilder;
import org.apache.kafka.streams.kstream.KStream;
import org.apache.kafka.streams.kstream.KTable;
KStreamBuilder builder = new KStreamBuilder();
// Create a stream of page view events from the PageViews topic, where the key of
// a record is assumed to be the user id (String) and the value an Avro GenericRecord
// that represents the full details of the page view event.
KStream<String, GenericRecord> pageViews = builder.stream("PageViews");
@songyunlu
songyunlu / .zshrc
Created September 13, 2017 06:59
My .zshrc
umask 022
export ZGEN_RESET_ON_CHANGE=(/home/jimmy/.zshrc)
# load zgen
source "/home/jimmy/.zgen/zgen.zsh"
# if the init scipt doesn't exist
if ! zgen saved; then
echo "Creating a zgen save"
@songyunlu
songyunlu / .vimrc
Created September 13, 2017 07:00
My .vimrc
set nocompatible
set background=dark
syntax on
set ruler
set nu
set t_Co=256
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab