Skip to content

Instantly share code, notes, and snippets.

@liuxinglanyue
liuxinglanyue / B.java
Last active June 27, 2016 07:59
内部类类名和父类类名相同的问题
public class B {
public static void main(String[] args) {
}
public class B {
public String d;
}
}
@liuxinglanyue
liuxinglanyue / ws.py
Last active December 4, 2015 08:28
通过python连接websocket
# install ws4py
# pip install ws4py
# easy_install ws4py
from ws4py.client.threadedclient import WebSocketClient
class DummyClient(WebSocketClient):
def opened(self):
self.send("www.baidu.com")
def closed(self, code, reason=None):
//attach_shm.c
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<stdio.h>
#define BUFSZ 1024
int main()
{
@liuxinglanyue
liuxinglanyue / DirectMemorySize.java
Last active August 29, 2015 14:27 — 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 {
package main
import (
"fmt"
)
func main() {
data := "A\xfe\x02\xff\x04"
for _, v := range data {
fmt.Printf("%#x ", v) //0x41 0xfffd 0x2 0xfffd 0x4
@liuxinglanyue
liuxinglanyue / ABA.java
Created June 17, 2015 07:57
这不是一个ABA问题,哈哈
public class ABA {
private static int count = 0;
public static void main(String[] args) throws Exception {
ABA aba = new ABA();
aba.increase();
Thread.sleep(10000);
System.out.println(count);
}
public void increase() {
@liuxinglanyue
liuxinglanyue / KMP.java
Created June 16, 2015 15:46
KMP算法,查找子串
public class KMP {
public static void main(String[] args) {
String source = "ababababcaab";
String target = "abababca";
KMP kmp = new KMP();
int[] result = kmp.preProcess(target);
for(int i=0; i<result.length; i++) {
System.out.println(result[i]);
}
user root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@liuxinglanyue
liuxinglanyue / LocalAddress.java
Created June 8, 2015 06:57
获取本地ip地址
public static String getLocalAddress() {
try {
// Traversal Network interface to get the first non-loopback and non-private address
Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
ArrayList<String> ipv4Result = new ArrayList<String>();
ArrayList<String> ipv6Result = new ArrayList<String>();
while (enumeration.hasMoreElements()) {
final NetworkInterface networkInterface = enumeration.nextElement();
final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
while (en.hasMoreElements()) {
@liuxinglanyue
liuxinglanyue / HeapOOM.java
Last active August 29, 2015 14:21
MAT工具分析OOM例子
//java -Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8 -XX:PermSize=32M -XX:MaxPermSize=64M -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -Xloggc:oom.log HeapOOM
import java.util.*;
public class HeapOOM {
public static void main(String[] args) {
List list = new ArrayList();
int count = 0;
while(true) {
count++;
OOMObject o = new OOMObject("objname" + count);
if(count%10000==0) {