Skip to content

Instantly share code, notes, and snippets.

@liuxinglanyue
liuxinglanyue / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@liuxinglanyue
liuxinglanyue / NASM.sublime-build
Last active August 29, 2015 14:21
在Mac上执行汇编程序,配置Sublime Text的编译环境
{
"cmd": ["nasm", "-f", "macho64", "${file}"],
"file_regex": "a(sm)?$",
"working_dir": "${file_path}",
"selector": "untitled.asm",
"variants":
[
{
public class InvokeDynamicTest {
public static void main(String[] args) {
Runnable x = () -> {
};
}
}
@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) {
@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 / 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]);
}
@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() {
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 / 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 {
//attach_shm.c
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<stdio.h>
#define BUFSZ 1024
int main()
{