Skip to content

Instantly share code, notes, and snippets.

View chenk008's full-sized avatar

chenk008

  • Alibaba Cloud
  • Hangzhou
  • 00:53 (UTC -12:00)
View GitHub Profile
@chenk008
chenk008 / RegexMatcheUtils.java
Created October 13, 2016 02:04
正则表达式工具类
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexMatcheUtils {
public static void main(String[] args) {
String result = replaceWithHandler("${x}*get(@36,3)", "@\\w+",
new RegexMatcheHandler() {
@chenk008
chenk008 / DirectMemorySize.java
Created November 21, 2016 09:21 — forked from rednaxelafx/DirectMemorySize.java
An Serviceability-Agent based tool to see stats of NIO direct memory, as an alternative on JDK6 without JMX support for direct memory monitoring. Only works on JDK6; to work on JDK7 will need some tweaking because static variables are moved to Java mirror
import java.io.*;
import java.util.*;
import sun.jvm.hotspot.memory.*;
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.tools.*;
import sun.jvm.hotspot.utilities.*;
public class DirectMemorySize extends Tool {
@chenk008
chenk008 / DumpClassURL.java
Created January 11, 2017 05:04 — forked from rednaxelafx/DumpClassURL.java
Using the ProtectionDomain of an InstanceKlass to see where it was loaded from, with Attach API this time
import java.lang.instrument.Instrumentation;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.Arrays;
import java.util.Comparator;
public class DumpClassURL {
public static void agentmain(String agentArgs, Instrumentation inst) {
Class<?>[] classes = inst.getAllLoadedClasses();
在java机器上执行:
tcpdump -i eth1 -s 0 -l -w - dst port 3306 | strings
-s 0 : 抓取数据包时默认抓取长度为68字节。加上-s 0 后可以抓到完整的数据包
-l:表示每行都输出到文件,不缓存
-w - :输出到console
dst port 3306 :目标端口,必须写在最后
@chenk008
chenk008 / native-mem-tracking.md
Created August 23, 2017 03:37 — forked from prasanthj/native-mem-tracking.md
Native memory tracking in JVM

Enable native memory tracking in JVM by specifying the following flag

-XX:NativeMemoryTracking=detail

Known the <PID> of the java process

jps

To print ps based RSS

ps -p <PID> -o pcpu,rss,size,vsize

To print native memory tracking summary

@chenk008
chenk008 / curl.md
Created March 23, 2018 15:02 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@chenk008
chenk008 / README.md
Created February 8, 2020 03:58 — forked from bobrik/README.md
CFS hiccups
@chenk008
chenk008 / get_ip_v1.c
Created March 27, 2020 13:34 — forked from listnukira/get_ip_v1.c
use getsockname to get ip and port
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define SERVER_ADDR "173.194.72.94"
#define SERVER_PORT 80
int main()
@chenk008
chenk008 / xstat
Created April 17, 2020 07:38 — forked from moiseevigor/xstat
xstat bash function to get file creation time on Linux with EXT4
xstat() {
for target in "${@}"; do
inode=$(ls -di "${target}" | cut -d ' ' -f 1)
fs=$(df "${target}" | tail -1 | awk '{print $1}')
crtime=$(sudo debugfs -R 'stat <'"${inode}"'>' "${fs}" 2>/dev/null |
grep -oP 'crtime.*--\s*\K.*')
printf "%s\t%s\n" "${crtime}" "${target}"
done
}