Skip to content

Instantly share code, notes, and snippets.

View adohe-zz's full-sized avatar

TonyAdo adohe-zz

View GitHub Profile
@adohe-zz
adohe-zz / ns-inet.sh
Created January 20, 2017 03:47 — forked from dpino/ns-inet.sh
Setup a network namespace with Internet access
#!/usr/bin/env bash
set -x
NS="ns1"
VETH="veth1"
VPEER="vpeer1"
VETH_ADDR="10.200.1.1"
VPEER_ADDR="10.200.1.2"
@adohe-zz
adohe-zz / gist:17442966ac940eae2430fe4871bb93e0
Created December 11, 2016 10:45 — forked from samnang/gist:1759336
Install Bash version 4 on MacOS X
# Install Bash 4 using homebrew
brew install bash
# Or build it from source...
curl -O http://ftp.gnu.org/gnu/bash/bash-4.2.tar.gz
tar xzf bash-4.2.tar.gz
cd bash-4.2
./configure --prefix=/usr/local/bin && make && sudo make install
# Add the new shell to the list of legit shells
@adohe-zz
adohe-zz / singleton.go
Created April 29, 2016 08:01
Golang singleton implementation
package singleton
import (
"sync"
)
type singleton struct {
}
var instance *singleton
@adohe-zz
adohe-zz / shift
Last active August 29, 2015 14:20
shift operation.
在c 中左移也就是所说的逻辑移位,右端补0,而右移是算数移位,左端补齐的是最高位的符号位。
故负数左移,有可能变成正数,但负数右移,肯定还是负数。
用16进制的形式对数据进行赋值,这16进制的数代表的是补码。
对于signed类型的扩展,看该数据的最高位,为1,则扩展的所有位都为1,为0,则扩展的位都为0,故0xf7扩展成32位是0xfffffff7
@adohe-zz
adohe-zz / notes
Created May 7, 2015 06:18
Notes on Distributed Systems
1. Distributed systems are different because they fail often. What sets distributed systems engineering apart is the probability of failure and, worse, the probability of partial failure. Networked systems fail more than systems that exist on only a single machine and that failures tend to be partial instead of total. Design for failure.
2. Writing robust distributed systems costs more than writing robust single-machine systems. There are failure conditions that are difficult to replicate on a single machine. Distributed systems tend to need actual, not simulated, distribution to flush out their bugs. Simulation is, of course, very useful.
3. Robust, open source distributed systems are much less common than robust, single-machine systems.
4. Coordination is very hard. Avoid coordination machines wherever possible. This is often describled as "horizontal scalability". The real trick of horizontal scalability is independence - being able to get data to machines such that communication and consensus between t
@adohe-zz
adohe-zz / go_install
Created April 24, 2015 02:52
install go on linux
#!/bin/bash
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
export PATH=$PATH:/usr/local/go/bin
@adohe-zz
adohe-zz / AddTwoNumbers.java
Last active August 29, 2015 14:19
LeetCode2 -- Add Two Numbers
package com.xqbase.java;
/**
* LeetCode02 -- Add Two Numbers
*
* @author Tony He
*/
public class AddTwoNumbers {
public static class ListNode {
@adohe-zz
adohe-zz / BoundedHashSet.java
Created April 11, 2015 16:06
simple about Semaphore usage
public class BoundedHashSet<T> {
private final Set<T> set;
private final Semaphore sem;
public BoundedHashSet(int bound) {
set = Collections.synchronizedSet(new HashSet<T>());
sem = new Semphore(bound);
}
public boolean add(T o) throw InterruptedException {
@adohe-zz
adohe-zz / PreLoader.java
Created January 11, 2015 03:42
Simple about FutureTask usage
package com.xqbase.java;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
/**
* Simple about how to use FutureTask to do some pre-load
* task.
*
@adohe-zz
adohe-zz / TestHarness.java
Created January 11, 2015 03:40
Simple about CountLatch usage
package com.xqbase.java;
import java.util.concurrent.CountDownLatch;
/**
* Simple about how to use Latch {@link java.util.concurrent.CountDownLatch}
* to control the threads start&stop process.
*
* @author Tony He
*/