跳至主要内容

博文

目前显示的是 2014的博文

Reactive Stream (1)

本周开始复习部分 Scala 的知识,并开始学习 Akka Stream 的基础部分。Akka Stream 是 Reactive Stream + [Sources, Sinks and FlowGraphs](http://typesafe.com/blog/sources-sinks-and-flowgraphs) + [Akka Stream experimental API](http://doc.akka.io/api/akka-stream-and-http-experimental/1.0-M1) + [Reactive Stream presentation by Joshua Suereth](https://docs.google.com/presentation/d/16eITQAn4HIdD6rV_0upX8LVgDeKL4z4WGnxPPGuzj8o/edit#slide=id.p) + [Async database access with PostgreSQL, Play, Scala and Heroku](http://mauricio.github.io/2013/04/29/async-database-access-with-postgresql-play-scala-and-heroku.html) + [Reactive Stream & Akka HTTP](http://spray.io/msug/#/)

YOW 2014 集锦 (未完成)

> 刚结束的 YOW 2014 墨尔本会议,听了整整两天,各种主题演讲人的水平参差不齐—— > 口若悬河者有之;平淡无奇者亦有之。简单整理几个比较有趣的几个话题。 Andrei Alexandrescu 这次放下了 C++ 委员会成员的身份,来宣讲他自己在“非死不可”主持发展的 D language。号称在系统编程领域超过 C 和 C++,而且语法支持各种高级语言的特性。在讨论时下流行的函数式编程的时候,他举的例子是 factorial (阶乘)函数—— // version 1 - functional style, but not tail currying ulong factorial(uint n) { return n

Some video

周末看的几个视频,第一个是大牛 Douglas Crockford 在 YUIConf 上所做的 Keynote,之后的是在他的 Slides 中提及的几个视频: + Douglas Crockford: Monads and Gonads (YUIConf Evening Keynote) [Youtube Video](https://www.youtube.com/watch?v=dkZFtimgAcM) + Carl Hewitt: The Actor Model (everything you wanted to know, but were afraid to ask) [Channel9 Video](http://channel9.msdn.com/Shows/Going+Deep/Hewitt-Meijer-and-Szyperski-The-Actor-Model-everything-you-wanted-to-know-but-were-afraid-to-ask) + Mark Millers: Secure Distributed Programming with Object-capabilities in JavaScript [Video 1](http://www.youtube.com/watch?v=w9hHHvhZ_HY), [Video 2](http://www.youtube.com/watch?v=oBqeDYETXME)

Paths in Linux

无意中找到的一个帖子,讲的是Linux系统中[几个 PATH 的区别](http://unix.stackexchange.com/questions/8656/usr-bin-vs-usr-local-bin-on-linux). 1. `/bin` (and `/sbin`) were intended for programs that needed to be on a small `/` partition before the larger `/usr`, etc. partitions were mounted. These days, it mostly serves as a standard location for key programs like `/bin/sh`, although the original intent may still be relevant for e.g. installations on small embedded devices. 2. `/sbin`, as distinct from `/bin`, is for system management programs (not normally used by ordinary users) needed before `/usr` is mounted. 3. `/usr/bin` is for distribution-managed normal user programs. 4. There is a `/usr/sbin` with the same relationship to `/usr/bin` as `/sbin` has to `/bin`. 5. `/usr/local/bin` is for normal user programs not managed by the distribution package manager, e.g. locally compiled packages. You should not install them into `/usr/bin` because future distribution upgrades may modify or delete them withou...

ImplDDD 阅读笔记 - Value Objects, Part 2

在比较 Value Objects 的时候,首先比较的是两个对象的类型,其次才是对象的 attributes。如果两个或多个 value objects 是相等的,那么使用其中任意一个赋值给 Entity 的 property 都不会改变该 Entity Object 的状态。 A method of an object can be designed as a _Side-Effect-Free Function_. A function is an operation of an object that produces output but without modifying its own state. Since no modification occurs when executing a specific operation, that operation is said to be side-effect free. Value Object 的方法都是 Side-Effect-Free 的,因为一旦被创建出来就无法再修改 Value Object 的状态了。这个特性实际上跟 immutability 有很强的关联,不过作者认为有必要将其独立出来,这样可以更容易把 Value Object 当做一个可用的对象而非简单的一组 attributes 来使用。 FullName name = new FullName("Vaughn", "Vernon"); // later ... name = name.withMiddleInitial("L"); 这里调用的 `withMiddleInitial` 就可以是(也必须是)一个 function,它基于原有的 Value Object 创建了一个新的 Value Object。 public FullName withMiddleInitial(String aMiddleNameOrInitial) { if (StringUtils.isBlank(aMiddleNameOrInitial == ...

ImplDDD 阅读笔记 - Value Objects, Part 1

Values types that measure, quantify, or describe things are easier to create, test, use, optimize, and maintain. Domain model 中真正的 Value Objects 并不是业务领域中的一种物品 (thing),它是用于测量、量化或是描述物品的。例如,一个人的年龄,它并不是一件事物,而是用来量化这个人从出生到现在的年数。 如果设计正确,Value Objects 的实例在创建之后就可以被随意传递,开发者可以即刻忘记这类对象,无论它们的生命周期是长是短,更无需担心对象的值是否被修改。在解决 Ubiquitious Language 的时候,确定正在建模的 domain concept 是否适合 Value Objects 是第一要务。有这么几个标准可以用来辅助判断: + It measures, quantifies, or describes a thing in the domain. + It can be maintained as immutable. + It models a conceptual whole by composing related attributes as an integral unit. + It is completely replaceable when the measurement or description changes. + It can be compared with others using Value equality. + It supplies its collaborators with Side-Effect-Free Behavior. 在绝大多少情况下,Value Objects 都是 immutable 的,一旦它们被创建出来,就无法再修改它的值。在 Java 或是 C# 这样的语言中,开发者往往使用 constructor 来构造 Value Objects 的实例,传入的参数被用于确定该对象的全部状态。构造参数可能直接被保存为 Value Objects 的 attributes,也可能被用于推导 (derive) 出对象内的一个或是若干 attributes...

ImplDDD 阅读笔记 - Validation

讨论 Validation 的时候,不得不提及 Self encapsulation,objects 的 constructor 将成员变量的赋值代理给各自的 setter methods 来执行,而 setter 可以检查对象自身是否具有合适的 state。本书的作者并不认同将 self encapsulation 视作为 validation 的一种,因为从单一职责的角度来看,更适合由独立的 validation class 而不是 domain class 自己来执行 validation 操作。他对 self encapsulation 的看法是,assertions that follow a design-by-contract approach。所谓的 design-by-contract 是由 Bertravel Meyer 在 Eiffel 语言中所提倡的,可以具体细分为 pre-condition, post-condition 和 invariants of the components。 The primary reasons to use validation in the model are to check the correctness of + any one attribute/property, + any whole object + or, any composition of objects. Domain model 的 validation 被划分为三个层次,也就是说,即使一个 Entity 中所有的 attributes/properties 都有效,这个 Entity 还是可能由于 attributes 的组合状态无效。因此,还是要用 Specification 或是 Strategy 来对整个 Entity 的状态来执行校验。 由于整个 Entity 的 state 必须对 validation 可见,并不表示将 validation processing 内嵌在 Entity 里是个好主意。很多时候对于 domain object 的 validation 逻辑的修改比起对于 domain model 本身的业务逻辑的修改来的更为频繁!此外,从 responsibility 的角度来考虑也应当独立出 ...

探索家用 NAS (三)

在考虑了市场上各种选择之后,选择了 Asustor 的一款四盘位产品,从硬件配置来看,这台 NAS 配备了 Intel Atom CPU,足以支持多媒体解码以及安装五花八门的 apps,标配内存 1GB,如果嫌少自己还可以加一条最大 2GB 的笔记本内存。 两盘位的 NAS 直接被过滤掉了,因为仅支持 RAID0 和 RAID1,家用网络的瓶颈往往并不是速度,现在大部分的无线路由器或是 HUB 都提供了一定数量的千兆网口,看看测评报告就会发现不少产品的 RAID0 速度也真没快到哪去。至于 RAID1,不选择的原因是它需要 1:1 的备份消耗,性价比不足。超过四盘位的 NAS 对我来说过于高级,因此就只剩下了可以配置 RAID5 或是 RAID10 的 4 Bays Device。 从软件的角度来看,如果自行组建 NAS,的确有像是 FreeNAS 或是“黑群晖”这样的操作系统可用,但是看了很多人的配置经历觉得并不是很理想,花的功夫不少,有兴趣的朋友可以看看 知乎上的这一个问答 (好吧,俺承认主要是懒得动手折腾)。像是 Synology、QNAP 这些台系厂商最近几年大力研发自己的平台,对于 web interface 和移动终端的支持都已经很丰富了。Asustor 虽然是后起之秀,不过看大量的评测也对于他家的 ADM 给予了肯定。 于是,就要下单了……

探索家用 NAS (二)

这周花了点儿时间在网上研究厂商提供的 NAS 产品,对比了米国亚马逊和国内网商的价格,主要看了京东和易讯的报价。下面列的是几款主要的产品,都是不带硬盘的裸机—— + BUFFALO LinkStation Pro Duo 2-Bay Diskless Enclosure High Performance Network Attached Storage (NAS) - LS-WVL/E 双盘位的老产品,CPU是Marvell的ARM架构处理器,1.6GHz;内存是256MB,最大支持8TB硬盘。 + Synology DiskStation 2-Bay (Diskless) Network Attached Storage (DS213j) 支持浮点运算的 1.2GHz 处理器,512MB DDR3 内存,最大支持 8TB。 + Synology America DiskStation 2-Bay Diskless Network Attached Storage (DS214play) 支持浮点运算的 1.6GHz 双核处理器,1GB DDR3 内存,最大支持 8TB。 + Synology DiskStation 4-Bay (Diskless) Network Attached Storage DS412+ (Black) 双核 2.13GHz Atom 处理器,1GB DDR3 内存,最大支持 16TB。 第一个产品价格约为 630 元;第二款价格为 1500 元;第三款为 3000 元;最后一款显然有着最“强”的价格 4600 元。从价格角度来看显然双硬盘位的较为便宜,但是从性能和容量来看四位产品有极大的优势。 NAS 重量级产品主要集中在台系的 QNAP 和 Synology 两家身上,从评测文来看貌似QNAP的系统和界面比起Synology的略微逊色一分。而巴法络的 NAS 貌似被不少网友诟病不稳定……本质上价格高的产品提供的不仅仅是硬件,更重要的是软件的整合。

探索家用 NAS (一)

现成的 NAS 设备大多仅支持RAID 0/1,可用性不是很高,如果选用4 bay的设备,则可以使用RAID 5/6/10。在亚马逊上看了看,现成的四盘设备(注意是不带硬盘的空设备)大概价格从两百多刀到五百多刀都有(美元结算)。基本配置是 1.2GHz 的 CPU 和 512MB 板载内存。 NETGEAR ReadyNAS 104 4-Bay Diskless Network Attached Storage (RN10400-100NAS) 售价 250 美元 Seagate Business Storage NAS 4-Bay 8TB Network Attached Storage STBP8000100 售价 590 美元 家庭内用的电子娱乐设施主要包括这么几类: 笔记本电脑和台式机,或是一体机 平板电脑(iPad 或是安卓平板) 智能手机(iPhone 或是 Android Phone) Gaming Console (XBox 或是 PS) 各类设备使用的操作系统都不太一样,有的是 Windows 7/8、或是 Mac OS X,或是 iPhone OS,甚至是诸多 Android 碎片化的版本,还有一些封闭的系统……好在大都支持无线网络访问。 而家庭数字娱乐内容主要包括照片、视频、电影(你懂的)还有一些备份的文件,在针对复杂的设备群的访问的时候,NAS的好处就很显著——不管终端设备的硬件配置高低计算能力强弱操作系统几何,只要通过网络就可以访问到基本的存储服务。 想象一下,家人随时可以将手机中的照片上传到NAS备份,下载好的电视剧可以坐在沙发上看小米电视或是躺在床上看手机,音乐也可以很方便地同步到各个设备上头。这个愿景是很棒的,不过考虑到实际上NAS的价格,我可能更倾向于DIY一台而不是去购买现成的设备。 普通的电脑并不是NAS,我认为NAS至少需要满足以下这些条件: 低功耗 具体说来包括低耗电量静音等。CPU不需要太强大,也不需要超过四核,否则散热就成了大问题。GPU也不需要,因为终端设备有能力硬解视频流。静音是个preferrable的特点,因为谁也不想要搞一堆小风扇塞在盒子里,那样还得考虑智能风扇的设定……麻烦当然是越少越好。 低存储成本 支持备份的 RAID 是必须的,高级的 RA...

关于SSD的那些事

刚刚看完一篇很长的技术贴,确切的说是硬件评测贴。这是一篇写于2009年的文章,5年的时间跨度对于计算机硬件发展而言是好几个世代,不过作者在评测中介绍到的很多东西是与存储系统紧密相关的,例如传统硬盘的工作原理,SSD的TRIM指令由来等。非常值得一读,毫不夸张的说,这是积累攒机知识所必须的…… 文章的地址在这里—— The SSD Anthology

ImplDDD 阅读笔记 - Entity Identity

DDD 中实体类型的设计往往被错误的导向了与数据库有关的 Scheme Design。 > Because of the prevailing approaches to software development that place > importance on the database, instead of designing domain concepts with rich > behaviors, developers might think primarily about the attributes (columns) > and associations (foreign keys) of the data. 这种以数据库范式为导向的设计思路导致 domain models 中几乎每一个概念都以 entity 的方式被编码为仅有 `getter` 和 `setter` 的类型,可是显然 Domain driven design 所追求的 entities 不应该仅仅具有 property accessors。 > An entity is a unique thing and is capable of being changed continuously over > a long period of time. Changes may be so extensive that the object might seem > much different from what it once was. And yes, it is the same object by identity. 常见的 *Anemia model (贫血的模型)* 很多时候就是来自于这样的设计。例如,书中第一章所给出的 Customer 的例子就是很【贫血】的: private void saveCustomer( String customerId, String customerFirstName, String customerLastName, String ...

Mac OSX 10.9 更新 port 症结

自从 MacBook Pro 升级到 Mavericks 之后,还没有用过 port 来更新软件。今天刚好需要安装 tmux 所以执行了 sudo port upgrade outdated 来更新所有已经过期的软件包,却发现居然报错: --->  Configuring expat Error: Failed to configure expat, consult /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_textproc_expat/expat/work/expat-2.1.0/config.log Error: org.macports.configure for port expat returned: configure failure: command execution failed Please see the log file for port expat for details:     /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_textproc_expat/expat/main.log Error: Unable to upgrade port: 1 To report a bug, follow the instructions in the guide:     http://guide.macports.org/#project.tickets 谷歌了之后看到有人说需要 用 XCode 安装 developer library ,于是照做了一下,貌似没什么用,病症还是在升级到了 OSX 10.9 之后遇到了问题,我仔细查看了日志后发现是与 C 编译器有关的: error: C compiler cannot create executables 貌似强大的 clang 无法找到 stdio.h ,...

ImplDDD 阅读笔记 - Domains, Subdomains and Bounded Contexts

从广义的角度来说,Domain 指的是一个组织所从事的【领域】。不同行业的组织有着截然不同的领域,它们的认知范围和运营方式构成了自身的 domain。在设计的时候,应当尽可能的将不同的 domain 分离开来,形成 Core Domain、Supporting Domain 和 Generic Domain。 + A Core Domain is a part of the business Domain that is of primary importance to the success of the organization. + 有时候为了支撑业务的运行,必须要创建 Bounded Context 来建立不可缺的模型,这就是 Supporting Subdomain。这些模型是不可缺的 (essential) 但并非最为核心的 (core)。 + 另外,对于业务而言并不具有特殊性但是对于全局 (overall business solution) 而言是必须的部分可以被归入 Generic Subdomain。 书中给出的一个例子是 SaaSOviation 的 collaboration product,在设计的时候,这个虚拟的团队一开始将 `User` 和 `Permission` 这样的 domain 融入了 `Forum`、`Discussion` 之中,导致了不必要的概念引入,从而形成了不必要的 complicated code: public class Forum extends Entity { public Discussion startDiscussion(String aUsername, String aSubject) { if (this.isClosed()) { throw new IllegalStateException("Forum is closed."); } User user = userRepository.userFor(this.tenantId(), aUsername); if (...

Add Type Constraints to your JavaScript

刚看完了 Channel 9 上放的一段视频,是大牛 [Andres Hejlsberg 介绍 TypeScript 的视频](http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-TypeScript)。 [TypeScript](http://www.typescriptlang.org/) 有一套自己的 Language Specification,其中允许定义 modules、classes 和 functions 等具有强类型的标识对象。tsc 是 TypeScript Compiler,有能力扫描所有的 reference files 并根据类型关系提供 development time 的语法高亮和上下文提示,从 tooling 方面极大的强化了 javascript 在开发大规模应用程序(scalable application)时候的效率。而这恰恰是 javascript 的软肋…… 有一段 demo 展示了如何针对 type script 文件执行重构——传统的 javascript 文件由于没有具体的类型信息无法让 IDE 支持像是“重命名”这样的简单操作,很多时候 IDE 只能以朴素的字符串替换方式来重命名所有的出现地方。而 TypeScript 由于编译器可以推断类型信息,因此重构变得可行。 在视频的最后一段 demo 中,Andres 还展示了 typescript compiler 的“自举” (self boot) —— 编译自身的源代码。 除了编译出 js 文件外,还可以指定生成相应的 *.d.ts 文件列举所有对外可见的 interfaces。这对于所有需要支持 TypeScript 的工具来说都是很要紧的。 总得来看,typescript 很好的弥补了javascript 弱类型的不足,如果在大多数 IDE (如Eclipse、IntelliJ或WebStorm)中能够得到很好的支持的话,应该是web developers手中很好的一枚工具!