Skip to content

Instantly share code, notes, and snippets.

View caoxudong's full-sized avatar
💭
coding,talking

caoxudong caoxudong

💭
coding,talking
View GitHub Profile
@caoxudong
caoxudong / ActuatorConfig.java
Created December 28, 2019 11:42
intercept actuator uri in springboot 2
package demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.servlet.WebMvcEndpointManagementContextConfiguration;
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
@caoxudong
caoxudong / LambdaDemo.java
Last active December 23, 2019 02:35
lambda and method reference bytecode
package com.example.demo.lambda;
import java.io.PrintStream;
import java.util.function.Consumer;
public class LambdaDemo {
public static void main(String[] args) {
Consumer<Integer> c1 = s -> System.out.println(s);
Consumer<Integer> c2 = System.out::println;
@caoxudong
caoxudong / README.markdown
Last active May 22, 2023 07:29
create a user for yapi

create a user for yapi, e.g.:

$ python3 create_user.py --mongo_host localhost --mongo_port 27017 --username haha --useremail haha@163.com
INFO: generate default password: Uck33M42Za
INFO: create user successfully, id=29

note:

  • install python lib pymongo
@caoxudong
caoxudong / server.py
Created December 21, 2018 09:33 — forked from mdonkers/server.py
Simple Python 3 HTTP server for logging all GET and POST requests
#!/usr/bin/env python3
"""
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
class S(BaseHTTPRequestHandler):
@caoxudong
caoxudong / basic_op.markdown
Last active September 15, 2018 13:44
linux basic op scripts

线上常用脚本

删除大小为0的文件

find . -name "*" -type f -size 0c | xargs -n 1 rm -f

swap使用量top10

for file in /proc/*/status ; do awk '/VmSwap|^Pid/{printf $2 " " $3}END{ print ""}' $file; done | awk -F ' ' 'BEGIN { jpsOutputFile="/tmp/caoxudong.stat.swap.txt"; jpsCmd="jps >"jpsOutputFile; system(jpsCmd); while (getline line < jpsOutputFile) {split(line, idname, " "); apps[idname[1]]=idname[2];}}    {split($0, idcountunit, " "); result[idcountunit[1]]=apps[idcountunit[1]]" "idcountunit[2]" "idcountunit[3];}    END{for(id in result){print id, result[id]}}' | sort -k 3 -n -r | head
@caoxudong
caoxudong / MethodHandleTest.java
Last active March 25, 2021 02:44
关于MethodHandle性能的简单测试
package test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
public class MethodHandleTest {
public static void main(String[] args) throws Throwable {
@caoxudong
caoxudong / ComputeSummerTime.java
Created October 17, 2017 08:09
计算夏令时的时间
package test.data;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
public class ComputeSummerTime {
/**
@caoxudong
caoxudong / check_threads_count.sh
Created September 26, 2017 05:38
查看系统中线程数最多的10个进程
ps -eLf | tail -n +2 | awk -F ' ' '{threads_count[$2]++;} END{for(pid in threads_count){print pid,threads_count[pid];}}' | sort -k2 -n -r | head
@caoxudong
caoxudong / check_swap.sh
Created September 8, 2017 10:37
倒序查看进程占用的swap分区资源
for file in /proc/*/status ; do awk '/VmSwap|^Pid/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | head
@caoxudong
caoxudong / gist:311865cdc24efa3b3d6e55bd71b1b70a
Created June 28, 2017 07:16 — forked from fernandoaleman/gist:5083680
How to update VirtualBox Guest Additions with vagrant
# Start the old vagrant
$ vagrant init centos-6.3
$ vagrant up
# You should see a message like:
# [default] The guest additions on this VM do not match the install version of
# VirtualBox! This may cause things such as forwarded ports, shared
# folders, and more to not work properly. If any of those things fail on
# this machine, please update the guest additions and repackage the
# box.