Neio Notes Share knowledge and experience with you

8Sep/110

Game Font Generator – BMFont

Somebody may face the difficult of drawing text by  using directX or OpenGL  directly. We have to generate character bitmap then use it as texture for showing texts.

BMFont helps us with this task. BMFont provides both GUI window mode and command line mode. In GUI window mode, you can tick what character you need to generate, you will receive a png format font image and configuration file for accessing the font image.

Command line mode is suitable for automatic generating purpose. For example, you write an Unicode encoded text file with the text that you need to display. Then use command line to generate. For example:

bmfont.com -c config.bmfc -o gamefont.fnt -t text.txt 

This command line tell bmfont load config.bmfc and output as gamefont.fnt while all characters present in the text.txt will be added to the font.

Filed under: 经验之谈 No Comments
2Sep/110

Windows 7 下的串口調試

最近的項目涉及到RS232通訊,創建虛擬的RS232串口來調試是開發時最方便的選擇。許多年前曾經可以用的一些虛擬串口工具在Windows 7下均失效了,於是又另外找了一個,與大家分享。

工具的名字叫:HW VSP3 , 推薦它因為他是FREEWARE,而且支持Windows 7 64bit。它的工作原理是虛擬出串口並且轉發到所設定的TCP地址。注意選SinglePort版本的,Multiport是commercial version。

這時候只需要一個TCP測試工具,例如 TCP&UDP調試工具,即可與你當前的程序之間相互收發信息。當然也可以是你撰寫的單元測試工具,或者程序的客戶端模擬工具。

1Sep/110

HLSL Notes 1

Getting Started

Shader is a very powerful tool that enhanced the computer graphics. Since several years ago, computer graphic cards have supported hardware-accelerated shader. The picture below shows an example of shader effects.

Shader is written in a so-called shader language. The shader language files are complied and are put into the graphic hardware running in parallel.   There are some different kinds of shader languages. OpenGL provided a C-liked  shader language, called OpenGL Shader Language (GLSL). In Microsoft DirectX 9 or later, shaders are programmed by High Level Shader Language (HLSL).

Concept

In shader programming, pixels are processed in parallel. So in shading language, we are dealing with single pixels. To simply the shader programming, the shader can be written in the following formulation:

F(x,y,z) = value

It tell the system what color will be shown in the position (x,y,z).

Vertex Shader & Pixel Shader

Due to the limitation of hardware pipeline, shader are divided into different types, such as vertex shader and pixel shader. They are processed in sequence in the graphics pipeline. (The latest newest shader model, the unified shader model has already simplified and unified the shading programming) However, since there are still many machine that does not support the latest shader model, this note will focus just on shader model 2.0.

HLSL example

In HLSL, like C programming, there will be an entry function, such as main().

For example:

sampler2D inputTexture : register(s0);

float4 ps_main (float2 texCoord: TEXCOORD0) : COLOR

{

float4 color = tex2D(inputTexture, texCoord);

return color;

}

This shader do NOTHING changed like directly rendering.

23Apr/110

LaTeX in WordPress

今天尝试下在Wordpress上显示公式,看样子 WP LaTeX 插件不错。下面展示一个例子:

BYY(p||q)=\int_{X,R}p(R|X)p(X)\ln\frac{p(R|X)p(X)}{q(X|R)q(R)}dXdR

上面的式子是Bayesian Ying-Yang Matching function. 是徐雷教授的机器学习理论,用这个可以推出EM,K-means等特例。

8Oct/100

My Current Research in CUHK

It has been more one month, since I began my study in The Chinese University of Hong Kong.  Hong Kong impressed me in its order and efficiency.  It's transport system is really perfect that I can nearly go anywhere on time. I just have a little problem with its local language, the Cantonese, which I'm really very poor.

I'm now with professor K.H. Wong in CUHK and doing research in Computer Vision.  I the first term, I selected courses of Data Mining, Computer Vision and Semantic Web, along with PROJECT I, in which I have to take researches and keep thinking new ideas in implementing the technology of computer vision.

I will introduce later, in my blog, about what I'm studying.  The link will be updated here, too.

Filed under: 生活随笔 No Comments
3Dec/092

NoSQL小记

--Neio

我是在今年(2009年)夏天的“NoSQL”运动后(链接)才深入将Key-Value型存储方式引入现有的工作中的。早先对Google的Bigtable略有了解,知道其对数据存储思想的影响,但始终没有深入去了解它,所以现在也算是了去了一个遗憾。

我认为,NoSQL运动的意义并不是完全反对SQL,而是在于告诉被关系型数据库(RDBMS)这座宏伟的大山挡住视线的人们,SQL并非唯一的数据存储方式。也就是后来人们说的"Not Only SQL"——这一简短精辟的诠释"NoSQL"的短语。

目前我使用的Hypertable, HBase(HBase为参照使用),都是基于Bigtable模型的Key-Value型(更准确说是RowColumn型)分布式存储方式。选择它们,也是在于Bigtable盛名之下的缘故。

NoSQL运动中的模型并非Bigtable模型只此一家,而是如同春秋时期的诸子百家,整体呈现出了百家争鸣的局面。

Why NoSQL?

三个关键字:ACID, BASE, CAP

ACID是DBMS中强调的,分别是原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)、持久性 (Durability)。对于这四个名词不了解的,请参考维基百科对于ACID的描述。总体来说,ACID的目的就是通过事务支持,保证数据的完整性和正确性。

CAP: CAP是一个经验理论,由Brewer所提。三个字母分别是 Consistency, Availability 和 Partition Tolerance的缩写,分别可以翻译为一致性、有效性和网络分离容忍度。三个目标无法兼得,ACID在一致性和有效性卓有成效,而在Partition tolerance上的努力, 则非常艰难。而目前互联网应用情形下的海量数据,将单台计算机的处理能力压榨殆尽,单台计算机上的关系型数据库很难满足应用需求;而如果将关系型数据库的表分割存储在不同的计算机上,其有效性将很难保证。

于是乎,BASE被渐渐从记忆中挖掘出来,渐渐成为hot word。这个名词同样是Brewer所提。分别是英文:Basically Available, Soft-state, Eventual Consistency的缩写,正好与ACID这个缩写在字面上的意思相对应。这个理论认为,只需要满足Eventual Consistency(最终一致性)即可,而且可以是无连接的(Soft-state)。值得一提的是,eBay正是根据BASE的原理设计起架构。有兴趣的朋友可以参考《
BASE: An Acid Alternative》。

这三个名词与 NoSQL什么关系?

NoSQL做的,就是通过降低对数据一致性、完整性的要求,转而偏向于CAP中的A和P,通过增加Tolerance to network partition(P)的支持, 甚至与追求P来达到满足高并发的需求。而这背后,就需要BASE理论的支撑,才敢如此的放肆。因为放弃了对一致性的高要求,只需要满足BASE的Eventual Consistency, 也能最终达到一致。

后记

面向高并发的软件架构,特别是电子商务型的网站,更是要在CAP中三个度量中做取舍。核心的业务需要一致性的保证,偏向于用通过关系型数据库来保证,而一些对于一致性要求不高的数据,通过使用Key-Value型数据存储方式,又可以满足大量访问的要求。

ACID与BASE,这两个中和一下,不正是我们所需要的么? 所以, Why not NoSQL?

----------------------
PS. 文章在Draft停留了1个月,一直未完稿。始终还没调整好工作的节奏, 困于工作中啊。
----------------------

16Nov/092

Recruit [Out-dated]

Updated on Dec. 8, 2010

我现在已经离开正在上学。

以前的公司现在仍然在大力招人。

----------------------------------

目前我们公司正在招纳新人,具体情况详见:

http://www.qzqx.net/about/Invite.aspx

公司全名:泉州市视通光电网络有限公司
工作地点:公司总部,福建省泉州市中山中路旁(中心市区)
工作要求:如果你有以下资历之一,非常欢迎你的加盟。

1、GIS应用开发2年或以上经验,为主要项目负责人;
2、精通算法,懂得数学建模的;熟练掌握C++或C#的优先;
3、拥有5年或以上团队经验,且有担任项目经理经验;
4、拥有企业软件设计5年或以上经验者。

拥有以上其中一项资历者,在我们公司可以找到很好的才华展示机会。

积极进取、勇于创新

有意者请将简历或相关材料发到我的邮箱(neio.zhou~~gmail.com),也可以直接通过上面的链接地址上的联系方式联系。

Filed under: 生活随笔 2 Comments
30Oct/095

Thrift C#for Hypertable Issue

前言

近日在为Hypertable做一层.NET(C#)的封装,遇到了一个较为严重的问题:用Thrift封装的Hypertable C#客户端在连接Hypertable ThriftBroker的时候被主动断开,造成数据无法读取的现象。

过程

1、用Wireshark检查了TCP封包,观察到在发送第一笔数据后就被Hypertable ThriftBrokeryper主动发送FIN结束了连接,于是后面发送数据就丢掉了,更不用说接收信息;

2、检查Hypertable中的日志,查看到以下信息:
TConnection : transition() Negative Frame Size -2147418111, remote side not using TFramedTransport?
注意到这里可以看出,Hypertable使用了TFramedTransport作为其传输层接口。然而,C#的Thrift中尚无此接口。

26Oct/096

Thrift简介

Thrift是一个跨语言服务部署框架,最初由Facebook于2007年开发,后于2008年进入Apache孵化器(Apache Incubator)。

类似于SOAP,COM 和CORBA,Thrift通过定义一个中间定义语言和Thrift代码生成工具,生成指定语言的代码。目前,Thrift支持C++,Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, Smalltalk和OCaml的代码生成。

简单分析其机理,Thrift就是实现C/S模式,通过代码生成工具将接口定义文件生成服务器端和客户端代码(可以为不同语言),从而实现服务端和客户端跨语言的支持。

Thrift可以分为传输层和协议层:

1、传输层定义了数据的传输方式,可以为TCP/IP传输,内存共享或者文件共享等形式;
2、协议层定义了数据的传输格式,可以为二进制流或者XML等形式。

简单例子:

中间语言定义:

struct UserProfile {
1: i32 uid,
2: string name,
3: string blurb
}
service UserStorage {
void store(1: UserProfile user),
UserProfile retrieve(1: i32 uid)
}

Python客户端代码:

# Make an object
up = UserProfile(uid=1,
                 name="Mark Slee",
                 blurb="I'll find something to put here.")

# Talk to a server via TCP sockets, using a binary protocol
transport = TSocket.TSocket("localhost", 9090)
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)

# Use the service we already defined
service = UserStorage.Client(protocol)
service.store(up)

# Retrieve something as well
up2 = service.retrieve(2)

服务器端代码:

class UserStorageHandler : virtual public UserStorageIf {
 public:
  UserStorageHandler() {
    // Your initialization goes here
  }

  void store(const UserProfile& user) {
    // Your implementation goes here
    printf("store\n");
  }

  void retrieve(UserProfile& _return, const int32_t uid) {
    // Your implementation goes here
    printf("retrieve\n");
  }
};

int main(int argc, char **argv) {
  int port = 9090;
  shared_ptr<UserStorageHandler> handler(new UserStorageHandler());
  shared_ptr<TProcessor> processor(new UserStorageProcessor(handler));
  shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
  shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
  shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
  TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
  server.serve();
  return 0;
}

参考资料

1. http://incubator.apache.org/thrift

25Oct/090

First C++ Programming Experience with Hypertable(A)

前言

目前正在为Hypertable做一层封装,使之通过ZeroMQ或RabbitMQ提供一个通用数据访问接口。

说来蛮郁闷的,编译一个Hypertable的example耗费了我一天半的时间。一来,网速慢,下载boost, thrift, log4cpp等库,耗费了很多时间;二来,没有在Linux下做过项目。

下面我以example里面的freebase作为例子,说明编译环境的配。

编译Freebase例子

一、环境

Ubuntu 8.10

hypertable 0.9.2.7  (hypertable-0.9.2.7-linux-i386.deb

Page 1 of 212