Skip to content

Instantly share code, notes, and snippets.

View Aitozi's full-sized avatar
🐢
Happy coding

WenjunMin Aitozi

🐢
Happy coding
  • 09:44 (UTC +08:00)
View GitHub Profile
@Aitozi
Aitozi / tmux-cheatsheet.markdown
Created June 13, 2018 14:16 — forked from ryerh/tmux-cheatsheet.markdown
Tmux 快捷键 & 速查表

Tmux 快捷键 & 速查表

启动新会话:

tmux [new -s 会话名 -n 窗口名]

恢复会话:

tmux at [-t 会话名]
@Aitozi
Aitozi / StreamGraphHasherV2.java
Last active May 27, 2018 04:27
Flink JobGraph生成涉及的类
public class StreamGraphHasherV2 implements StreamGraphHasher {
private static final Logger LOG = LoggerFactory.getLogger(StreamGraphHasherV2.class);
/**
* Returns a map with a hash for each {@link StreamNode} of the {@link
* StreamGraph}. The hash is used as the {@link JobVertexID} in order to
* identify nodes across job submissions if they didn't change.
*
* <p>The complete {@link StreamGraph} is traversed. The hash is either
@Aitozi
Aitozi / SharedBuffer.java
Created April 2, 2018 05:13
这个清理为什么遇到比pruningTimestamp大的时间就停止清理了呢
public void prune(long pruningTimestamp, List<SharedBufferEntry<K, V>> prunedEntries) {
Iterator<Map.Entry<ValueTimeWrapper<V>, SharedBufferEntry<K, V>>> iterator = entries.entrySet().iterator();
boolean continuePruning = true;
while (iterator.hasNext() && continuePruning) {
SharedBufferEntry<K, V> entry = iterator.next().getValue();
if (entry.getValueTime().getTimestamp() <= pruningTimestamp) {
prunedEntries.add(entry);
iterator.remove();
@Aitozi
Aitozi / ContinuousEventTimeTrigger.java
Created April 1, 2018 15:16
ReducingState usage in ContinuousEventTimeTrigger.java
private final ReducingStateDescriptor<Long> stateDesc =
new ReducingStateDescriptor<>("fire-time", new Min(), LongSerializer.INSTANCE);
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
@Aitozi
Aitozi / gist:298f0f2464bb04d6df6bf312c8cf09dd
Created November 13, 2017 02:11 — forked from jessitron/gist:8376139
scala: print all URLs on classpath
def urlses(cl: ClassLoader): Array[java.net.URL] = cl match {
case null => Array()
case u: java.net.URLClassLoader => u.getURLs() ++ urlses(cl.getParent)
case _ => urlses(cl.getParent)
}
val urls = urlses(getClass.getClassLoader)
println(urls.filterNot(_.toString.contains("ivy")).mkString("\n")
@Aitozi
Aitozi / 惰性求值
Created November 13, 2017 01:21
scala惰性求值
def exists(p: A=> Boolean): Boolean = this match {
case Cons(h, t) => p(h()) || t().exists(p)
case _ => false
}
@Aitozi
Aitozi / ClusterClient.java
Created October 24, 2017 16:00
Flink job启动分析
try {
// invoke main method
prog.invokeInteractiveModeForExecution();
if (lastJobExecutionResult == null && factory.getLastEnvCreated() == null) {
throw new ProgramMissingJobException();
}
if (isDetached()) {
// in detached mode, we execute the whole user code to extract the Flink job, afterwards we run it here
return ((DetachedEnvironment) factory.getLastEnvCreated()).finalizeExecute();
}
@Aitozi
Aitozi / MeterView.java
Last active September 25, 2017 01:46
计算Meter,每个一个UPDATE_INTERVAL_SECONDS调用一次update方法
package org.apache.flink.metrics;
public class MeterView implements Meter, View {
/** The underlying counter maintaining the count */
private final Counter counter;
/** The time-span over which the average is calculated */
private final int timeSpanInSeconds;
/** Circular array containing the history of values */
private final long[] values;
/** The index in the array for the current time */
@Aitozi
Aitozi / Threadlocal.java
Last active September 5, 2017 08:15
Threadlocal的用法
/**
*
*当我们调用get方法的时候,其实每个当前线程中都有一个ThreadLocal。每次获取或者设置都是对该ThreadLocal进行的操作,是与其他线程分开的
*应用场景:当很多线程需要多次使用同一个对象,并且需要该对象具有相同初始化值的时候最适合使用ThreadLocal
*/
public class ConnectionUtil {
private static ThreadLocal<Connection> tl = new ThreadLocal<Connection>();
private static Connection initConn = null;
static {
try {