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 / 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 / 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 / CheckGZIPStream
Created November 11, 2014 14:06
check gzip stream
package com.xqbase.java;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.util.zip.GZIPInputStream;
public class CheckGZIPStream {
@adohe-zz
adohe-zz / linux_node_install.sh
Created October 15, 2014 15:42
add linux node install script
curl http://nodejs.org/dist/<version>/node-<version>.tar.gz
tar zxvf node-<version>.tar.gz
cd node-<version>
./configure
make
[sudo] make install
@adohe-zz
adohe-zz / upload.js
Created October 14, 2014 16:14
add upload script
var http = require('http'),
fs = require('fs'),
parse = require('url').parse;
function upload(url, filePath, callback) {
var urlObj = parse(url),
path = urlObj.pathname + (urlObj.search || ''),
options = {
hostname: urlObj.hostname,
path: path,
@adohe-zz
adohe-zz / request_handler.js
Last active August 29, 2015 14:07
request timeout handler
var http = require('http'),
parse = require('url').parse;
function requestUrl(url, callback) {
var urlObj = parse(url),
path = urlObj.pathname + (urlObj.search || ''),
options = {
hostname: urlObj.hostname,
path: path,
port: urlObj.port || 80,
@adohe-zz
adohe-zz / file
Created July 29, 2014 12:25
UNIX special file descriptors
in UNIX system, there are three special file descriptors,
they are stdin, stdout, stderr, and the corrsponding file
descriptors are 0, 1, 2, and they are store in the corrsponding
FILE struct.
@adohe-zz
adohe-zz / main
Created July 27, 2014 07:31
Arguments - Call by Value(C version)
#include <stdio.h>
#include <stdlib.h>
int power(int m, int n);
int main() {
int m, n;
system("clear");
printf("Enter two numbers:\n");
@adohe-zz
adohe-zz / TestRef
Created July 27, 2014 07:14
Arguments - Call by Value(Java Version)
package com.ado.java;
public class TestRef {
public static void main(String[] args)
{
ValueObject vo1 = new ValueObject("A", 1);
System.out.println("after vo1: " + vo1.getName()); //=A
changeValue1(vo1);