Skip to content

Instantly share code, notes, and snippets.

View ochinchina's full-sized avatar

Steven Ou ochinchina

  • NOKIA Chengdu, China
View GitHub Profile
@ochinchina
ochinchina / NettyConnection.java
Last active January 11, 2024 01:32
netty client reconnect if the connection is lost or the server is not started
package com.nokia.nls.nmif;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
@ochinchina
ochinchina / remove_snapshot_in_release.md
Created March 3, 2016 06:43
remove snapshot in the apache archiva repositories/internal

if you publish a snapshot release to apache/archiva and start to browse the repository, you will get "managed repo is configured for release only" error.

To fix this, you should:

  1. login to the archiva installed machine
  2. goto the repository repositories/internal to find the component whose snapshot is pushed
  3. delete the snapshot version directory ( like "1.0-SNAPSHOT" )
  4. remove the snapshot version from maven-metadata.xml file
  5. re-generate the md5 and put it to the maven-metadata.xml.md5 like below:
@ochinchina
ochinchina / ReadBytesFromIStream.cpp
Created July 2, 2014 10:09
read bytes to a buffer from C++ std::istream
#include <iostream>
std::size_t read_bytes( std::istream& in, char* buf, std::size_t len ) {
std::size_t n = 0;
while( len > 0 && in.good() ) {
in.read( &buf[n], len );
int i = in.gcount();
n += i;
len -= i;
@ochinchina
ochinchina / EchoClient.java
Last active September 20, 2023 09:52
Async socket demo in java
package asyncsocket;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;
import java.util.concurrent.atomic.AtomicInteger;
@ochinchina
ochinchina / pipe_demo.go
Created May 28, 2015 08:13
golang: connect two commands with pipe
package main
import (
"bytes"
"io"
"os"
"os/exec"
)
func main() {
import com.google.common.io.CharStreams;
import javax.activation.DataSource;
import javax.mail.BodyPart;
import javax.mail.Header;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMultipart;
import java.io.*;
import java.util.Enumeration;
@ochinchina
ochinchina / top_jstack_thread_cpu.md
Created July 24, 2015 07:51
use linux top command and the jdk utility jstack to find which java thread consumes most CPU

use top command to find which java thread consume high CPU

Using the following command to find what java threads consume high CPU

$ top -n1 -p <pid> -H
Tasks:  47 total,   0 running,  47 sleeping,   0 stopped,   0 zombie
Cpu(s): 22.1%us,  2.2%sy,  0.0%ni, 74.8%id,  0.0%wa,  0.0%hi,  0.9%si,  0.0%st
@ochinchina
ochinchina / AsynchronousSocketChannelWrapper.java
Last active September 14, 2020 16:30
AsynchronousSocketChannel wrapper to support completely asyn operations
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
/**
* This class wraps the AsynchronousSocketChannel reading and writing operations. The wrapped reading and writing operations is
* completely asynchronous operation. No any exception will be thrown from the read/write operation. If any exception occurs
* during read & write, the failed() method in CompletionHandler will be called.
@ochinchina
ochinchina / use_wnameless_oracle-xe-11g.md
Last active June 3, 2020 06:08
how to use wnameless/oracle-xe-11g docker image

##pull wnameless/oracle-xe-11g

$ sudo docker pull wnameless/oracle-xe-11g

##start the wnameless/oracle-xe-11g

$ sudo docker run -d -p 49160:22 -p 49161:1521 wnameless/oracle-xe-11g
@ochinchina
ochinchina / CsvParser.hpp
Last active May 25, 2020 13:32
A lightweighted Csv parser in C++ language
/**
* parse csv from file or string
*
*/
#ifndef _CSV_PARSER_HPP
#define _CSV_PARSER_HPP
#include <iostream>
#include <string>
#include <fstream>