Skip to content

Instantly share code, notes, and snippets.

View songyunlu's full-sized avatar

Jimmy Lu songyunlu

View GitHub Profile
#/bin/sh
# kubeadm
sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo bash -c "echo 'deb http://apt.kubernetes.io/ kubernetes-xenial main' > /etc/apt/sources.list.d/kubernetes.list"
sudo apt-get update
sudo apt-get install -y kubelet kubeadm
# docker
@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
@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"
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");
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
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");
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;
@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;
}
@SpringBootApplication
@EnableDiscoveryClient
public class DiscoveryClientApp {
public static void main(String[] args) {
SpringApplication.run(DiscoveryClientApp.class, args);
}
}
@SpringBootApplication
@EnableEurekaServer
public class ServiceRegistryApp {
public static void main(String[] args) {
SpringApplication.run(ServiceRegistryApp.class, args);
}
}