Skip to content

Instantly share code, notes, and snippets.

View justdoit0823's full-sized avatar

余森彬 justdoit0823

View GitHub Profile
@justdoit0823
justdoit0823 / tcp_rtt.sh
Last active August 18, 2020 03:44
Analysis tcp rtt or rto with tshark.
# rtt
tshark -r tcpdump_outfile -Tfields -e frame.time_relative -e tcp.analysis.ack_rtt|awk -F'\t' 'length($2) > 0 {print $2}'
# rto
tshark -r tcpdump_outfile -Tfields -e frame.time_relative -e tcp.analysis.rto|awk -F'\t' 'length($2) > 0 {print $2}'
@justdoit0823
justdoit0823 / remote_tcp_port_rtt.sh
Last active August 11, 2020 06:43
Show highest rtt within remote tcp server port from local.
# replace 10.73 with your own network and 15138 with port
ss -ti|grep -E '10.73.[[:digit:]]{2,3}.[[:digit:]]{2,3}:15138' -A 1|grep 'ESTAB' -A 1|grep -v -- --|awk '{if(index($0, "ESTAB")) {h = $5} if(index($0, "rtt")) {split($4, a, "rtt:"); split(a[2], b, "/"); if(b[1] > r[h]) {r[h] = b[1]}}} END {for(h in r) print h, r[h]}'
@justdoit0823
justdoit0823 / process_segment_memory.sh
Last active July 22, 2020 07:42
Linux process segment memory usage stat script.
# total threads memory
grep -A 2 'stack:' /proc/$PID/smaps|grep Rss|awk '{m += $2} END {print m}'
# top ten threads
grep -A 2 'stack:' /proc/$PID/smaps|grep -v -- '--'|awk '{if(index($0, "stack")) {split($NF, a, "stack:"); split(a[2], b, "]"); s[i++] = b[1]} if(index($0, "Rss")) {v[b[1]] = $2}} END {for(t in s) print s[t], v[s[t]]}'|sort -k 2 -nr|head
@justdoit0823
justdoit0823 / PrimitiveType.java
Created June 25, 2020 05:31
Print java primitive type presentation.
import java.util.Arrays;
import java.util.List;
public class PrimitiveType {
public static void main(String[] args) {
byte[] x = new byte[]{1};
char[] y = new char[]{1, 2};
int[] z = new int[]{1};
long[] j = new long[]{1L};
@justdoit0823
justdoit0823 / DefaultClassShow.java
Created May 31, 2020 04:55
Show default class object info in java.
import java.util.Arrays;
import java.util.List;
class DefaultClassShow {
public static void main(String... args) {
byte[] b = new byte[]{1, 2, 3};
char[] c = new char[]{1, 2, 3};
@justdoit0823
justdoit0823 / springboot_application_properties.md
Created May 9, 2020 09:18
How to configure property value in springboot application.

Property Priority

  1. Devtools global settings properties in the $HOME/.config/spring-boot folder when devtools is active.
  2. @TestPropertySource annotations on your tests.
  3. properties attribute on your tests. Available on @SpringBootTest and the test annotations for testing a particular slice of your application.
  4. Command line arguments.
  5. Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property).
  6. ServletConfig init parameters.
  7. ServletContext init parameters.
@justdoit0823
justdoit0823 / ListInterfaces.java
Created April 9, 2020 05:56
list network interfaces.
import java.net.NetworkInterface;
import java.util.Enumeration;
public class ListInterfaces {
public static void main(String[] args) {
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
System.out.println("interface " + interfaces.nextElement().getName());
@justdoit0823
justdoit0823 / kafka_topic_offsets.py
Created February 8, 2020 13:57
Fetch kafka topic offsets at specified timestamp.
from kafka import KafkaConsumer, TopicPartition
def get_topic_offsets(bootstrap_servers, topic, n_partition, ts):
consumer = KafkaConsumer(bootstrap_servers=bootstrap_servers)
return consumer.offsets_for_times({TopicPartition(topic, i): ts for i in range(n_partition)})
@justdoit0823
justdoit0823 / spark_job_duration_on_yarn.py
Created February 6, 2020 05:15
collect spark job duration from yarn application web page.
import bs4
import requests
def parse_ts(s):
s = s.strip()
v, unit = s.split(' ')[:2]
v = float(v)
if unit == 'ms':
@justdoit0823
justdoit0823 / test_ufunc_type_size.c
Created April 27, 2019 08:30
Test PyUFuncObject size.
#include "stdio.h"
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
// compile with comamnd `gcc -I/usr/local/lib/python3.6/site-packages/numpy/core/include $(python3.6m-config --cflags) test_ufunc_type_size.c`
int main(int argc, char * argv[]) {
printf("ufunc type size is %ld.\n", sizeof(PyUFuncObject));
return 0;