洗牌算法

-- To shuffle an array a of n elements (indices 0..n-1):
for i from n−1 downto 1 do
     j ← random integer such that 0 ≤ j ≤ i
     exchange a[j] and a[i]

java 实现

import java.util.Arrays;
import java.util.Random;

public class Shuffle {

	public static void shuffle(int[] arr) {
		int i = arr.length;
		Random random = new Random();
		while (i > 1) {
			i = i - 1;
			int j = random.nextInt(i);
			int temp = arr[i];
			arr[i] = arr[j];
			arr[j] = temp;
		}
		System.out.println(Arrays.toString(arr));
	}

	public static void main(String[] args) {
		int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
		for (int i = 0; i < 50; i++)
			shuffle(arr);
	}
}

运行50次结果

[7, 3, 0, 2, 9, 1, 8, 4, 6, 5]
[3, 2, 5, 9, 1, 6, 7, 0, 4, 8]
[7, 8, 6, 1, 4, 2, 0, 9, 5, 3]
[9, 3, 1, 7, 5, 6, 4, 8, 2, 0]
[5, 9, 0, 2, 1, 4, 7, 6, 3, 8]
[4, 8, 3, 9, 6, 1, 5, 0, 2, 7]
[0, 6, 9, 1, 3, 5, 4, 2, 7, 8]
[6, 3, 8, 4, 5, 2, 0, 9, 1, 7]
[8, 9, 3, 1, 4, 7, 6, 2, 0, 5]
[1, 8, 4, 7, 2, 3, 0, 5, 9, 6]
[9, 1, 3, 5, 0, 8, 6, 4, 2, 7]
[1, 7, 9, 4, 6, 3, 8, 0, 5, 2]
[0, 8, 4, 7, 3, 2, 6, 5, 9, 1]
[1, 7, 8, 9, 6, 5, 0, 4, 3, 2]
[5, 4, 1, 8, 0, 7, 3, 2, 9, 6]
[8, 6, 2, 0, 1, 5, 9, 3, 4, 7]
[5, 7, 4, 9, 0, 3, 6, 2, 1, 8]
[8, 9, 5, 4, 7, 0, 1, 3, 2, 6]
[2, 5, 6, 7, 3, 1, 4, 9, 0, 8]
[0, 7, 8, 2, 6, 5, 9, 1, 3, 4]
[4, 3, 6, 0, 5, 1, 2, 9, 8, 7]
[6, 1, 5, 8, 9, 4, 7, 0, 2, 3]
[9, 4, 0, 2, 5, 6, 3, 8, 7, 1]
[5, 2, 7, 0, 4, 3, 9, 6, 1, 8]
[4, 3, 1, 7, 9, 0, 6, 2, 8, 5]
[5, 8, 6, 1, 4, 9, 2, 0, 7, 3]
[3, 0, 2, 6, 1, 5, 8, 7, 9, 4]
[1, 6, 0, 4, 7, 3, 5, 9, 2, 8]
[5, 8, 6, 0, 2, 4, 7, 3, 9, 1]
[8, 7, 3, 6, 4, 1, 0, 9, 2, 5]
[9, 0, 7, 1, 5, 8, 4, 3, 6, 2]
[0, 4, 9, 7, 8, 1, 6, 5, 2, 3]
[5, 0, 4, 2, 1, 7, 9, 8, 3, 6]
[7, 2, 8, 3, 5, 4, 1, 0, 6, 9]
[2, 6, 4, 8, 0, 5, 9, 7, 1, 3]
[0, 2, 9, 7, 8, 6, 1, 4, 3, 5]
[6, 4, 1, 2, 9, 7, 5, 3, 8, 0]
[3, 2, 4, 0, 5, 9, 8, 1, 6, 7]
[9, 0, 8, 7, 6, 2, 3, 4, 1, 5]
[4, 1, 5, 3, 8, 9, 0, 6, 2, 7]
[8, 5, 6, 0, 2, 4, 7, 3, 1, 9]
[1, 4, 9, 6, 3, 2, 8, 7, 0, 5]
[9, 5, 6, 2, 0, 7, 1, 3, 4, 8]
[1, 8, 3, 6, 4, 5, 7, 0, 9, 2]
[8, 3, 7, 5, 1, 9, 0, 2, 4, 6]
[2, 0, 6, 4, 5, 1, 9, 7, 8, 3]
[9, 6, 1, 2, 4, 8, 3, 5, 7, 0]
[6, 3, 4, 0, 2, 1, 8, 9, 5, 7]
[2, 9, 1, 3, 5, 6, 4, 8, 7, 0]
[3, 5, 7, 1, 6, 0, 8, 9, 4, 2]

BackOff重试算法

可以使用斐波那契数列计算重试时间,也可以使用指数补偿计算重试时间。

定义一个接口

@FunctionalInterface
public interface ExponentialBackOffFunction <T> {
	T execute();
}

定义重试工具类

import static java.util.Arrays.asList;

import java.net.SocketTimeoutException;
import java.util.List;

import javax.net.ssl.SSLHandshakeException;

import lombok.extern.log4j.Log4j;

@Log4j
public final class ExponentialBackOff {
	
	private static final int[] FIBONACCI = new int[] { 1, 1, 2, 3, 5, 8, 13 };
	private static final List<Class<? extends Exception>> EXPECTED_COMMUNICATION_ERRORS = asList(
			SSLHandshakeException.class, SocketTimeoutException.class);

	private ExponentialBackOff() {
	}

	// E(c) = Math.pow(2, c) - 1
	// 考虑到补偿时间的均匀分布,补偿时间的数学期望是所有可能性的平均值。
	// 也就是说,在c次冲突之后,补偿时隙数量在 [0,1,...,N] 中,其中 [公式] E(c) = Math.pow(2, c) - 1
	// 则补偿时间的数学期望 E(c) = (Math.pow(2, c) - 1)/2
	public static long getWaitTimeExponential(int attempt) {
		double waitTime = (Math.pow(2, attempt) - 1) / 2;
		return Math.round(waitTime * 100);
	}
	
	// 这个地方使用斐波那契数去增加重试时间
	public static long getWaitTimeDefault(int attempt) {
		return FIBONACCI[attempt] * 100;
	}

	public static <T> T execute(ExponentialBackOffFunction<T> fn) {
		for (int attempt = 0; attempt < FIBONACCI.length; attempt++) {
			try {
				return fn.execute();
			} catch (Exception e) {
				handleFailure(attempt, e);
			}
		}
		throw new RuntimeException("Failed to communicate.");
	}

	private static void handleFailure(int attempt, Exception e) {
		if (e.getCause() != null && !EXPECTED_COMMUNICATION_ERRORS.contains(e.getCause().getClass()))
			throw new RuntimeException(e);
		doWait(attempt);
	}

	private static void doWait(int attempt) {
		try {
			long sleepTime = getWaitTimeExponential(attempt);
			System.out.println("attempt " + attempt + " sleep " + sleepTime);
			Thread.sleep(sleepTime);
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		}
	}
}

测试案例

public class Test {
	public static void main(String[] args) {
		ExponentialBackOff.execute(new Work());
	}
}

class Work implements ExponentialBackOffFunction<String> {

	@Override
	public String execute() {
		int a = 5 / 0;
		return a + "";
	}
}

运行结果

使用指数补偿:
attempt 0 sleep 0
attempt 1 sleep 50
attempt 2 sleep 150
attempt 3 sleep 350
attempt 4 sleep 750
attempt 5 sleep 1550
attempt 6 sleep 3150
使用斐波那契数列
attempt 0 sleep 100
attempt 1 sleep 100
attempt 2 sleep 200
attempt 3 sleep 300
attempt 4 sleep 500
attempt 5 sleep 800
attempt 6 sleep 1300

微服务编排框架

发现一个优秀的微服务编排框架:zeebe

微服务核心研究之–编排

当一个系统采用了微服务架构后,会拆分成很多新的微服务,但原有的业务可能还是没有变化,如何在微服务架构下实现原有的业务?相对于传统架构,微服务架构下更需要通过各微服务之间的协作来实现一个完整的业务流程,可以说服务编排是微服务架构下的必备技能。但是,编排涉及到RPC、分布式事务等等,编排的质量不能仅仅取决于老师傅的手艺,需要有完善的编排框架来支撑。

关于微服务的组合(协调):
编制(Orchestration)—— 面向可执行的流程:通过一个可执行的流程来协同内部及外部的服务交互。通过中心流程来控制总体的目标,涉及的操作,服务调用顺序。
编排(Choreography)—— 面向合作:通过消息的交互序列来控制各个部分资源的交互。参与交互的资源都是对等的,没有集中的控制。

哲学家就餐问题 [go/java 实现练习并发编程]

java

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

class Philosopher implements Runnable{
	private final String name;
	private final ReentrantLock left;
	private final ReentrantLock right;
	private final AtomicInteger hunger = new AtomicInteger(3);
	public Philosopher(String name, ReentrantLock left, ReentrantLock right) {
		this.name = name;
		this.left = left;
		this.right = right;
	}
	@Override
	public void run() {
		while (this.hunger.get() > 0) {
			System.out.println(name + " Hungry");
			this.left.lock();
			this.right.lock();
			System.out.println(name + " Eating");
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			this.right.unlock();
			this.left.unlock();
			System.out.println(name + " Thinking");
			this.hunger.decrementAndGet();
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}	
}

public class DiningPhilosopher {
	public static void main(String[] args) {
		ExecutorService executor = Executors.newCachedThreadPool();
		String[] philosophers = new String[] {"Mark", "Russell", "Rocky", "Haris", "Root"};
		ReentrantLock fork0 = new ReentrantLock();
		ReentrantLock forkLeftLock = fork0;
		List<Philosopher> philosopherList = new ArrayList<Philosopher>();
		for(int i=1;i<philosophers.length;i++) {
			String name = philosophers[i];
			ReentrantLock forkRightLock = new ReentrantLock();
			philosopherList.add(new Philosopher(name, forkLeftLock, forkRightLock));
			forkLeftLock = forkRightLock;
		}
		philosopherList.add(new Philosopher(philosophers[0], fork0, forkLeftLock));
		for (Philosopher philosopher : philosopherList) {
			executor.submit(philosopher);
		}
		executor.shutdown();
	}
}

go

package main

import (
	"hash/fnv"
	"log"
	"math/rand"
	"os"
	"sync"
	"time"
)

// 初始化5个人
var ph = []string{"Mark", "Russell", "Rocky", "Haris", "Root"}

const hunger = 3                // 每个哲学家吃几次饭
const think = time.Second / 100 // 思考时间
const eat = time.Second / 100   // 吃饭时间

var fmt = log.New(os.Stdout, "", 0)

var dining sync.WaitGroup

func diningProblem(phName string, dominantHand, otherHand *sync.Mutex) {
	fmt.Println(phName, "Seated")
	h := fnv.New64a()
	h.Write([]byte(phName))
	rg := rand.New(rand.NewSource(int64(h.Sum64())))
	rSleep := func(t time.Duration) {
		time.Sleep(t/2 + time.Duration(rg.Int63n(int64(t))))
	}
	for h := hunger; h > 0; h-- {
		fmt.Println(phName, "Hungry")
		dominantHand.Lock() // 获取资源
		otherHand.Lock()
		fmt.Println(phName, "Eating")
		rSleep(eat)
		dominantHand.Unlock() // 释放资源
		otherHand.Unlock()
		fmt.Println(phName, "Thinking")
		rSleep(think)
	}
	fmt.Println(phName, "Satisfied")
	dining.Done()
	fmt.Println(phName, "Left the table")
}

func main() {
	fmt.Println("Table empty")
	dining.Add(5)
	fork0 := &sync.Mutex{}
	forkLeft := fork0
	for i := 1; i < len(ph); i++ {
		forkRight := &sync.Mutex{}
		go diningProblem(ph[i], forkLeft, forkRight)
		forkLeft = forkRight
	}
	go diningProblem(ph[0], fork0, forkLeft)
	dining.Wait() // 等待结束
	fmt.Println("Table empty")
}

云在青天水在瓶

忙里偷闲终于把大明王朝1566看完了,对政治和经济更加敬畏。分享那些让人听来振聋发聩的语录。

1.三思就是思危 、思退和思变。知道了危险就能躲开危险,这就是“思危”;躲到人家都不再注意你的地方,这就叫思退;退了下来就有机会再慢慢看慢慢想,自己以前哪儿错了,往后该怎么做,这就是思变。

2.不谋全局者,不可谋一隅,不谋一世者,并不可谋一时。

3.这个世上,真靠得住的就两种人,一种是笨人,一种是直人。笨人没有心眼,直人不使心眼。

4.圣人的书是用来读的,用来办事百无一用。

5.任何人答应你的事都不算数,只有自己能做主的才算数。

6.做事情,不问能不能做成,要问应不应该做。

7.这人啊,熬一天不累,熬十天就累了;小心一年不难,小心一辈子就难了。

8.圣人出黄河清,可黄河什么时候清过?黄河虽浊,亦能灌溉;长江虽清,时有泛滥。

9.世间万事万物都只有一个理,各人站的位置不同,看法不同而已。

10.都说人不如旧衣不如新,可在朕看来,衣服和人都是老的好,衣服旧了贴身,人旧了贴心啊。

11.有时离九霄而膺天命 情何以堪;御四海而哀苍生 心为之伤。有时候啊,最亲的不是父子是师徒。儿子将父母之恩视为当然,弟子将师傅之恩,视为报答。

12.只有架起锅子煮白米,不能架起锅子煮道理吧。

13.文官的衣服上绣的是禽,武官的衣服上绣的是兽。披上了这身皮,我们哪一个不是衣冠禽兽。

14.历来造反的都是种田的人,没听说商人能闹翻了天。

15.屋檐滴水代接代,新官不算旧官账。

16.有些事不上秤没四两重,上了秤一千斤打不住。

17.用人之道,贵在知人。两京一十三省的官员,都要靠你们来举荐。有实心用事者,如胡总宪,有顾全大局者,如赵贞吉,这些都是好的。像郑泌昌 何茂才这等硕鼠,竟也荐任封疆,严世藩的两双眼睛,是不是全都瞎了!

18.这个世上,真靠得住的就两种人,一种是笨人,一种是直人。笨人没有心眼,直人不使心眼。

19.人心似水,水是往低处走的,人心总是高了还想高啊!

20.官做的在大,落到底也是居家过日子。

21.平时叫你读读《左传通鉴》,你不以为然;我叫你读一读王阳明的书,你更是不以为然,还说什么半部《论语》可治天下。现在我问你,孔子说的‘知不可为而为之’是什么本意?孔子是告诉世人,做事时不问可不可能,但问应不应该。毁堤淹田,伤天害理,上误国家,下害百姓。这也叫知不可为而为之?

22.朝廷也就是几座宫殿,几座衙门。饭还是要分锅吃的。

23.读书是为了明理,明了理就有了主张,知道该怎么做。但理是在变化的,又不能守死理。

24.圣人出黄河清,可黄河什么时候清过?黄河虽浊,亦能灌溉;长江虽清,时有泛滥。

25.裕王:大明朝谁是贤臣?嘉靖:没有谁是真正的贤臣,贤时用之,不贤黜之。

service mesh

A service mesh is a dedicated infrastructure layer that controls service-to-service communication over a network. It provides a method in which separate parts of an application can communicate with each other. Service meshes appear commonly in concert with cloud-based applications, containers and microservices.

A service mesh is in control of delivering service requests in an application. Common features provided by a service mesh include service discovery, load balancing, encryption and failure recovery. High availability is also common through utilizing software controlled by APIs rather than utilizing hardware. Service meshes can make service-to-service communication fast, reliable and secure.

As an example, an application structured in a microservices architecture might be composed of hundreds of services, all with their own instances operating in a live environment. This could make it challenging for developers to keep track of which components must interact, and make changes to their application if something goes wrong. Including communication protocols in a service rather than in a separate and dedicated layer would make the process of keeping track and making changes to an application fairly complex. Utilizing a service mesh allows developers the ability to separate service-to-service communication into a dedicated layer.

An organization may choose to utilize an API gateway, which handles protocol transactions, over a service mesh. However, developers must update the API gateway every time a microservice is added or removed.

How a service mesh works
A service mesh architecture uses a proxy instance called a sidecar in whichever development paradigm is in use, commonly containers and/or microservices. In a microservice application, a sidecar will attach to each service. In a container, the sidecar is attached to each application container, VM or container orchestration unit, such as a Kubernetes pod.

Sidecars can handle tasks abstracted from the service itself, such as monitoring and security.

Service instances, sidecars and their interactions make up what is called the data plane in a service mesh. A layer called the control plane manages tasks such as creating instances, monitoring and implanting policies, such as network management or network security policies. Control planes can connect to a CLI or a GUI interface for application management.

Service mesh benefits and drawbacks
A service mesh addresses some large issues with managing service-to-service communication, but not all. Some advantages of a service mesh include:

Simplifies communication between services in both microservices and containers.
Easier to diagnose communication errors, since they would occur on their own infrastructure layer.
Supports security features such as encryption, authentication and authorization.
Allows for faster development, testing and deployment of an application.
Sidecars placed next to a container cluster is effective in managing network services.
Some downsides to service meshes include:

Runtime instances increase by utilizing a service mesh.
Adds an extra step where each service call must first run through the sidecar proxy.
Service meshes do not address issues such as integrating with other services or systems and routing type or transformation mapping.
The service mesh market
A service mesh is commonly available as an open source technology from diverse creators. It can also be consumed as a service from major cloud providers.

Istio is an open source service mesh provided by Google, IBM and Lyft. Istio is designed as a universal control plane first targeted for Kubernetes deployments, but can be used on multiple platforms. Its data plane relies on proxies called Envoy sidecars. This service mesh features security measures such as identity and key management. It also supports fault injection and hybrid deployment.

Istio service mesh
The Istio service mesh architecture is one of the major designs available.
Linkerd is another open source, multiplatform service mesh. Linkerd was developed by Buoyant and is built on Twitter’s Finagle library. This service mesh supports platforms such as Kubernetes, Docker and Amazon ECS. Features include built-in service discovery and control plane, Namerd.

Goroutines vs Threads

Here are some of the advantages of Goroutines over threads:

You can run more goroutines on a typical system than you can threads.
Goroutines have growable segmented stacks.
Goroutines have a faster startup time than threads.
Goroutines come with built-in primitives to communicate safely between themselves (channels).
Goroutines allow you to avoid having to resort to mutex locking when sharing data structures.
Goroutines are multiplexed onto a small number of OS threads, rather than a 1:1 mapping.
You can write massively concurrent servers withouth having to resort to evented programming.

You can run more of them
On Java you can run 1000’s or tens of 1000’s threads. On Go you can run hundreds of thousands or millions of goroutines.

Java threads map directly to OS threads, and are relatively heavyweight. Part of the reason they are heavyweight is their rather large fixed stack size. This caps the number of them you can run in a single VM due to the increasing memory overhead.

Go OTOH has a segmented stack that grows as needed. They are “Green threads”, which means the Go runtime does the scheduling, not the OS. The runtime multiplexes the goroutines onto real OS threads, the number of which is controlled by GOMAXPROCS. Typically you’ll want to set this to the number of cores on your system, to maximize potential parellelism.

They let you avoid locking hell
One of the biggest drawback of threaded programming is the complexity and brittleness of many codebases that use threads to achieve high concurrency. There can be latent deadlocks and race conditions, and it can become near impossible to reason about the code.

Go OTOH gives you primitives that allow you to avoid locking completely. The mantra is don’t communicate by sharing memory, share memory by communicating. In other words, if two goroutines need to share data, they can do so safely over a channel. Go handles all of the synchronization for you, and it’s much harder to run into things like deadlocks.

No callback spaghetti, either
There are other approaches to achieving high concurrency with a small number of threads. Python Twisted was one of the early ones that got a lot of attention. Node.js is currently the most prominent evented frameworks out there.

The problem with these evented frameworks is that the code complexity is also high, and difficult to reason about. Rather than “straightline” coding, the programmer is forced to chain callbacks, which gets interleaved with error handling. While refactoring can help tame some of the mental load, it’s still an issue.

Golang 的 goroutine 是如何实现的?

鲁迅 聪明人和傻子和奴才(思考网易裁员事件)

聪明人和傻子和奴才
The Wise Man, the Fool and the Slave

奴才总不过是寻人诉苦。只要这样,也只能这样。有一日,他遇到一个聪明人。
What a slave did was just to look for someone to listen to his own grievances. That was the only thing he wanted to do and also the only thing he could do. One day he came across a wise man.

“先生!”他悲哀地说,眼泪联成一线,就从眼角上直流下来①。“你知道的。我所过的简直不是人的生活②。吃的是一天未必有一餐,这一餐又不过是高粱皮,连猪狗都不要吃的,尚且只有一小碗……”
“Sir!” said he sadly, tears trickling down from the corners of his eyes. “As you can see, I lead a subhuman life. I’m not even assured of a single meal a day. If I have one, it’s only a small bowl of kaoliang husks, which even a pig or dog would disdain to eat …”

“这实在令人同情。”聪明人也惨然③说。
“What a wretched life you lead!” the wise man replied with pity.

“可不是么!”他高兴了。“可是做工是昼夜无休息的:清早担水晚烧饭,上午跑街夜磨面,晴洗衣裳雨张伞,冬烧汽炉夏打扇。半夜要煨银耳,侍候主人耍钱④;头钱从来没分,有时还挨皮鞭……”
“Isn’t it?” the slave followed up with exaltation. “And I toil day and night without rest. I carry water at dawn and cook dinner at dusk. I run errands all morning and grind wheat at night. I wash the clothes when it’s fine and hold an umbrella for my master when it’s rainy. I take care of the heating stove in winter and keep cooling my master with a fan in summer. I boil white fungus for him late at night. I wait on him at his gambling table without ever getting a tip. Instead I sometimes get a good thrashing …”

“唉唉……”聪明人叹息着,眼圈有些发红,似乎要下泪。
“Oh, dear!” the wise man said with a sigh, the rims of his eyes looking somewhat red as if he were about to shed tears.

“先生!我这样是敷衍不下去的⑤。我总得另外想法子。可是什么法子呢?……”
“Sir! I can’t put up with it any more. I’ve got to find a way out. But what can I do?…”

“我想,你总会好起来……⑥”
“I’m sure you’ll pull through sooner or later …”

“是么?但愿如此。可是我对先生诉了冤苦,又得你的同情和慰安,已经舒坦得不少了。可见天理没有灭绝……”
“Really? I hope so. But, sir, I already feel much better now as you’ve given me sympathy and encouragement after listening to my grievances. It’s thus clear that Heaven always upholds justice …”

但是,不几日,他又不平起来了,仍然寻人去诉苦。
A few days later, however, he again began to grumble and look for somebody to listen to his complaints.

“先生!”他流着眼泪说,“你知道的。我住的简直比猪窠还不如。主人并不将我当人⑦;他对他的叭儿狗还要好到几万倍……”
“Sir!” he cried out tearfully. “You know, I live in a place even lousier than a pigsty. My master treats me like dirt. He treats his Pekinese ten thousand times better …”

“混账!”那人大叫起来,使他吃惊了。那人是一个傻子。
“Damn it!” the listener swore in such a loud voice as to make the slave start. This man was a fool.

“先生,我住的只是一间破小屋,又湿,又阴,满是臭虫,睡下去就咬得真可以⑧。秽气冲着鼻子,四面又没有一个窗……”
“Sir, I live in a run-down small hut which is wet, dingy, stinking and full of bedbugs. They bite me all over when I lie down to sleep. And the place doesn’t even have a single window …”

“你不会要你的主人开一个窗的么?”
“Why not ask your master to have a window made?”

“这怎么行?……”
“How can I do that? …”

“那么,你带我去看去!”
“OK, you show me around!”

傻子跟奴才到他屋外,动手就砸那泥墙。
As soon as they came to the slave’s dwelling, the fool started to pound its mud wall.

“先生!你干什么?”他大惊地说。
“What the hell are you doing, sir?” the slave yelled with alarm.

“我给你打开一个窗洞来。”
“I’m trying to knock a hole to make a window for you.”

“这不行!主人要骂的⑨!”
“No, you can’t do that! The master will be mad at me!”

“管他呢!”他仍然砸。
“To hell with your master!” The fool continued pounding away.

“来人呀!强盗在毁咱们的屋子了!快来呀!迟一点可要打出窟窿来了!……”他哭嚷着,在地上团团地打滚。
“Help! A robber is breaking down our house! Hurry up, or he’ll knock a big hole in the wall! …” Sobbing and shouting at the top of his voice, the slave rolled round and round on the ground.

一群奴才都出来了⑩,将傻子赶走。
Thereupon, a whole troop of slaves arrived on the scene and drove away the fool.

听到了喊声,慢慢地最后出来的是主人。
The last one that came out unhurriedly on hearing the commotion was the master.

“有强盗要来毁咱们的屋子,我首先叫喊起来,大家一同把他赶走了。”他恭敬而得胜地说⑪。
“A robber came to smash up our house,” the slave spoke respectfully and smugly. “I was the first to shout the alarm. We together drove him away.”

“你不错。”主人这样夸奖他。
“You did well,” the master praised him.

这一天就来了许多慰问的人,聪明人也在内。
A great many people came that day to express their solicitude, among them the wise man.

“先生。这回因为我有功,主人夸奖了我了。你先前说我总会好起来,实在是有先见之明……”他大有希望似的高兴地说。
“Sir, I’ve just been praised by my master for my meritorious service,” the slave said to the wise man very happily and hopefully. “I remember you said the other day that I would pull through sooner or later. So you’re really a man of foresight …”

“可不是么……”聪明人也代为高兴似的回答他。
“Oh, yeah …” replied the wise man as if he, too, were happy for the sake of the slave.

说明

《聪明人和傻子和奴才》是鲁迅(1881—1936)写于1925年12月的一篇短文,选自他的散文诗集《野草》。正如该书其他一些篇章,此文也以揭露和冷讽社会相为特点,刻画聪明人的刁巧与奴才之不可救药。

注释

①“眼泪联成一线,就从眼角上直流下来”译为tears trickling down from the corners of his eyes,未译为tears falling down in a string from the corners of his eyes,因trickling down表达“一连串落下”或“一滴滴流下”之意。

②“我所过的简直不是人的生活”译为I lead a subhuman life,其中subhuman作“非人的”(more like an animal than a human being)解。此句也可译为I lead a dog’s life。

③“惨然”在此应作“怜悯地”解,故译with pity。

④“侍候主人耍钱”意即“侍候主人赌钱”,故译I wait on him at his gambling table(或mah-jong table、gambling parties等)。

⑤“我这样是敷衍不下去的”意即“我无法凑合下去了”或“我不能再忍受了”,故译I can’t put up with it any more。

⑥“我想,你总会好起来……”可按“你迟早会渡过难关的……”译为I’m sure you will pull through sooner or later …。此句也可译为I believe things will improve eventually …。

⑦“主人并不将我当人”可译为My master treats me like dirt或My master doesn’t treat me like a human being。

⑧“咬得真可以”可按“浑身都被咬了”译为They bite me all over。

⑨“主人要骂的”可按“主人会对我大发脾气”之意译为The master will be mad at me。也可直译为The master will curse me或The master will swear at me。

⑩“一群奴才都出来了”译为A whole troop of slaves arrived on the scene,其中troop比group可取,因前者有“一起行动”的含意。

⑪“他恭敬而得胜地说”可按“他恭敬而沾沾自喜地说”译为the slave spoke respectfully and smugly。

遥远的救世主

1、 “着相”的无缘。 当女人不再需要脱下裤子换取温饱奢侈的时候,男人也不再显得那么重要,男女也就有可能平等了…

2、中国为什么落后?……五千年的文化积淀足以让你怕着胸脯说:我们有文化。但是五千年积淀却不能让你挺着胸脯回答说:我们有什么文化?因为有文化和有什么文化不是一个概念。

3、 你不缺一颗杀我的心,只是缺一个杀我而不影响自我评价的理由。

4、 天下之道论到极致,百姓的柴米油盐;人生冷暖论到极致,男人和女人的一个情字。

5、 不可思议一词不是众生道里的对神秘事物的描述,而是如是、本来、就是如此,容不得你思议。告诉你不可以思议,由不得你思议。从数学逻辑上说,一加一等于二,容得了你思议吗?不容,这就告诉你了,一加一等于二是规律,规律不以人的意志为转移,你只能认识、遵循,不可思议。

6、 佛教包括了佛法,而佛法有别于佛教。佛教以佛法证一,进而证究竟,最终是为给心找个不苦的理由,成佛,无量寿,极乐。佛教以假度真的方便法门住福相、住寿相、住果相,是以无执无我为名相的太极我执,致使佛教具有了迷信、宿命、贪执的弱势文化特征,已然障蔽佛法。

7、 救世主是没有的,只有自己救自己;救主,不是人,是道,得救不是破了戒的狼吞虎咽,是觉悟;强势文化造就强者,弱势文化造就弱者。

8、 悟道方知天命,修行务取真经, 一生一灭一枯荣,皆有因缘注定。 袈裟原本清净,红尘即是性空, 幽幽古刹千年钟,解了几多痴梦!

9、 神就是道,道法自然,按照规律办事的人就是神。

10、 女人哪,好多贱东西是骨子里生的,只要你是女人就扔不掉。

11、 任何一种命运,归根到底都是本国文化属性的产物,不以人的意志为转移。

12、 什么是客观规律?一切以时间、地点和条件为转移。

13、 愚昧是智者的社会资源。

14、 神即道,道法自然,如来。

15、 不能超越本能的男人,不算好汉。

16、 丁元英说:”想干成点事就记住两句话,别把别人不当人了,别把自己太当人了。就这点规律而言,天下乌鸦一般黑。”

17、 原来能做到实事求是就是神话! 原来能说老实话、能办老实事的人就是神! 因此可见,让人做到实事求是有多难,让人做到说老实话、办老实事有多难,而做到的人却成了说鬼话、办鬼事,倒行逆施。 这个世界怎么了?

18、 女人不是因为被爱才可爱,而是因为可爱才被爱。

19、 5年以后我不嫌你老,你就可以不老了吗?5年以后我变成了一个色狼,值得你回头看一眼吗?

20、 生存法则很简单,就是忍人所不忍,能人所不能。忍是一条线,能是一条线,两者的间距就是生存机会。如果能忍人所不忍,能人所不能,就比别人多了一些生存机会。

21、 隐藏与压抑,你不知道?或者知道,又能怎样?

22、 强势文化就是遵循事物规律的文化,弱势文化就是依赖强者的道德期望破格获取的文化,也是期望救主的文化。强势文化在武学上被称为”秘笈”,而弱势文化由于易学、易懂、易用,成了流行品种。

23、 古城是留不住你的,我也没奢望天长地久。你给我留个念想,让我知道你曾经这样爱我,我曾经这样做过女人,别让我把记忆都留在床上。

24、 智玄大师沉默不语,静静地看着丁元英,过了许久黯然感叹道:得智的得智,化缘的化缘,烧香的烧香,坐禅的坐禅。

25、 人是有命运的,文化属性和作用在不同人身上的自然规律决定了命和运,改变客观条件,才能改变命运。你是你自己的救世主。

26、 本是后山人, 偶做前堂客。 醉舞经阁半卷书, 坐井说天阔。大志戏功名,海斗量福祸。 论到囊中羞涩时, 怒指乾坤错。

27、 如果我的能力只能让我穷困潦倒,那穷困潦倒就是我的价值。

28、 公司在法律条款面前是一天都生存不下去,到时候不是考虑如何经营的问题,而是考虑怎么伺候好这群爷。

29、 说魔说鬼都是个表述,本质是思维逻辑和价值观与众人不同,所谓的地狱之门也无非是价值观冲突所带来的精神痛苦。如果你是觉者,我尊敬你,向你学习;如果你是魔鬼,我鉴别你,弃你而去。即便是价值观不同,就真有那么可怕吗?

30、 你能给我什么不重要,重要的是你别剥夺我什么。

31、 一个纯洁到一尘不染的女声,仿佛从天国里倾泻而下,仿佛是一双上帝的眼睛,怜悯地注视着人类,只一声,我骤然有一种灵魂之门被撞开的颤栗。

32、 你是一块玉,但我不是匠人,我不过是一个略懂投机之道得混子。充其量挣几个打发凡夫俗子得铜板,你要求得是一种雄性文化得魂,我不能因为你没有说出来而装作不知道,接受你就接受了一种高度,我没有这个自信。

33、 问:”为人处世当怎么做?” 答曰 :”随缘惜缘不攀缘。”

34、 修为成佛,再求;悟为明性,在知。修行以行制性,悟道以性施行。觉者由心生律,修者以律制心。

35、 透视社会依次有三个层面, 技术、 制度、和文化。小到一个人,大到一个国家一个民族任何一种命运归根到底都是那种文化属性的产物。强势文化造就强者, 弱势文化造就弱者,这是规律。也可以理解为天道,不以人的意志为转移。

36、 人是有命运的,文化属性和作用在不同人身上的自然规律决定了命和运,改变客观条件,才能改变命运。你是你自己的救世主!

37、 启迪人的觉悟、震撼人灵魂的精神拯救的暴利与毒品麻醉的暴利完全等值,而且不必像贩毒那样耍花招,没有心理成本和法律风险。

38、 品性这东西,今天缺个角、明天裂个缝,也就离塌陷不远了。

39、 更高级的哲人独处着,这并不是因为他想孤独,而是因为在他周围找不到他的同类。

40、 弱势得救之道,也有也没有。没有竞争的社会就没有活力,而竞争必然会产生贫富、等级,此乃天道,乃社会进步的必然代价。无弱,强焉在?一个‘强’字,弱已经在其中了。故而,佛度心苦,修的是一颗平常心。

41、 永远都不会跟你吵架。他的每个毛孔里都渗透着对世俗文化居高临下的包容,包容到不屑跟你讲道理,包容到让你自己觉得低俗自卑。

42、 这个年代,执着于出人头地并不难,难的恰恰是不执着于出人头地 ;一颗阴暗的心永远托不起一张灿烂的脸。

43、 不落恶果者有信无证,住因住果、住念住心,如是生灭。不昧因果者无住而住,无欲无不欲,无戒无不戒,如是涅碦。

44、 红颜知己自古有之,这还得看男人是不是一杯好酒,自古以来能有几个男人把自己酿到淡而又淡的名贵 ,这不是为之而可为的事,能混就混吧。

45、 认识这个人就是开了一扇窗户,就能看到不一样的东西,听到不一样的声音,能让你思考、觉悟,这已经够了。其它还有很多,比如机会、帮助。

46、 生老病死,有谁因为怕就躲过去了?

47、 只要不是我觉到、悟到的,你给不了我,给了我也拿不住,叶晓明他们就是例子。只有我自己觉到、悟到的,我才有可能做到,我能做到的才是我的。

48、 扶贫的事若以次第而分,也有三个层面。一、天上掉馅饼的神话,实惠、破格,是为市井文化。二、最不道德的道德,明辨是非,是为哲人文化。三、不打碎点东西不足以缘起主题,大智大爱,是为英雄文化。

49、 佛乃觉性,非人,人人都有觉性不等于觉性就是人。人相可坏,觉性无生无灭,即觉即显,即障即尘蔽,无障不显,了障涅碦。觉行圆满之佛乃佛教人相之佛,圆满即止,即非无量。若佛有量,即非阿弥陀佛。佛法无量即觉行无量,无圆无不圆,无满无不满,亦无是名究竟圆满。

50、 强势文化就是遵循事物规律的文化,弱势文化就是依赖强者的道德期望破格获取的文化,也是期望救主的文化。强势文化在武学上被称为”秘笈”,弱势文化由于易学,易懂,易用成了流行品种。

51、 所谓真经,就是能够达到寂空涅盘的究竟法门,可悟不可修。修为成佛,在求。悟为明性,在知。修行以行制性,悟道以性施行,觉者由心生律,修者以律制心。不落恶果者有信无证,住因住果、住念住心,如是生灭。不昧因果者无住而住,无欲无不欲,无戒无不戒,如是涅盘。

52、 因为你不知道你,所以你是你。你知道了你,你就不是你。

53、 晚辈个人以为,佛教以次第而分,从精深处说是得道天成的道法,道法如来不可思议,即非文化。从浅义处说是导人向善的教义,善恶本有人相、我相、众生相,即是文化。