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 / install_boot2docker_2_hadrdisk.txt
Created September 26, 2014 01:57
install boot2docker to harddisk in the virtualbox
1, create a virtual machine from the virtualbox with VDI harddisk
2, add a virtual CDROM to the virtual machine and select boot2docker.iso ( the boot2docker.iso should be downloaded before)
3, start the virtual machine
4, write the boot2docker.iso image to the virtual harddisk using dd command
# dd if=/dev/cdrom of=/dev/sda
@ochinchina
ochinchina / HowToSetProxyFor boost2docker
Last active August 29, 2015 14:06
set proxy for boot2docker
1) edit file /var/lib/boot2docker/profile, and add the proxy setting lines to the file
export HTTP_PROXY=http://<proxy host>:<port>
export HTTPS_PROXY=https://<proxy host>:<port>
2) restart the docker
/etc/init.d/docker restart
@ochinchina
ochinchina / VirtualBox.xml
Last active August 29, 2015 14:06
core-os fleet with own deployed discovery service
<?xml version="1.0"?>
<!--
** DO NOT EDIT THIS FILE.
** If you make changes to this file while any VirtualBox related application
** is running, your changes will be overwritten later, without taking effect.
** Use VBoxManage or the VirtualBox Manager GUI to make changes.
-->
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.12-linux">
<Global>
<ExtraData>
@ochinchina
ochinchina / dockerBehindProxyInCoreOs
Last active August 29, 2015 14:06
docker in coreos usage
If the coreos is deployed behind a proxy, we can simply use following steps to make docker work:
1) copy the /usr/lib/systemd/system/docker.service to /etc/systemd/system/ directory
sudo cp /usr/lib/systemd/system/docker.service /etc/systemd/system/
2) edit the /etc/systemd/system/docker.service file and add
Environment="HTTP_PROXY=http://proxy.example.com:8080"
@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 / FoundationDBCTest.cpp
Created July 22, 2014 07:35
The foundationdb C API test
#define FDB_API_VERSION 200
#include <foundationdb/fdb_c.h>
#include <iostream>
#include <thread>
#include <string>
#include <unistd.h>
void init() {
fdb_error_t err = fdb_select_api_version( FDB_API_VERSION );
@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 / ZkQueueTest.cpp
Created July 14, 2014 02:05
The zookeeper queue implementation using C API
#include <zookeeper.h>
#include <iostream>
#include <string>
#include <unistd.h>
#include <mutex>
#include <condition_variable>
#include <sstream>
class ZkQueue {
public:
@ochinchina
ochinchina / Makefile
Created July 8, 2014 07:57
Demostrate how to select a leader from zookeeper in C API, before doing make, set the ZK_DIR environment variable
CPP = g++
INCS = -I$(ZK_DIR)/src/c/include -I/home/ochinchina/zookeeper-3.4.6/src/c/generated
LIBS = -L$(ZK_DIR)/src/c/.libs -lzookeeper_mt -lpthread
CXX_FLAGS = -std=c++11
all: leader
leader: ZkLeaderElection.o
$(CPP) -o leader ZkLeaderElection.o $(LIBS)
@ochinchina
ochinchina / Makefile
Created July 7, 2014 10:05
implement barrier with the zookeeper C API, require C++11 compiler
CPP = g++
INCS = -I$(ZK_DIR)/src/c/include -I$(ZK_DIR)/src/c/generated
LIBS = -L$(ZK_DIR)/src/c/.libs -lzookeeper_mt -lpthread
CXX_FLAGS = -std=c++11
all: barrier
barrier: ZkBarrierTest.o
$(CPP) -o barrier ZkBarrierTest.o $(LIBS)